fix: TTS primo step con voce corretta, bottone Rileggi sempre visibile

- startCookingMode: attende voiceschanged prima di parlare il primo step
  cosi la voce Google (donna) viene usata subito, non il fallback robot
- _cookingTTS parte sempre true (attivato), icona 🔊
- Bottone Rileggi visibile di default senza display:none
- Cache buster aggiornato a v=20260329c
This commit is contained in:
dadaloop82
2026-03-29 16:00:24 +00:00
parent 23e8d9a6b8
commit 2d754526a5
2 changed files with 26 additions and 11 deletions
+24 -9
View File
@@ -6009,15 +6009,34 @@ function startCookingMode() {
}
_cookingRecipe = JSON.parse(JSON.stringify(recipe)); // deep copy so we can track .used
_cookingStep = 0;
_cookingTTS = 'speechSynthesis' in window;
_cookingTTS = true;
document.getElementById('cooking-title').textContent = _cookingRecipe.title || '';
document.getElementById('cooking-tts-btn').textContent = _cookingTTS ? '🔊' : '🔇';
document.getElementById('cooking-tts-btn').textContent = '🔊';
document.getElementById('cooking-overlay').style.display = 'flex';
document.body.classList.add('cooking-mode-active');
try { screen.orientation?.lock('portrait'); } catch (_) { /* ignore */ }
// Preload voices for TTS
if (_cookingTTS) window.speechSynthesis.getVoices();
renderCookingStep();
// Ensure voices are loaded, then render (and speak) the first step
if ('speechSynthesis' in window) {
const voices = window.speechSynthesis.getVoices();
if (voices.length > 0) {
renderCookingStep();
} else {
// Voices not yet loaded — render immediately (muted), then re-speak after voices arrive
renderCookingStep();
window.speechSynthesis.addEventListener('voiceschanged', function _onVoices() {
window.speechSynthesis.removeEventListener('voiceschanged', _onVoices);
if (_cookingTTS && _cookingStep === 0) {
const text = (_cookingRecipe.steps[0] || '').replace(/^Passo\s*\d+\s*[:.]\s*/i, '');
if (text) speakCookingStep(text);
}
});
}
} else {
_cookingTTS = false;
document.getElementById('cooking-tts-btn').textContent = '🔇';
renderCookingStep();
}
}
function closeCookingMode() {
@@ -6063,10 +6082,6 @@ function renderCookingStep() {
ingsEl.style.display = 'none';
}
// Replay button
const replayBtn = document.getElementById('cooking-replay');
if (replayBtn) replayBtn.style.display = 'speechSynthesis' in window ? 'inline-flex' : 'none';
// Navigation button states
const prevBtn = document.getElementById('cooking-prev');
const nextBtn = document.getElementById('cooking-next');
+2 -2
View File
@@ -981,7 +981,7 @@
<div class="cooking-body">
<div class="cooking-step-num" id="cooking-step-num">1 / 1</div>
<div class="cooking-step-text" id="cooking-step-text"></div>
<button class="cooking-replay-btn" id="cooking-replay" onclick="replayCookingTTS()" title="Rileggi questo passo" style="display:none">🔊 Rileggi</button>
<button class="cooking-replay-btn" id="cooking-replay" onclick="replayCookingTTS()" title="Rileggi questo passo">🔊 Rileggi</button>
<div class="cooking-step-ings" id="cooking-step-ings" style="display:none"></div>
</div>
<div class="cooking-nav">
@@ -990,6 +990,6 @@
</div>
</div>
<script src="assets/js/app.js?v=20260329b"></script>
<script src="assets/js/app.js?v=20260329c"></script>
</body>
</html>