fix(tts): pocket-tts refuză text cu diacritice RO în loc să-l pronunțe greșit

Kyutai pocket-tts nu suportă română (vezi eval anterior). Codul rula
oricum sinteza pe orice text primit; acum _synthesize_pockettts
respinge diacriticele RO înainte de request, fără fallback silențios
pe altă voce.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 17:30:12 +00:00
parent a043e2f177
commit 00ac971044
3 changed files with 34 additions and 0 deletions

View File

@@ -53,6 +53,15 @@ class _PocketTTSUnavailable(Exception):
"""pocket-tts server e nereachable sau eșuează server-side (5xx) — caller-ul trebuie să facă fallback pe Supertonic."""
# pocket-tts e monolingv engleză per deployment — diacriticele RO sunt un semnal
# sigur că textul n-a fost tradus (vezi personality/TOOLS.md).
_RO_DIACRITICS = set("ăâîșțĂÂÎȘȚşţŞŢ")
def _looks_romanian(text: str) -> bool:
return any(ch in _RO_DIACRITICS for ch in text)
def sanitize_for_supertonic(text: str) -> str:
"""Replace Unicode punctuation and strip chars that crash Supertonic's ONNX model."""
for src, dst in _TTS_PUNCT_MAP.items():
@@ -172,6 +181,12 @@ def _synthesize_pockettts(text: str, entry: dict) -> dict:
Raises:
_PocketTTSUnavailable: eșec tehnic (connect error/timeout/5xx) — caller-ul face fallback.
"""
if _looks_romanian(text):
return {
"ok": False,
"error": "pocket-tts nu suportă română — textul trebuie să fie în engleză.",
}
state_path = entry.get("state_path")
voice_url = entry.get("voice_url")