This commit is contained in:
2025-12-24 11:21:07 +08:00
parent dd7e44a4b8
commit da249ad779
7 changed files with 308 additions and 64 deletions

View File

@@ -6,6 +6,7 @@ export class Relatime {
ready = false
timeoutHandle: NodeJS.Timeout | null = null
startTime: number = 0
isRelatime: boolean = true
constructor() {
// const url = new URL('/ws/asr', "http://localhost:51015")
const url = new URL('/ws/asr', window.location.origin)
@@ -50,9 +51,17 @@ export class Relatime {
const voice = data.toString('base64');
this.asr.ws.send(JSON.stringify({ voice }));
}
sendBase64(data: string, opts?: { isRelatime?: boolean }) {
setIsRelatime(isRelatime: boolean) {
this.isRelatime = isRelatime;
}
async sendBase64(data: string, opts?: { isRelatime?: boolean }) {
if (!this.ready) return;
console.log('send 花费时间:', Date.now() - this.startTime);
if (opts?.isRelatime !== this.isRelatime) {
return;
}
// console.log('send 花费时间:', Date.now() - this.startTime);
const connected = await this.asr.checkConnected();
if (!connected) return;
this.asr.ws.send(JSON.stringify({ voice: data, format: 'float32', time: Date.now(), ...opts }));
// if (this.timeoutHandle) {
// clearTimeout(this.timeoutHandle);