44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Shim: translate_srt_local
|
|
|
|
Delegates to `whisper_project.infra.marian_adapter.MarianTranslator.translate_srt`
|
|
if available; otherwise falls back to running the script in `examples/`.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser(prog="translate_srt_local")
|
|
p.add_argument("--in", dest="in_srt", required=True)
|
|
p.add_argument("--out", dest="out_srt", required=True)
|
|
args = p.parse_args()
|
|
|
|
try:
|
|
# Prefer the infra adapter when available
|
|
from whisper_project.infra.marian_adapter import MarianTranslator
|
|
|
|
t = MarianTranslator()
|
|
t.translate_srt(args.in_srt, args.out_srt)
|
|
return
|
|
except Exception:
|
|
# Fallback: run the examples script if present
|
|
try:
|
|
script = "examples/translate_srt_local.py"
|
|
cmd = [sys.executable, script, "--in", args.in_srt, "--out", args.out_srt]
|
|
subprocess.run(cmd, check=True)
|
|
return
|
|
except Exception:
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
logger.exception("Error al ejecutar la traducción local")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main() or 0)
|
|
|