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];
|
yield [data.slice(offset, dataLen), true];
|
||||||
}
|
}
|
||||||
|
const format = ['wav', 'mp3', 'pcm'] as const;
|
||||||
|
type AsrClientFormat = (typeof format)[number];
|
||||||
interface AsrClientOptions {
|
interface AsrClientOptions {
|
||||||
segDuration?: number;
|
segDuration?: number;
|
||||||
wsUrl?: string;
|
wsUrl?: string;
|
||||||
uid?: string;
|
uid?: string;
|
||||||
format?: string;
|
format?: AsrClientFormat;
|
||||||
rate?: number;
|
rate?: number;
|
||||||
bits?: number;
|
bits?: number;
|
||||||
channel?: number;
|
channel?: number;
|
||||||
@ -311,7 +312,8 @@ export class AsrWsClient extends VolcEngineBase {
|
|||||||
request: {
|
request: {
|
||||||
model_name: 'bigmodel',
|
model_name: 'bigmodel',
|
||||||
enable_punc: true,
|
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> {
|
private async segmentDataProcessor(audioData: Buffer, segmentSize: number): Promise<any> {
|
||||||
await this.sendFullClientRequest();
|
await this.sendFullClientRequest();
|
||||||
const that = this;
|
const that = this;
|
||||||
|
if (this.isError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const sendVoice = async (audioData: Buffer, segmentSize: number) => {
|
const sendVoice = async (audioData: Buffer, segmentSize: number) => {
|
||||||
that.setCanSend(false);
|
that.setCanSend(false);
|
||||||
for (const [chunk, last] of sliceData(audioData, segmentSize)) {
|
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);
|
throw new Error('event.data is string: ' + event.data);
|
||||||
}
|
}
|
||||||
// console.log('parsed', parsed.payloadSequence, parsed.payloadMsg.result.text);
|
// console.log('parsed', parsed.payloadSequence, parsed.payloadMsg.result.text);
|
||||||
|
if (parsed?.payloadMsg?.error) {
|
||||||
|
this.emitter.emit('error', parsed);
|
||||||
|
this.isError = true;
|
||||||
|
}
|
||||||
if (parsed.isLastPackage) {
|
if (parsed.isLastPackage) {
|
||||||
this.emitter.emit('end', parsed);
|
this.emitter.emit('end', parsed);
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,6 +21,7 @@ type VolcEngineBaseOptions = {
|
|||||||
export class VolcEngineBase extends WSServer {
|
export class VolcEngineBase extends WSServer {
|
||||||
canSend = false;
|
canSend = false;
|
||||||
isEnd: boolean = false;
|
isEnd: boolean = false;
|
||||||
|
isError: boolean = false;
|
||||||
|
|
||||||
constructor(opts: VolcEngineBaseOptions) {
|
constructor(opts: VolcEngineBaseOptions) {
|
||||||
super({
|
super({
|
||||||
|
@ -239,8 +239,8 @@ function parserResponse(res: Buffer | string): Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function printResponse(res: Response, tag: string): void {
|
function printResponse(res: Response, tag: string): void {
|
||||||
console.log(`===>${tag} header:`, res.header, res.optional.event);
|
// console.log(`===>${tag} header:`, res.header, res.optional.event);
|
||||||
console.log(`===>${tag} optional:`, res.optional);
|
// console.log(`===>${tag} optional:`, res.optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPayloadBytes(
|
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