clear console log

This commit is contained in:
熊潇 2025-04-22 13:41:49 +08:00
parent 17ce93d5bd
commit ad5bcd5be8
3 changed files with 35 additions and 6 deletions

View File

@ -221,12 +221,13 @@ function* sliceData(data: Buffer, chunkSize: number): Generator<[Buffer, boolean
yield [data.slice(offset, dataLen), true];
}
const format = ['wav', 'mp3', 'pcm'] as const;
type AsrClientFormat = (typeof format)[number];
interface AsrClientOptions {
segDuration?: number;
wsUrl?: string;
uid?: string;
format?: string;
format?: AsrClientFormat;
rate?: number;
bits?: number;
channel?: number;
@ -311,7 +312,8 @@ export class AsrWsClient extends VolcEngineBase {
request: {
model_name: 'bigmodel',
enable_punc: true,
result_type: 'single', // all, single
// result_type: 'single', // all, single
result_type: 'all',
},
};
}
@ -348,6 +350,9 @@ export class AsrWsClient extends VolcEngineBase {
private async segmentDataProcessor(audioData: Buffer, segmentSize: number): Promise<any> {
await this.sendFullClientRequest();
const that = this;
if (this.isError) {
return;
}
const sendVoice = async (audioData: Buffer, segmentSize: number) => {
that.setCanSend(false);
for (const [chunk, last] of sliceData(audioData, segmentSize)) {
@ -396,6 +401,10 @@ export class AsrWsClient extends VolcEngineBase {
throw new Error('event.data is string: ' + event.data);
}
// console.log('parsed', parsed.payloadSequence, parsed.payloadMsg.result.text);
if (parsed?.payloadMsg?.error) {
this.emitter.emit('error', parsed);
this.isError = true;
}
if (parsed.isLastPackage) {
this.emitter.emit('end', parsed);
} else {

View File

@ -21,7 +21,8 @@ type VolcEngineBaseOptions = {
export class VolcEngineBase extends WSServer {
canSend = false;
isEnd: boolean = false;
isError: boolean = false;
constructor(opts: VolcEngineBaseOptions) {
super({
url: opts.url,

View File

@ -239,8 +239,8 @@ function parserResponse(res: Buffer | string): Response {
}
function printResponse(res: Response, tag: string): void {
console.log(`===>${tag} header:`, res.header, res.optional.event);
console.log(`===>${tag} optional:`, res.optional);
// console.log(`===>${tag} header:`, res.header, res.optional.event);
// console.log(`===>${tag} optional:`, res.optional);
}
function getPayloadBytes(
@ -373,3 +373,22 @@ export async function runDemo(appId: string, token: string, speaker: string, tex
});
});
}
export class TtsMix {
appId: string;
token: string;
constructor(appId: string, token: string) {
this.appId = appId;
this.token = token;
}
/**
*
* @param speaker
* @param text
* @param outputPath
* @returns
*/
async getVoiceDemo(speaker: string, text: string, outputPath: string): Promise<void> {
return runDemo(this.appId, this.token, speaker, text, outputPath);
}
}