38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Bound local-STT conversion errors in the pinned Hermes Agent source."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(os.environ.get("HERMES_AGENT_PATCH_ROOT", "/opt/hermes"))
|
|
|
|
|
|
def replace_exact(path: Path, before: str, after: str) -> None:
|
|
"""Replace one exact upstream fragment, failing closed on image drift."""
|
|
source = path.read_text(encoding="utf-8")
|
|
if source.count(before) != 1:
|
|
raise SystemExit(f"Hermes STT patch context changed in {path}: {before[:80]!r}")
|
|
path.write_text(source.replace(before, after, 1), encoding="utf-8")
|
|
|
|
|
|
transcription = ROOT / "tools/transcription_tools.py"
|
|
replace_exact(
|
|
transcription,
|
|
""" except subprocess.CalledProcessError as e:
|
|
details = e.stderr.strip() or e.stdout.strip() or str(e)
|
|
logger.error("ffmpeg conversion failed for %s: %s", file_path, details)
|
|
return None, f"Failed to convert audio for local STT: {details}"
|
|
""",
|
|
""" except subprocess.CalledProcessError as e:
|
|
details = e.stderr.strip() or e.stdout.strip() or str(e)
|
|
logger.error(
|
|
"ffmpeg conversion failed for %s: %s", file_path, details[-2000:]
|
|
)
|
|
return None, (
|
|
"Audio conversion failed: upload is invalid, incomplete, or uses an "
|
|
"unsupported codec"
|
|
)
|
|
""",
|
|
)
|