fix: TTS available crashes on non-string tts_provider (#2034)

This commit is contained in:
Afonso Coutinho
2026-07-11 03:19:51 +01:00
committed by GitHub
parent 667f9e4cae
commit def3483032
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ class TTSService:
if provider == "local":
kokoro = self._get_kokoro()
return kokoro is not None and kokoro.available
if provider.startswith("endpoint:"):
if isinstance(provider, str) and provider.startswith("endpoint:"):
return True # assume reachable; errors surface at synthesis time
return False
@@ -0,0 +1,17 @@
from services.tts.tts_service import TTSService
def test_available_tolerates_non_string_provider(tmp_path):
"""A hand-edited/corrupt data/settings.json can store a non-string
tts_provider (e.g. null or a number). available reads it and calls
provider.startswith("endpoint:"), which raised AttributeError on a
non-str. It must instead fall through and report unavailable."""
service = TTSService(cache_dir=str(tmp_path))
service._load_settings = lambda: {
"tts_enabled": True,
"tts_provider": 123,
"tts_model": "tts-1",
"tts_voice": "alloy",
"tts_speed": "1",
}
assert service.available is False