This commit is contained in:
2025-04-20 01:32:28 +08:00
parent 5e781499e9
commit 17ce93d5bd
5 changed files with 49 additions and 3 deletions

View File

@@ -315,7 +315,7 @@ export class AsrWsClient extends VolcEngineBase {
},
};
}
private async sendFullClientRequest() {
async sendFullClientRequest() {
if (this.hasSendFullClientRequest) {
return;
}
@@ -353,6 +353,7 @@ export class AsrWsClient extends VolcEngineBase {
for (const [chunk, last] of sliceData(audioData, segmentSize)) {
that.seq += 1;
const isEnd = that.isEnd && last; // 结束了,而且是语音的最后一包
console.log('chunkSize', Buffer.byteLength(chunk), segmentSize, 'last', last);
if (isEnd) {
that.seq = -that.seq;
}
@@ -391,9 +392,14 @@ export class AsrWsClient extends VolcEngineBase {
try {
const parsed = parseResponse(Buffer.from(event.data as ArrayBuffer));
console.log(`Seq ${parsed.payloadSequence} response:`, parsed);
if (typeof event.data === 'string') {
throw new Error('event.data is string: ' + event.data);
}
// console.log('parsed', parsed.payloadSequence, parsed.payloadMsg.result.text);
if (parsed.isLastPackage) {
this.emitter.emit('end', parsed);
} else {
this.emitter.emit('message', parsed);
}
} catch (error) {
console.error('Error processing response:', error);
@@ -425,9 +431,14 @@ export class AsrWsClient extends VolcEngineBase {
throw error;
}
}
/**
* 发送语音流, 最小10000
* @param data
* @returns
*/
public async sendVoiceStream(data: Buffer) {
const segmentSize = Buffer.byteLength(data);
console.log('segmentSize', segmentSize);
let segmentSize = Buffer.byteLength(data);
return await this.segmentDataProcessor(data, segmentSize);
}
}