mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
feat: ElevenLabs TTS George voice + fix HA toggle optimistic update
This commit is contained in:
+32
-12
@@ -1781,22 +1781,42 @@ function loadVoices() {
|
||||
synth.onvoiceschanged = set;
|
||||
}
|
||||
|
||||
function speak(text) {
|
||||
let _ttsAudio = null;
|
||||
|
||||
async function speak(text) {
|
||||
if (!text) return;
|
||||
if (_ttsAudio) { _ttsAudio.pause(); _ttsAudio = null; }
|
||||
synth?.cancel();
|
||||
const reactor = document.getElementById('arcReactor');
|
||||
reactor?.classList.add('speaking');
|
||||
try {
|
||||
const res = await fetch('/api/tts', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type':'application/json','X-Session-Token': sessionToken},
|
||||
body: JSON.stringify({text: text.substring(0, 400)}),
|
||||
});
|
||||
if (!res.ok) throw new Error('tts');
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
_ttsAudio = new Audio(url);
|
||||
_ttsAudio.onended = () => { URL.revokeObjectURL(url); _ttsAudio = null; reactor?.classList.remove('speaking'); };
|
||||
_ttsAudio.onerror = () => { reactor?.classList.remove('speaking'); _ttsAudio = null; };
|
||||
await _ttsAudio.play();
|
||||
} catch(e) {
|
||||
reactor?.classList.remove('speaking');
|
||||
_speakFallback(text);
|
||||
}
|
||||
}
|
||||
|
||||
function _speakFallback(text) {
|
||||
if (!synth || !text) return;
|
||||
synth.cancel();
|
||||
const utter = new SpeechSynthesisUtterance(text);
|
||||
if (selectedVoice) utter.voice = selectedVoice;
|
||||
utter.rate = 0.92;
|
||||
utter.pitch = 0.85;
|
||||
utter.volume = 1;
|
||||
|
||||
utter.onstart = () => {
|
||||
document.getElementById('arcReactor').classList.add('speaking');
|
||||
};
|
||||
utter.onend = () => {
|
||||
document.getElementById('arcReactor').classList.remove('speaking');
|
||||
};
|
||||
|
||||
utter.rate = 0.92; utter.pitch = 0.85; utter.volume = 1;
|
||||
const reactor = document.getElementById('arcReactor');
|
||||
utter.onstart = () => reactor?.classList.add('speaking');
|
||||
utter.onend = () => reactor?.classList.remove('speaking');
|
||||
synth.speak(utter);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user