fix: type STT text char-by-char, increase TTS debounce to 2s
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user