fix: browser TTS ignored when HA TTS configured; wrong ha_hint i18n key

- speakCookingStep: respect tts_engine='browser' explicitly; if user
  chose browser engine, always use _speakBrowser regardless of HA.
  Also add per-engine try/catch so HA or server TTS failures fall back
  to browser TTS instead of silently doing nothing.
- index.html: fix data-i18n='settings.tts.ha_hint' → 'settings.ha.ha_hint'
  (key lived in settings.ha not settings.tts)
This commit is contained in:
dadaloop82
2026-05-25 10:37:17 +00:00
parent bac9485e4e
commit 83b5eb3063
2 changed files with 18 additions and 9 deletions
+17 -8
View File
@@ -13733,17 +13733,26 @@ async function _ttsViaProxy(req) {
async function speakCookingStep(text) {
if (!text) return;
const s = getSettings();
// Use custom TTS endpoint only when explicitly configured; otherwise always use browser TTS.
// Respect the user's explicit engine choice.
// Do NOT gate on s.tts_enabled — the _cookingTTS toggle in cooking mode is the only gate.
// If the preferred engine fails, always fall back to browser TTS.
const fallback = () => _speakBrowser(text);
try {
// 1. HA TTS — if HA is enabled and a media player entity is configured
if (s.ha_enabled && s.ha_tts_entity && s.ha_url) {
const req = _buildHaTtsRequest(text, s);
await _ttsViaProxy(req);
// 2. Generic external endpoint ('server' or legacy 'custom' engine)
// 1. Browser engine — always use Web Speech API / kiosk bridge directly
if (!s.tts_engine || s.tts_engine === 'browser') {
_speakBrowser(text);
// 2. HA TTS — if HA is enabled and a media player entity is configured
} else if (s.ha_enabled && s.ha_tts_entity && s.ha_url) {
try {
const req = _buildHaTtsRequest(text, s);
await _ttsViaProxy(req);
} catch(e) { fallback(); }
// 3. Generic external endpoint ('server' or legacy 'custom' engine)
} else if ((s.tts_engine === 'server' || s.tts_engine === 'custom') && s.tts_url) {
const req = _buildTtsRequest(text, s);
await _ttsViaProxy(req);
try {
const req = _buildTtsRequest(text, s);
await _ttsViaProxy(req);
} catch(e) { fallback(); }
} else {
_speakBrowser(text);
}
+1 -1
View File
@@ -1318,7 +1318,7 @@
<div id="tts-test-status" style="display:none;margin-top:8px"></div>
<!-- HA TTS quick-fill hint -->
<div style="margin-top:12px;padding:10px 12px;background:rgba(3,169,244,0.07);border:1px solid rgba(3,169,244,0.25);border-radius:8px;font-size:0.82rem">
<span data-i18n="settings.tts.ha_hint">🏠 Se usi Home Assistant, usa il tab <strong>Home Assistant</strong> per configurare TTS, webhook e sensori.</span>
<span data-i18n="settings.ha.ha_hint">🏠 Se usi Home Assistant, usa il tab <strong>Home Assistant</strong> per configurare TTS, webhook e sensori.</span>
</div>
</div>
</div>