#!/usr/bin/env python3 """Standalone NeuTTS synthesis helper. Called by tts_tool via subprocess so the ~500MB TTS model lives in a process that exits after synthesis. Usage: python -m tools.neutts_synth --text "Hello" --out out.wav --ref-audio jo.wav --ref-text jo.txt Requires ``pip install -U neutts[all]`` and espeak-ng (apt/brew). """ import argparse import struct import sys from pathlib import Path def _write_wav(path: str, samples, sample_rate: int = 24000) -> None: """Write a WAV file from float32 samples (no soundfile dependency).""" import numpy as np if not isinstance(samples, np.ndarray): samples = np.array(samples, dtype=np.float32) pcm = (np.clip(samples.flatten(), -1.0, 1.0) * 32767).astype(np.int16) data_size = len(pcm) * 2 # 16-bit mono with open(path, "wb") as f: f.write(b"RIFF" + struct.pack("