import argparse import json import subprocess import sys import time from pathlib import Path ap = argparse.ArgumentParser() ap.add_argument("--input", action="append", default=[]) ap.add_argument("--outdir", required=True) ap.add_argument("--params", default="{}") a = ap.parse_args() p = json.loads(a.params) text = (p.get("text") or "").strip() if not text: print("ERROR: text is required") sys.exit(1) voice = p.get("voice", "af_heart") speed = float(p.get("speed", 1.0)) outdir = Path(a.outdir) cmd = [ sys.executable, "-m", "mlx_audio.tts.generate", "--model", "prince-canuma/Kokoro-82M", "--text", text, "--voice", voice, "--speed", str(speed), "--file_prefix", str(outdir / f"tts_{voice}"), ] t0 = time.time() r = subprocess.run(cmd, capture_output=True, text=True) if r.stdout: print(r.stdout[-2000:]) if r.stderr: print(r.stderr[-2000:], file=sys.stderr) wavs = sorted(outdir.glob("*.wav")) if r.returncode != 0 or not wavs: print("ERROR: kokoro generation failed") sys.exit(1) print(f"done in {time.time() - t0:.1f}s: {', '.join(w.name for w in wavs)}")