fix: clean patch script - only target Edge, no Coqui references

This commit is contained in:
Thierry Pouplier
2026-05-09 13:59:09 +00:00
parent 78f499bde8
commit 3f080da35e
2 changed files with 13 additions and 64 deletions

View File

@@ -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') 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 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 RUN /opt/hermes/.venv/bin/python3 /tmp/patch_tts_tool.py && rm /tmp/patch_tts_tool.py

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/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 import sys
tts_path = '/opt/hermes/.venv/lib/python3.13/site-packages/tools/tts_tool.py' 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: with open(tts_path) as f:
code = f.read() 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 # Replace the Edge fallback with Piper fallback
old_edge = ''' else: old_edge = ''' else:
# Default: Edge TTS (free), with NeuTTS as local fallback # Default: Edge TTS (free), with NeuTTS as local fallback
@@ -89,8 +37,8 @@ old_edge = ''' else:
"or set up NeuTTS for local synthesis." "or set up NeuTTS for local synthesis."
}, ensure_ascii=False)''' }, ensure_ascii=False)'''
new_piper_fallback = ''' else: new_piper = ''' else:
# Default: Piper TTS (local, CPU, no cloud) # Default: Piper TTS (local, CPU, no cloud, no Microsoft)
piper_available = False piper_available = False
try: try:
piper_binary = "/opt/hermes/.venv/bin/piper" piper_binary = "/opt/hermes/.venv/bin/piper"
@@ -127,19 +75,20 @@ new_piper_fallback = ''' else:
}, ensure_ascii=False)''' }, ensure_ascii=False)'''
if old_edge in code: 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") print("Edge fallback replaced with Piper")
else: else:
print("Edge fallback NOT found, checking if already Piper...")
if 'Default: Piper TTS' in code: if 'Default: Piper TTS' in code:
print("Piper fallback already present, skipping") print("Piper fallback already present")
else: else:
print("ERROR: Could not find Edge fallback") print("ERROR: Could not find Edge fallback in tts_tool.py")
# Debug: show what the else block looks like # Debug output
import re import re
match = re.search(r' else:\n # Default:', code) for m in re.finditer(r' else:\n # Default:', code):
if match: start = max(0, m.start() - 100)
print("Found else block at", match.start()) end = min(len(code), m.end() + 200)
print(f"Found else/default at position {m.start()}:")
print(code[start:end])
sys.exit(1) sys.exit(1)
with open(tts_path, 'w') as f: with open(tts_path, 'w') as f: