Compare commits
24 Commits
c2471818b2
...
fix/hermes
| Author | SHA1 | Date | |
|---|---|---|---|
| 93c01fa314 | |||
| 6e540635bf | |||
|
|
b89be7b8f4 | ||
|
|
748b5037b9 | ||
|
|
3f80744ebd | ||
|
|
6f17743667 | ||
|
|
98216d2872 | ||
|
|
a40e347dfa | ||
|
|
cfa2a898c3 | ||
|
|
0609720b33 | ||
|
|
d97f1cb1e5 | ||
|
|
1a1cfec80a | ||
|
|
90e227bc4e | ||
|
|
8e9a75fe5c | ||
|
|
3016d0da2c | ||
|
|
b750d26d80 | ||
|
|
0a9507de65 | ||
|
|
b3fa424661 | ||
|
|
77fe8133ae | ||
|
|
3f080da35e | ||
|
|
78f499bde8 | ||
|
|
e779818e73 | ||
|
|
25d7611043 | ||
|
|
28213eec5c |
189
ai/Dockerfile
189
ai/Dockerfile
@@ -1,160 +1,73 @@
|
|||||||
# 1. On récupère la version la plus récente d'UV
|
# 1. On récupère la version la plus récente d'UV
|
||||||
FROM ghcr.io/astral-sh/uv:latest AS uv_source
|
FROM ghcr.io/astral-sh/uv:latest AS uv_source
|
||||||
|
|
||||||
# 2. Image de base stable
|
# 2. Image officielle Hermes Agent de NousResearch
|
||||||
FROM debian:stable-slim
|
# Contient déjà: Python, Node.js, npm, Playwright/Chromium, venv, tts_tool.py, etc.
|
||||||
|
FROM nousresearch/hermes-agent:latest
|
||||||
|
|
||||||
# Disable Python stdout buffering to ensure logs are printed immediately
|
# ---------- System dependencies ----------
|
||||||
ENV PYTHONUNBUFFERED=1
|
# The official hermes-agent image already has: git, curl, ffmpeg, python3,
|
||||||
|
# gcc, build-essential, openssh-client, procps, tini, ripgrep, docker-cli,
|
||||||
# Install system dependencies in one layer, clear APT cache
|
# libportaudio2, ca-certificates, etc.
|
||||||
# tini reaps orphaned zombie processes (MCP stdio subprocesses, git, bun, etc.)
|
#
|
||||||
|
# These extras we need to add back:
|
||||||
|
# - poppler-utils, imagemagick (PDF/image processing)
|
||||||
|
# - texlive-* (LaTeX typesetting for reports)
|
||||||
|
# - qemu-user-static, binfmt-support (QEMU cross-compilation)
|
||||||
|
# - emacs-nox (text editing in container)
|
||||||
|
USER root
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
build-essential python3 ripgrep ffmpeg gcc python3-dev libffi-dev procps git openssh-client docker-cli tini \
|
|
||||||
curl poppler-utils imagemagick \
|
|
||||||
texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-xetex texlive-science \
|
|
||||||
qemu-user-static binfmt-support qemu-user-binfmt \
|
|
||||||
emacs-nox \
|
|
||||||
libportaudio2 \
|
libportaudio2 \
|
||||||
hipcc espeak-ng && \
|
ca-certificates \
|
||||||
|
poppler-utils \
|
||||||
|
imagemagick \
|
||||||
|
texlive-latex-base \
|
||||||
|
texlive-latex-extra \
|
||||||
|
texlive-fonts-recommended \
|
||||||
|
texlive-xetex \
|
||||||
|
texlive-science \
|
||||||
|
qemu-user-static \
|
||||||
|
binfmt-support \
|
||||||
|
emacs-nox && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Création de l'utilisateur 'hermes' directement avec les bons accès
|
# ---------- UV (hyperfast pip alternative) ----------
|
||||||
RUN useradd -u 10000 -m -d /opt/data hermes
|
|
||||||
|
|
||||||
# Copie d'uv (dernière version)
|
|
||||||
COPY --chmod=0755 --from=uv_source /uv /usr/local/bin/
|
COPY --chmod=0755 --from=uv_source /uv /usr/local/bin/
|
||||||
|
|
||||||
WORKDIR /opt/hermes
|
WORKDIR /opt/hermes
|
||||||
|
|
||||||
# On donne la propriété du dossier de travail à l'utilisateur hermes
|
# ---------- Piper TTS dans le venv existant ----------
|
||||||
RUN chown hermes:hermes /opt/hermes
|
# Le venv de l'image de base est root-owned, on doit installer en root aussi
|
||||||
|
RUN . /opt/hermes/.venv/bin/activate && \
|
||||||
|
uv pip install --no-cache-dir piper-tts sounddevice numpy
|
||||||
|
|
||||||
# ---------- Coqui TTS venv (Python 3.11 + PyTorch ROCm) ----------
|
# ---------- Télécharger la voix Piper Ryan (high quality) ----------
|
||||||
# Install Python 3.11 via uv for Coqui compatibility
|
RUN mkdir -p /opt/hermes/.venv/share/piper/voices && \
|
||||||
RUN uv python install 3.11
|
/opt/hermes/.venv/bin/python3 /dev/stdin << 'PYEOF'
|
||||||
|
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, base + '/en_US-ryan-high.onnx')
|
||||||
|
urllib.request.urlretrieve(url + '.json', base + '/en_US-ryan-high.onnx.json')
|
||||||
|
PYEOF
|
||||||
|
|
||||||
# Create the coqui venv and install PyTorch ROCm + TTS
|
# ---------- Patch tts_tool.py: remplacer Edge TTS par Piper ----------
|
||||||
RUN uv venv --python 3.11 /opt/coqui-tts
|
# Edge TTS appelle les serveurs Microsoft — on ne veut jamais ça.
|
||||||
RUN uv pip install --python /opt/coqui-tts/bin/python3 --no-cache-dir \
|
# Piper roule localement sur CPU, aucun cloud, aucune donnée qui sort.
|
||||||
torch==2.3.1+rocm5.7 \
|
COPY patch_tts_tool.py /tmp/patch_tts_tool.py
|
||||||
torchaudio==2.3.1+rocm5.7 \
|
RUN /opt/hermes/.venv/bin/python3 /tmp/patch_tts_tool.py && rm /tmp/patch_tts_tool.py
|
||||||
--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
|
|
||||||
|
|
||||||
# ---------- Source code ----------
|
|
||||||
# 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 ----------
|
|
||||||
RUN uv venv && \
|
|
||||||
uv pip install --no-cache-dir 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)
|
|
||||||
"
|
|
||||||
|
|
||||||
# ---------- Runtime ----------
|
# ---------- Runtime ----------
|
||||||
|
# Retour à l'utilisateur non-root pour la sécurité
|
||||||
|
USER hermes
|
||||||
|
|
||||||
ENV HERMES_HOME=/opt/data
|
ENV HERMES_HOME=/opt/data
|
||||||
ENV PATH="/opt/data/.local/bin:${PATH}"
|
ENV PATH="/opt/data/.local/bin:${PATH}"
|
||||||
|
|
||||||
VOLUME [ "/opt/data" ]
|
VOLUME [ "/opt/data" ]
|
||||||
|
|
||||||
# Le conteneur tourne de manière ultra-sécurisée sous l'utilisateur hermes dès le départ
|
# Script de réparation des permissions + patch TTS au démarrage
|
||||||
ENTRYPOINT [ "/usr/bin/tini", "-g", "--", "/opt/hermes/docker/entrypoint.sh" ]
|
COPY --chmod=0755 fix-permissions.sh /opt/hermes/fix-permissions.sh
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/usr/bin/tini", "-g", "--", "/opt/hermes/fix-permissions.sh" ]
|
||||||
|
|||||||
@@ -38,13 +38,14 @@ services:
|
|||||||
- API_SERVER_HOST=0.0.0.0
|
- API_SERVER_HOST=0.0.0.0
|
||||||
- API_SERVER_KEY=hermes_local_key
|
- API_SERVER_KEY=hermes_local_key
|
||||||
- GATEWAY_ALLOW_ALL_USERS=true
|
- GATEWAY_ALLOW_ALL_USERS=true
|
||||||
- OPENROUTER_API_KEY=${OPEN...KEY}
|
- OPENROUTER_API_KEY=${OPENROUTER_API_KEY}
|
||||||
# ROCm for GPU-accelerated faster-whisper STT
|
# ROCm for GPU-accelerated faster-whisper STT
|
||||||
- HSA_OVERRIDE_GFX_VERSION=9.0.6
|
- HSA_OVERRIDE_GFX_VERSION=9.0.6
|
||||||
- HCC_AMDGPU_TARGET=gfx906
|
- HCC_AMDGPU_TARGET=gfx906
|
||||||
- HIP_VISIBLE_DEVICES=0,1
|
- HIP_VISIBLE_DEVICES=0,1
|
||||||
- ROCR_VISIBLE_DEVICES=0,1
|
- ROCR_VISIBLE_DEVICES=0,1
|
||||||
- HSA_ENABLE_SDMA=0
|
- HSA_ENABLE_SDMA=0
|
||||||
|
- TZ=America/Montreal
|
||||||
volumes:
|
volumes:
|
||||||
- /mnt/HoardingCow_docker_data/Hermes/data:/opt/data
|
- /mnt/HoardingCow_docker_data/Hermes/data:/opt/data
|
||||||
devices:
|
devices:
|
||||||
|
|||||||
38
ai/fix-permissions.sh
Normal file
38
ai/fix-permissions.sh
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Startup permission fix + TTS patch.
|
||||||
|
# Runs as root before the entrypoint drops to the hermes user.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
HERMES_HOME="${HERMES_HOME:-/opt/data}"
|
||||||
|
|
||||||
|
# Fix ownership on critical writable directories
|
||||||
|
chown -R hermes:hermes \
|
||||||
|
"$HERMES_HOME/sessions" \
|
||||||
|
"$HERMES_HOME/checkpoints" \
|
||||||
|
"$HERMES_HOME/skills" \
|
||||||
|
"$HERMES_HOME/memories" \
|
||||||
|
"$HERMES_HOME/workspace" \
|
||||||
|
"$HERMES_HOME/pastes" \
|
||||||
|
"$HERMES_HOME/logs" \
|
||||||
|
"$HERMES_HOME/cron" \
|
||||||
|
"$HERMES_HOME/plans" \
|
||||||
|
"$HERMES_HOME/hooks" \
|
||||||
|
"$HERMES_HOME/cache" \
|
||||||
|
2>/dev/null || true
|
||||||
|
|
||||||
|
# Fix data volume root ownership
|
||||||
|
if [ "$(stat -c %u "$HERMES_HOME" 2>/dev/null)" != "$(id -u hermes)" ]; then
|
||||||
|
chown hermes:hermes "$HERMES_HOME" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ---------- Patch tts_tool.py: replace Edge TTS with Piper ----------
|
||||||
|
# Fallback runtime patch in case the volume's site-packages differ from the image.
|
||||||
|
# Idempotent: if already patched, the script does nothing.
|
||||||
|
PATCH_SCRIPT="/opt/hermes/patch_tts_tool.py"
|
||||||
|
if [ -f "$PATCH_SCRIPT" ]; then
|
||||||
|
echo "Applying TTS patch (Piper only, no Edge fallback)..."
|
||||||
|
/opt/hermes/.venv/bin/python3 "$PATCH_SCRIPT" 2>&1 || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Chain to the official Hermes entrypoint
|
||||||
|
exec /opt/hermes/docker/entrypoint.sh "$@"
|
||||||
181
ai/patch_tts_tool.py
Normal file
181
ai/patch_tts_tool.py
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Patch Hermes TTS tool: add Piper TTS provider, remove Edge TTS as default.
|
||||||
|
|
||||||
|
Patches ALL copies of tts_tool.py found (venv site-packages + /opt/hermes/tools/).
|
||||||
|
|
||||||
|
Searches multiple paths for tts_tool.py so it works both at build time
|
||||||
|
(in the image venv) and at runtime (on the mounted data volume).
|
||||||
|
|
||||||
|
Idempotent: if already patched, does nothing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Search for all copies of tts_tool.py
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
CANDIDATE_PATHS = [
|
||||||
|
"/opt/hermes/.venv/lib/python3.13/site-packages/tools/tts_tool.py",
|
||||||
|
"/opt/hermes/tools/tts_tool.py",
|
||||||
|
]
|
||||||
|
|
||||||
|
found_paths = []
|
||||||
|
|
||||||
|
for p in CANDIDATE_PATHS:
|
||||||
|
if os.path.exists(p):
|
||||||
|
found_paths.append(p)
|
||||||
|
print(f"Found tts_tool.py at: {p}")
|
||||||
|
|
||||||
|
# Also try to find via Python import
|
||||||
|
import subprocess
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
[sys.executable, "-c", "import tools.tts_tool; print(tools.tts_tool.__file__)"],
|
||||||
|
capture_output=True, text=True, timeout=5
|
||||||
|
)
|
||||||
|
if result.returncode == 0:
|
||||||
|
p = result.stdout.strip()
|
||||||
|
if os.path.exists(p) and p not in found_paths:
|
||||||
|
found_paths.append(p)
|
||||||
|
print(f"Found tts_tool.py via import at: {p}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not found_paths:
|
||||||
|
print("WARNING: tts_tool.py not found anywhere. Patching deferred to runtime.")
|
||||||
|
print(f"Searched: {CANDIDATE_PATHS}")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Old else block: the Edge TTS default fallback to replace
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
old_else = ''' else:
|
||||||
|
# Default: Edge TTS (free), with NeuTTS as local fallback
|
||||||
|
edge_available = True
|
||||||
|
try:
|
||||||
|
_import_edge_tts()
|
||||||
|
except ImportError:
|
||||||
|
edge_available = False
|
||||||
|
|
||||||
|
if edge_available:
|
||||||
|
logger.info("Generating speech with Edge TTS...")
|
||||||
|
try:
|
||||||
|
import concurrent.futures
|
||||||
|
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
|
||||||
|
pool.submit(
|
||||||
|
lambda: asyncio.run(_generate_edge_tts(text, file_str, tts_config))
|
||||||
|
).result(timeout=60)
|
||||||
|
except RuntimeError:
|
||||||
|
asyncio.run(_generate_edge_tts(text, file_str, tts_config))
|
||||||
|
elif _check_neutts_available():
|
||||||
|
logger.info("Edge TTS not available, falling back to NeuTTS (local)...")
|
||||||
|
provider = "neutts"
|
||||||
|
_generate_neutts(text, file_str, tts_config)
|
||||||
|
else:
|
||||||
|
return json.dumps({
|
||||||
|
"success": False,
|
||||||
|
"error": "No TTS provider available. Install edge-tts (pip install edge-tts) "
|
||||||
|
"or set up NeuTTS for local synthesis."
|
||||||
|
}, ensure_ascii=False)'''
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# New block: elif provider == "piper" + else: fallback with Piper only
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
new_block = ''' elif provider == "piper":
|
||||||
|
# Piper TTS (local, CPU, no cloud, no Microsoft)
|
||||||
|
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):
|
||||||
|
return json.dumps({
|
||||||
|
"success": False,
|
||||||
|
"error": "Piper TTS voice model not found. "
|
||||||
|
"Install Piper TTS and download a voice model."
|
||||||
|
}, ensure_ascii=False)
|
||||||
|
logger.info("Generating speech with Piper TTS (local, CPU)...")
|
||||||
|
import subprocess as _sp
|
||||||
|
cmd = [piper_binary, "--model", model_path, "--output-raw"]
|
||||||
|
try:
|
||||||
|
proc = _sp.Popen(cmd, stdin=_sp.PIPE, stdout=_sp.PIPE, stderr=_sp.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]
|
||||||
|
_sp.run(ffmpeg_cmd, input=raw_audio, capture_output=True, timeout=30)
|
||||||
|
except Exception as e:
|
||||||
|
return json.dumps({
|
||||||
|
"success": False,
|
||||||
|
"error": f"Piper TTS failed: {e}"
|
||||||
|
}, ensure_ascii=False)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Default: Piper TTS (local, CPU, no cloud, no Microsoft)
|
||||||
|
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 os.path.exists(model_path) and os.path.exists(piper_binary):
|
||||||
|
logger.info("Generating speech with Piper TTS (local, CPU)...")
|
||||||
|
import subprocess as _sp
|
||||||
|
cmd = [piper_binary, "--model", model_path, "--output-raw"]
|
||||||
|
try:
|
||||||
|
proc = _sp.Popen(cmd, stdin=_sp.PIPE, stdout=_sp.PIPE, stderr=_sp.PIPE)
|
||||||
|
raw_audio, stderr = proc.communicate(input=text.encode(), timeout=60)
|
||||||
|
if proc.returncode != 0:
|
||||||
|
raise RuntimeError(stderr.decode()[:200])
|
||||||
|
ffmpeg_cmd = ["ffmpeg", "-f", "s16le", "-ar", "22050", "-ac", "1", "-i", "-", "-y", file_str]
|
||||||
|
_sp.run(ffmpeg_cmd, input=raw_audio, capture_output=True, timeout=30)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return json.dumps({
|
||||||
|
"success": False,
|
||||||
|
"error": "Piper TTS not available. Install piper-tts and download a voice model."
|
||||||
|
}, ensure_ascii=False)'''
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Apply the patch to all copies found
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
patched_any = False
|
||||||
|
|
||||||
|
for tts_path in found_paths:
|
||||||
|
with open(tts_path) as f:
|
||||||
|
code = f.read()
|
||||||
|
|
||||||
|
if 'provider == "piper"' in code:
|
||||||
|
print(f"ALREADY PATCHED: {tts_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if old_else in code:
|
||||||
|
code = code.replace(old_else, new_block, 1)
|
||||||
|
with open(tts_path, 'w') as f:
|
||||||
|
f.write(code)
|
||||||
|
print(f"PATCHED: {tts_path}")
|
||||||
|
patched_any = True
|
||||||
|
else:
|
||||||
|
print(f"SKIP {tts_path}: Edge fallback pattern not found")
|
||||||
|
import re
|
||||||
|
for m in re.finditer(r' else:\n # Default:', code):
|
||||||
|
start = max(0, m.start() - 100)
|
||||||
|
end = min(len(code), m.end() + 300)
|
||||||
|
print(f" Found 'else:/# Default:' at position {m.start()}:")
|
||||||
|
print(f" {code[start:end]}")
|
||||||
|
print(" ---")
|
||||||
|
# Don't exit with error — if one copy isn't patchable, try the others
|
||||||
|
|
||||||
|
if not patched_any:
|
||||||
|
all_patched = all(
|
||||||
|
'provider == "piper"' in open(p).read()
|
||||||
|
for p in found_paths
|
||||||
|
)
|
||||||
|
if all_patched:
|
||||||
|
print("All copies already patched.")
|
||||||
|
sys.exit(0)
|
||||||
|
print("WARNING: Could not patch any copy of tts_tool.py")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("tts_tool.py patched successfully across all copies.")
|
||||||
Reference in New Issue
Block a user