generated from tailored/router-template
clear console log
This commit is contained in:
parent
17ce93d5bd
commit
ad5bcd5be8
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user