#!/usr/bin/env python3 """Standalone NeuTTS synthesis helper. Called by tts_tool.py via subprocess to keep the TTS model (~500MB) in a separate process that exits after synthesis — no lingering memory. Usage: python -m tools.neutts_synth --text "Hello" --out output.wav \ --ref-audio samples/jo.wav --ref-text samples/jo.txt Requires: python -m pip install -U neutts[all] System: apt install espeak-ng (or brew install espeak-ng) """ 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) samples = samples.flatten() # Clamp and convert to int16 samples = np.clip(samples, -1.0, 1.0) pcm = (samples * 32767).astype(np.int16) num_channels = 1 bits_per_sample = 16 byte_rate = sample_rate * num_channels * (bits_per_sample // 8) block_align = num_channels * (bits_per_sample // 8) data_size = len(pcm) * (bits_per_sample // 8) with open(path, "wb") as f: f.write(b"RIFF") f.write(struct.pack("