From f39bbdebf99247c82085cbac3b16878265e81ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=27=C3=A9lectron=20rare?= <108685187+electron-rare@users.noreply.github.com> Date: Sun, 21 Jun 2026 09:04:44 +0200 Subject: [PATCH] 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. --- tower/lisael_content.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tower/lisael_content.py b/tower/lisael_content.py index dd98420..8b2bca7 100644 --- a/tower/lisael_content.py +++ b/tower/lisael_content.py @@ -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 '.bin' or ''.""" try: