fix: TTS cucina - gestione asincrona voci e delay dopo cancel()

This commit is contained in:
dadaloop82
2026-03-29 15:43:46 +00:00
parent f87e2204a9
commit bba6551b37
+19 -7
View File
@@ -6076,14 +6076,26 @@ function renderCookingStep() {
function speakCookingStep(text) {
if (!('speechSynthesis' in window)) return;
window.speechSynthesis.cancel();
const utt = new SpeechSynthesisUtterance(text);
utt.lang = 'it-IT';
utt.rate = 0.9;
utt.pitch = 1.0;
function _doSpeak() {
const utt = new SpeechSynthesisUtterance(text);
utt.lang = 'it-IT';
utt.rate = 0.9;
utt.pitch = 1.0;
const voices = window.speechSynthesis.getVoices();
const itVoice = voices.find(v => v.lang.startsWith('it'));
if (itVoice) utt.voice = itVoice;
window.speechSynthesis.speak(utt);
}
// Voices may not be ready yet on first load — wait for voiceschanged if empty
const voices = window.speechSynthesis.getVoices();
const itVoice = voices.find(v => v.lang.startsWith('it'));
if (itVoice) utt.voice = itVoice;
window.speechSynthesis.speak(utt);
if (voices.length > 0) {
// Small delay after cancel() to avoid the speak being silently dropped
setTimeout(_doSpeak, 50);
} else {
window.speechSynthesis.addEventListener('voiceschanged', () => setTimeout(_doSpeak, 50), { once: true });
}
}
function toggleCookingTTS() {