An 8M-parameter English text-to-speech model distilled from Kokoro-82M. 9 MB, runs 18x real time on one CPU thread.
Voice selection for Paradee 1.2 (four voices); 1.1 and 1.0 stay available
Claude0fb12c8796c4
diff --git a/paradee/__init__.py b/paradee/__init__.pyindex 676ccd7..4b1da53 100644--- a/paradee/__init__.py+++ b/paradee/__init__.py@@ -1,5 +1,5 @@-"""Paradee: an 8M-parameter English text-to-speech model distilled from Kokoro-82M (voice af_heart)."""-from .tts import Paradee, SAMPLE_RATE+"""Paradee: an 8M-parameter English text-to-speech model distilled from Kokoro-82M, with four of its voices."""+from .tts import Paradee, SAMPLE_RATE, VOICES-__all__ = ["Paradee", "SAMPLE_RATE"]-__version__ = "1.1.0"+__all__ = ["Paradee", "SAMPLE_RATE", "VOICES"]+__version__ = "1.2.0"diff --git a/paradee/__main__.py b/paradee/__main__.pyindex fa0bb6c..f17d969 100644--- a/paradee/__main__.py+++ b/paradee/__main__.py@@ -9,11 +9,12 @@ def main():ap.add_argument("text", nargs="?", help="text to speak (read from stdin when omitted)")ap.add_argument("-o", "--out", default="paradee.wav")ap.add_argument("--speed", type=float, default=1.0)+ ap.add_argument("--voice", default="af_heart", help="af_heart, bf_isabella, am_puck or bm_fable (1.0 and 1.1: af_heart only)")ap.add_argument("--fp32", action="store_true", help="use the fp32 model instead of int8")- ap.add_argument("--model-version", default="1.1", choices=["1.1", "1.0"])+ ap.add_argument("--model-version", default="1.2", choices=["1.2", "1.1", "1.0"])a = ap.parse_args()text = a.text if a.text is not None else sys.stdin.read()- audio = Paradee(version=a.model_version, quantized=not a.fp32)(text, speed=a.speed)+ audio = Paradee(version=a.model_version, quantized=not a.fp32)(text, speed=a.speed, voice=a.voice)pcm = (np.clip(audio, -1, 1) * 32767).astype("<i2")with wave.open(a.out, "wb") as w:w.setnchannels(1); w.setsampwidth(2); w.setframerate(SAMPLE_RATE); w.writeframes(pcm.tobytes())diff --git a/paradee/tts.py b/paradee/tts.pyindex 0ec0247..e596a11 100644--- a/paradee/tts.py+++ b/paradee/tts.py@@ -4,7 +4,9 @@ import numpy as npimport onnxruntime as ortfrom huggingface_hub import hf_hub_download-REPOS = {"1.1": "sahilmahendrakar/Paradee-8M-v1.1", "1.0": "sahilmahendrakar/Paradee-8M-v1.0"}+REPOS = {"1.2": "sahilmahendrakar/Paradee-8M-v1.2", "1.1": "sahilmahendrakar/Paradee-8M-v1.1", "1.0": "sahilmahendrakar/Paradee-8M-v1.0"}+# the voices of each version, in the order the 1.2 model numbers them. 1.0 and 1.1 have af_heart only.+VOICES = {"1.2": ["af_heart", "bf_isabella", "am_puck", "bm_fable"], "1.1": ["af_heart"], "1.0": ["af_heart"]}SAMPLE_RATE = 24000MAX_PHONEMES = 510 # the text side has 512 positions, two of which are the pad tokens at each end@@ -12,14 +14,17 @@ MAX_PHONEMES = 510 # the text side has 512 positions, two of which are the padclass Paradee:"""Load once, then call with text to get a float32 waveform at 24 kHz.- version: "1.1" (default) or "1.0", the earlier release with the slower decoder.+ version: "1.2" (default, four voices), "1.1" or "1.0" (af_heart only; 1.0 has the slower decoder).quantized: use the 8.5 MB int8 file (default) instead of the 35 MB fp32 one. They sound the same.model_path / config_path: local files instead of downloading from the Hugging Face Hub.threads: CPU threads for onnxruntime. One thread already runs about 60x faster than real time."""- def __init__(self, version="1.1", quantized=True, model_path=None, config_path=None, threads=1):+ def __init__(self, version="1.2", quantized=True, model_path=None, config_path=None, threads=1):+ if version not in REPOS:+ raise ValueError(f"unknown version {version!r}; choose one of {', '.join(REPOS)}")repo, revision = REPOS[version], f"v{version}"+ self.version, self.voices = version, VOICES[version]name = "onnx/paradee_int8.onnx" if quantized else "onnx/paradee.onnx"model_path = model_path or hf_hub_download(repo, name, revision=revision)config_path = config_path or hf_hub_download(repo, "config.json", revision=revision)@@ -43,14 +48,22 @@ class Paradee:phonemes, _ = self.g2p(british=voice.startswith("b"))(text)return phonemes- def generate_from_phonemes(self, phonemes, speed=1.0):+ def check_voice(self, voice):+ if voice not in self.voices:+ raise ValueError(f"Paradee {self.version} has no voice {voice!r}; its voices are {', '.join(self.voices)}")++ def generate_from_phonemes(self, phonemes, speed=1.0, voice="af_heart"):+ self.check_voice(voice)ids = [0] + [self.vocab[c] for c in phonemes if c in self.vocab][:MAX_PHONEMES] + [0]feed = {"input_ids": np.array([ids], dtype=np.int64), "speed": np.array([speed], dtype=np.float32)}+ if len(self.voices) > 1:+ feed["voice"] = np.array([self.voices.index(voice)], dtype=np.int64)return self.session.run(None, feed)[0][0]def __call__(self, text, speed=1.0, voice="af_heart"):- """speed > 1 speaks faster. Long text is read one sentence at a time."""- parts = [self.generate_from_phonemes(ps, speed) for ps in self._chunks(text, voice)]+ """speed > 1 speaks faster. voice is one of self.voices. Long text is read one sentence at a time."""+ self.check_voice(voice)+ parts = [self.generate_from_phonemes(ps, speed, voice) for ps in self._chunks(text, voice)]return np.concatenate(parts) if parts else np.zeros(0, dtype=np.float32)def _chunks(self, text, voice="af_heart"):diff --git a/pyproject.toml b/pyproject.tomlindex ebf8a92..0855ea8 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[project]name = "paradee"-version = "1.1.0"+version = "1.2.0"description = "An 8M-parameter English text-to-speech model distilled from Kokoro-82M"readme = "README.md"license = "Apache-2.0"@@ -22,7 +22,7 @@ dependencies = [paradee = "paradee.__main__:main"[project.urls]-"Model" = "https://huggingface.co/sahilmahendrakar/Paradee-8M-v1.1"+"Model" = "https://huggingface.co/sahilmahendrakar/Paradee-8M-v1.2"[build-system]requires = ["hatchling"]