fix: clean Dockerfile with Piper TTS, external patch script
This commit is contained in:
@@ -38,49 +38,24 @@ USER hermes
|
||||
# On copie tout le projet d'un coup sans assumer la présence de fichiers de lock spécifiques
|
||||
COPY --chown=hermes:hermes . .
|
||||
|
||||
# ---------- Python virtualenv ----------
|
||||
# ---------- Python virtualenv avec Piper TTS ----------
|
||||
RUN uv venv && \
|
||||
uv pip install --no-cache-dir sounddevice numpy faster-whisper
|
||||
uv pip install --no-cache-dir piper-tts sounddevice numpy faster-whisper
|
||||
|
||||
# ---------- Patch tts_tool.py to add Coqui provider ----------
|
||||
RUN /opt/hermes/.venv/bin/python3 -c "
|
||||
tts_path = '/opt/hermes/.venv/lib/python3.13/site-packages/tools/tts_tool.py'
|
||||
with open(tts_path) as f:
|
||||
code = f.read()
|
||||
coqui_block = '''
|
||||
elif provider == \"coqui\":
|
||||
logger.info(\"Generating speech with Coqui TTS (GPU, local)...\")
|
||||
import subprocess
|
||||
coqui_python = \"/opt/coqui-tts/bin/python3\"
|
||||
coqui_script = \"/opt/coqui-tts/bin/coqui_synth.py\"
|
||||
coqui_config = tts_config.get(\"coqui\", {})
|
||||
model = coqui_config.get(\"model\", \"tts_models/en/vctk/vits\")
|
||||
use_gpu = coqui_config.get(\"use_gpu\", True)
|
||||
speaker = coqui_config.get(\"speaker\", \"\")
|
||||
cmd = [
|
||||
coqui_python, coqui_script,
|
||||
\"--text\", text,
|
||||
\"--out\", file_str,
|
||||
\"--model\", model,
|
||||
]
|
||||
if use_gpu:
|
||||
cmd.append(\"--gpu\")
|
||||
if speaker:
|
||||
cmd.extend([\"--speaker\", speaker])
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
||||
if result.returncode != 0:
|
||||
stderr = result.stderr.strip()
|
||||
raise RuntimeError(f\"Coqui TTS failed: {stderr or 'unknown error'}\")
|
||||
logger.info(\"Coqui TTS audio saved: %s\", file_str)
|
||||
'''
|
||||
code = code.replace(
|
||||
' else:\n # Default: Edge TTS (free), with NeuTTS as local fallback',
|
||||
coqui_block + ' else:\n # Default: Edge TTS (free), with NeuTTS as local fallback'
|
||||
)
|
||||
with open(tts_path, 'w') as f:
|
||||
f.write(code)
|
||||
# ---------- Télécharger la voix Piper Ryan ----------
|
||||
RUN mkdir -p /opt/hermes/.venv/share/piper/voices && \
|
||||
/opt/hermes/.venv/bin/python3 -c "
|
||||
import urllib.request
|
||||
base = '/opt/hermes/.venv/share/piper/voices'
|
||||
url = 'https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/ryan/high/en_US-ryan-high.onnx'
|
||||
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 ----------
|
||||
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
|
||||
|
||||
# ---------- Runtime ----------
|
||||
ENV HERMES_HOME=/opt/data
|
||||
ENV PATH="/opt/data/.local/bin:${PATH}"
|
||||
|
||||
Reference in New Issue
Block a user