"""Replicate predictor for kale-tts-1: text -> 24 kHz WAV. Files next to it (make_context.sh): models/, frontend/, kale_tts.py, kale_frontend.js.""" from pathlib import Path from cog import BasePredictor, Input, Path as CogPath HERE = Path(__file__).resolve().parent VOICES = ["kenzie", "simone", "amy", "frankie", "darlene", "owen", "toby", "jack", "earl", "magnus"] class Predictor(BasePredictor): def setup(self): import sys; sys.path.insert(0, str(HERE)) from kale_tts import KaleTTS, QuickJSFrontEnd, to_wav fe = QuickJSFrontEnd(frontend_dir=HERE / "frontend", bundle=HERE / "kale_frontend.js") self.to_wav = to_wav self.tts = {m: KaleTTS(HERE / "models" / m, threads=2, frontend=fe) for m in ("kale-tts-1-nano", "kale-tts-1-tiny")} def predict(self, text: str = Input(description="English text to read aloud"), voice: str = Input(default="kenzie", choices=VOICES, description="amy and jack are British (en-gb front end), the others American"), model: str = Input(default="kale-tts-1-nano", choices=["kale-tts-1-nano", "kale-tts-1-tiny"])) -> CogPath: out = Path("/tmp/kale-tts.wav"); out.write_bytes(self.to_wav(self.tts[model].speak(text, voice=voice))); return CogPath(out)