From 3f080da35e95e37eef468a1865da55d831fdf0be Mon Sep 17 00:00:00 2001 From: Thierry Pouplier Date: Sat, 9 May 2026 13:59:09 +0000 Subject: [PATCH] fix: clean patch script - only target Edge, no Coqui references --- ai/Dockerfile | 2 +- ai/patch_tts_tool.py | 75 +++++++------------------------------------- 2 files changed, 13 insertions(+), 64 deletions(-) diff --git a/ai/Dockerfile b/ai/Dockerfile index 87bdd34..bdd22c8 100644 --- a/ai/Dockerfile +++ b/ai/Dockerfile @@ -52,7 +52,7 @@ urllib.request.urlretrieve(url + '?download=true', base + '/en_US-ryan-high.onnx urllib.request.urlretrieve(url + '.onnx.json?download=true', base + '/en_US-ryan-high.onnx.json') " -# ---------- Patch tts_tool.py: remplacer Coqui par Piper, supprimer Edge ---------- +# ---------- Patch tts_tool.py: replace Edge TTS fallback with Piper ---------- COPY ai/patch_tts_tool.py /tmp/patch_tts_tool.py RUN /opt/hermes/.venv/bin/python3 /tmp/patch_tts_tool.py && rm /tmp/patch_tts_tool.py diff --git a/ai/patch_tts_tool.py b/ai/patch_tts_tool.py index 4791132..0187d3c 100644 --- a/ai/patch_tts_tool.py +++ b/ai/patch_tts_tool.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Patch Hermes TTS tool to add Piper provider and remove Edge TTS fallback.""" +"""Patch Hermes TTS tool: remove Edge TTS, replace with Piper as default/fallback.""" import sys tts_path = '/opt/hermes/.venv/lib/python3.13/site-packages/tools/tts_tool.py' @@ -7,58 +7,6 @@ tts_path = '/opt/hermes/.venv/lib/python3.13/site-packages/tools/tts_tool.py' with open(tts_path) as f: code = f.read() -# Replace the Coqui provider block with Piper -old_coqui = ' elif provider == "coqui":' -new_piper = ''' elif provider == "piper": - logger.info("Generating speech with Piper TTS (local, CPU)...") - import subprocess - piper_binary = "/opt/hermes/.venv/bin/piper" - piper_config = tts_config.get("piper", {}) - voice = piper_config.get("voice", "en_US-lessac-medium") - model_dir = piper_config.get("model_dir", "/opt/hermes/.venv/share/piper/voices") - model_path = os.path.join(model_dir, f"{voice}.onnx") - if not os.path.exists(model_path): - raise FileNotFoundError(f"Piper voice model not found: {model_path}") - cmd = [piper_binary, "--model", model_path, "--output-raw"] - proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_audio, stderr = proc.communicate(input=text.encode(), timeout=60) - if proc.returncode != 0: - raise RuntimeError(f"Piper TTS failed: {stderr.decode()[:200]}") - ffmpeg_cmd = ["ffmpeg", "-f", "s16le", "-ar", "22050", "-ac", "1", "-i", "-", "-y", file_str] - subprocess.run(ffmpeg_cmd, input=raw_audio, capture_output=True, timeout=30) - logger.info("Piper TTS audio saved: %s", file_str)''' - -if old_coqui in code: - code = code.replace(old_coqui, new_piper) - print("Coqui -> Piper replaced") -else: - # Fresh Hermes install - add Piper after the last provider (kittentts) - if 'provider == "piper"' in code: - print("Piper already present, skipping coqui replacement") - else: - print("Stock Hermes - adding Piper provider after kittentts...") - marker = ' elif provider == "kittentts":' - if marker in code: - # Find the end of the kittentts block and insert Piper before else - lines = code.split('\n') - kit_idx = None - for i, line in enumerate(lines): - if line.strip().startswith('elif provider == "kittentts":'): - kit_idx = i - break - if kit_idx is not None: - # Find the next blank line + else block - for i in range(kit_idx, len(lines)): - if lines[i].strip() == 'else:': - # Insert Piper block before this line - indent = ' ' - piper_lines = new_piper.split('\n') - insert = piper_lines + [''] - lines[i:i] = insert - code = '\n'.join(lines) - print("Piper provider added after kittentts") - break - # Replace the Edge fallback with Piper fallback old_edge = ''' else: # Default: Edge TTS (free), with NeuTTS as local fallback @@ -89,8 +37,8 @@ old_edge = ''' else: "or set up NeuTTS for local synthesis." }, ensure_ascii=False)''' -new_piper_fallback = ''' else: - # Default: Piper TTS (local, CPU, no cloud) +new_piper = ''' else: + # Default: Piper TTS (local, CPU, no cloud, no Microsoft) piper_available = False try: piper_binary = "/opt/hermes/.venv/bin/piper" @@ -127,19 +75,20 @@ new_piper_fallback = ''' else: }, ensure_ascii=False)''' if old_edge in code: - code = code.replace(old_edge, new_piper_fallback) + code = code.replace(old_edge, new_piper) print("Edge fallback replaced with Piper") else: - print("Edge fallback NOT found, checking if already Piper...") if 'Default: Piper TTS' in code: - print("Piper fallback already present, skipping") + print("Piper fallback already present") else: - print("ERROR: Could not find Edge fallback") - # Debug: show what the else block looks like + print("ERROR: Could not find Edge fallback in tts_tool.py") + # Debug output import re - match = re.search(r' else:\n # Default:', code) - if match: - print("Found else block at", match.start()) + for m in re.finditer(r' else:\n # Default:', code): + start = max(0, m.start() - 100) + end = min(len(code), m.end() + 200) + print(f"Found else/default at position {m.start()}:") + print(code[start:end]) sys.exit(1) with open(tts_path, 'w') as f: