fix: type STT text char-by-char, increase TTS debounce to 2s
Deploy Dashboard / deploy (push) Successful in 1m0s
Deploy Dashboard / deploy (push) Successful in 1m0s
This commit is contained in:
@@ -34,7 +34,7 @@ export class VoiceSession {
|
|||||||
_onOutput() {
|
_onOutput() {
|
||||||
if (!this.ttsEnabled || this.listening) return;
|
if (!this.ttsEnabled || this.listening) return;
|
||||||
clearTimeout(this._debounce);
|
clearTimeout(this._debounce);
|
||||||
this._debounce = setTimeout(() => this._readBuffer(), 600);
|
this._debounce = setTimeout(() => this._readBuffer(), 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
_readBuffer() {
|
_readBuffer() {
|
||||||
@@ -84,6 +84,17 @@ export class VoiceSession {
|
|||||||
this._notify();
|
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() {
|
toggleMic() {
|
||||||
this.listening ? this.stopListening() : this.startListening();
|
this.listening ? this.stopListening() : this.startListening();
|
||||||
}
|
}
|
||||||
@@ -101,9 +112,7 @@ export class VoiceSession {
|
|||||||
for (let i = e.resultIndex; i < e.results.length; i++) {
|
for (let i = e.resultIndex; i < e.results.length; i++) {
|
||||||
if (e.results[i].isFinal) {
|
if (e.results[i].isFinal) {
|
||||||
const text = e.results[i][0].transcript.trim();
|
const text = e.results[i][0].transcript.trim();
|
||||||
if (text && this.ws?.readyState === 1) {
|
if (text && this.ws?.readyState === 1) this._typeText(text + "\r");
|
||||||
this.ws.send(new TextEncoder().encode(text + "\r"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user