From 47ab062eddd1a9751fd2ce0a93f5f48aa5d2c0b5 Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Thu, 26 Feb 2026 15:50:17 +0800 Subject: [PATCH] fix: type STT text char-by-char, increase TTS debounce to 2s --- dashboard/frontend/src/lib/voice.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dashboard/frontend/src/lib/voice.js b/dashboard/frontend/src/lib/voice.js index bdcbdcb..db7e9ac 100644 --- a/dashboard/frontend/src/lib/voice.js +++ b/dashboard/frontend/src/lib/voice.js @@ -34,7 +34,7 @@ export class VoiceSession { _onOutput() { if (!this.ttsEnabled || this.listening) return; clearTimeout(this._debounce); - this._debounce = setTimeout(() => this._readBuffer(), 600); + this._debounce = setTimeout(() => this._readBuffer(), 2000); } _readBuffer() { @@ -84,6 +84,17 @@ export class VoiceSession { this._notify(); } + _typeText(text) { + let i = 0; + const next = () => { + if (i < text.length && this.ws?.readyState === 1) { + this.ws.send(new TextEncoder().encode(text[i++])); + setTimeout(next, 20); + } + }; + next(); + } + toggleMic() { this.listening ? this.stopListening() : this.startListening(); } @@ -101,9 +112,7 @@ export class VoiceSession { for (let i = e.resultIndex; i < e.results.length; i++) { if (e.results[i].isFinal) { const text = e.results[i][0].transcript.trim(); - if (text && this.ws?.readyState === 1) { - this.ws.send(new TextEncoder().encode(text + "\r")); - } + if (text && this.ws?.readyState === 1) this._typeText(text + "\r"); } } };