fix: iOS TTS unlock on user gesture, use \r for terminal Enter
Deploy Dashboard / deploy (push) Successful in 1m0s

This commit is contained in:
Gan, Jimmy
2026-02-26 15:45:27 +08:00
parent fca929df9f
commit 0f05890d12
+11 -2
View File
@@ -16,6 +16,7 @@ export class VoiceSession {
this._debounce = null;
this._recog = null;
this._onWriteDispose = null;
this._ttsUnlocked = false;
}
get lang() { return LANGS[this.langIdx]; }
@@ -68,10 +69,18 @@ export class VoiceSession {
toggleTts() {
this.ttsEnabled = !this.ttsEnabled;
if (!this.ttsEnabled) { speechSynthesis.cancel(); this.speaking = false; }
if (this.ttsEnabled && this.term) {
if (this.ttsEnabled) {
// iOS Safari requires first speak() in a user gesture to unlock audio
if (!this._ttsUnlocked) {
const u = new SpeechSynthesisUtterance("");
speechSynthesis.speak(u);
this._ttsUnlocked = true;
}
if (this.term) {
const buf = this.term.buffer.active;
this._lastLine = buf.baseY + buf.cursorY;
}
}
this._notify();
}
@@ -93,7 +102,7 @@ export class VoiceSession {
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 + "\n"));
this.ws.send(new TextEncoder().encode(text + "\r"));
}
}
}