update
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user