feat(hermes): Piper TTS (local US male, no cloud) #17

Merged
gortium merged 25 commits from feat/voice-support-v2 into master 2026-05-09 19:39:12 +00:00
2 changed files with 64 additions and 38 deletions
Showing only changes of commit 28213eec5c - Show all commits

View File

@@ -16,8 +16,7 @@ RUN apt-get update && \
texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-xetex texlive-science \
qemu-user-static binfmt-support qemu-user-binfmt \
emacs-nox \
libportaudio2 \
hipcc espeak-ng && \
libportaudio2 && \
rm -rf /var/lib/apt/lists/*
# Création de l'utilisateur 'hermes' directement avec les bons accès
@@ -31,74 +30,6 @@ WORKDIR /opt/hermes
# On donne la propriété du dossier de travail à l'utilisateur hermes
RUN chown hermes:hermes /opt/hermes
# ---------- Coqui TTS venv (Python 3.11 + PyTorch ROCm) ----------
# Install Python 3.11 via uv for Coqui compatibility
RUN uv python install 3.11
# Create the coqui venv and install PyTorch ROCm + TTS
RUN uv venv --python 3.11 /opt/coqui-tts
RUN uv pip install --python /opt/coqui-tts/bin/python3 --no-cache-dir \
torch==2.3.1+rocm5.7 \
torchaudio==2.3.1+rocm5.7 \
--index-url https://download.pytorch.org/whl/rocm5.7
RUN uv pip install --python /opt/coqui-tts/bin/python3 --no-cache-dir TTS setuptools
# Fix executable stack on bundled torch AMD libraries (required for ROCm)
RUN /opt/coqui-tts/bin/python3 -c "
import struct, os, glob
torch_lib = '/opt/coqui-tts/lib/python3.11/site-packages/torch/lib'
for so in glob.glob(os.path.join(torch_lib, '*.so*')):
try:
with open(so, 'r+b') as f:
if f.read(4) != b'\x7fELF': continue
f.seek(0)
h = f.read(64)
e_phoff = struct.unpack_from('<Q', h, 0x20)[0]
e_phentsize = struct.unpack_from('<H', h, 0x36)[0]
e_phnum = struct.unpack_from('<H', h, 0x38)[0]
for i in range(e_phnum):
f.seek(e_phoff + i * e_phentsize)
ph = f.read(e_phentsize)
if struct.unpack_from('<I', ph, 0)[0] == 0x6474e551:
flags = struct.unpack_from('<I', ph, 4)[0]
if flags & 1:
f.seek(e_phoff + i * e_phentsize + 4)
f.write(struct.pack('<I', flags - 1))
break
except: pass
"
# Créer le wrapper Coqui synth
RUN /opt/coqui-tts/bin/python3 -c "
script = '''#!/usr/bin/env python3
import argparse, sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--text', required=True)
parser.add_argument('--out', required=True)
parser.add_argument('--model', default='tts_models/en/vctk/vits')
parser.add_argument('--speaker', default='')
parser.add_argument('--gpu', action='store_true', default=True)
args = parser.parse_args()
try:
from TTS.api import TTS
tts = TTS(model_name=args.model, progress_bar=False, gpu=args.gpu)
kwargs = {'text': args.text, 'file_path': args.out}
if args.speaker and hasattr(tts, 'speakers') and tts.speakers:
kwargs['speaker'] = args.speaker
tts.tts_to_file(**kwargs)
print('OK:' + args.out)
except Exception as e:
print('ERROR:' + str(e), file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
main()
'''
with open('/opt/coqui-tts/bin/coqui_synth.py', 'w') as f:
f.write(script)
import os; os.chmod('/opt/coqui-tts/bin/coqui_synth.py', 0o755)
"
# ---------- Hermes venv ----------
# Passer immédiatement sous l'utilisateur hermes pour tout le reste du build
USER hermes