feat: 更新音频处理逻辑,添加最后识别文本功能并优化相关提示信息
This commit is contained in:
@@ -5,6 +5,7 @@ export class Relatime {
|
||||
asr: WSServer
|
||||
ready = false
|
||||
timeoutHandle: NodeJS.Timeout | null = null
|
||||
startTime: number = 0
|
||||
constructor() {
|
||||
// const url = new URL('/ws/asr', "http://localhost:51015")
|
||||
const url = new URL('/ws/asr', window.location.origin)
|
||||
@@ -51,15 +52,20 @@ export class Relatime {
|
||||
}
|
||||
sendBase64(data: string) {
|
||||
if (!this.ready) return;
|
||||
this.asr.ws.send(JSON.stringify({ voice: data, format: 'float32' }));
|
||||
if (this.timeoutHandle) {
|
||||
clearTimeout(this.timeoutHandle);
|
||||
}
|
||||
this.timeoutHandle = setTimeout(() => {
|
||||
this.asr.sendBlankJson()
|
||||
this.timeoutHandle = null;
|
||||
}, 10000); // 5秒钟没有数据则发送空JSON保持连接
|
||||
|
||||
console.log('send 花费时间:', Date.now() - this.startTime);
|
||||
this.asr.ws.send(JSON.stringify({ voice: data, format: 'float32', time: Date.now() }));
|
||||
// if (this.timeoutHandle) {
|
||||
// clearTimeout(this.timeoutHandle);
|
||||
// }
|
||||
// this.timeoutHandle = setTimeout(() => {
|
||||
// this.asr.sendBlankJson()
|
||||
// this.timeoutHandle = null;
|
||||
// }, 20000); // 20秒钟没有数据则发送空JSON保持连接
|
||||
}
|
||||
setStartTime(time: number) {
|
||||
this.startTime = time;
|
||||
}
|
||||
showCostTime() {
|
||||
console.log('当前花费时间:', Date.now() - this.startTime);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user