feat(tower): add gateway TTS helper

Add tts_speak() function to call the tailnet gateway TTS endpoint
(model tts-1, voice fr, response mp3). Configurable via LISAEL_TTS_URL
and LISAEL_TTS_VOICE env vars. Returns raw mp3 bytes, raises on failure.
This commit is contained in:
L'électron rare
2026-06-21 09:04:44 +02:00
parent 4bca57e514
commit f39bbdebf9
+12
View File
@@ -12,6 +12,8 @@ LVGLIMG = os.environ.get("LISAEL_LVGLIMG", os.path.join(BASE, "LVGLImage.py")
FEEDS_JSON = os.path.join(BASE, "feeds.json")
BOX_JSON = os.path.join(BASE, "box-state.json")
BOX_PORT = int(os.environ.get("LISAEL_BOX_PORT", "8080"))
TTS_URL = os.environ.get("LISAEL_TTS_URL", "http://100.78.6.122:9300/v1/audio/speech")
TTS_VOICE = os.environ.get("LISAEL_TTS_VOICE", "fr")
UA = {"User-Agent": "Mozilla/5.0"}
NS = {"itunes": "http://www.itunes.com/dtds/podcast-1.0.dtd"}
SUBS = {"": "'", "": '"', "": '"', "": "-",
@@ -104,6 +106,16 @@ def transcode(raw_path, out_path):
capture_output=True).returncode
return rc == 0 and os.path.exists(out_path)
def tts_speak(text):
"""Generate a mono mp3 announcement via the tailnet gateway. Returns bytes.
Raises on network/HTTP failure (caller decides degraded behaviour)."""
body = json.dumps({"model": "tts-1", "input": text, "voice": TTS_VOICE,
"response_format": "mp3"}).encode()
req = urllib.request.Request(TTS_URL, data=body,
headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req, timeout=30) as r:
return r.read()
def make_cover(img_bytes, key):
"""160x160 RGB565 .bin into STAGING via LVGLImage. Returns '<key>.bin' or ''."""
try: