Open-source State-of-the-art TTS model which runs on a CPU 😻
Python
fixed example.py and the default preprocessing step;
Rohan Joshie84f35fa979c
diff --git a/example.py b/example.pyindex 0b2db06..064fc46 100644--- a/example.py+++ b/example.py@@ -1,10 +1,29 @@from kittentts import KittenTTS-m = KittenTTS("KittenML/kitten-tts-nano-0.2")-audio = m.generate("This high quality TTS model works without a GPU it's 2026", voice='expr-voice-2-f' )+# it will run blazing fast on any GPU. But this example will run on CPU.-# available_voices : [ 'expr-voice-2-m', 'expr-voice-2-f', 'expr-voice-3-m', 'expr-voice-3-f', 'expr-voice-4-m', 'expr-voice-4-f', 'expr-voice-5-m', 'expr-voice-5-f' ]+# Step 1: Load the model+# m = KittenTTS("KittenML/kitten-tts-mini-0.8") # 80M version (highest quality)+m = KittenTTS("KittenML/kitten-tts-micro-0.8") # 40M version (balances speed and quality )+# m = KittenTTS("KittenML/kitten-tts-nano-0.8") # 15M version (tiny and faster )+++# Step 2: Generate the audio++# this is a sample from the TinyStories dataset.+text ="""One day, a little girl named Lily found a needle in her room. She knew it was difficult to play with it because it was sharp. Lily wanted to share the needle with her mom, so she could sew a button on her shirt.+Lily went to her mom and said, "Mom, I found this needle. Can you share it with me and sew my shirt?" Her mom smiled and said, "Yes, Lily, we can share the needle and fix your shirt."+Together, they shared the needle and sewed the button on Lily's shirt. It was not difficult for them because they were sharing and helping each other. After they finished, Lily thanked her mom for sharing the needle and fixing her shirt. They both felt happy because they had shared and worked together."""+++# available_voices : ['Bella', 'Jasper', 'Luna', 'Bruno', 'Rosie', 'Hugo', 'Kiki', 'Leo']+voice = 'Luna'++++audio = m.generate(text=text, voice=voice )# Save the audioimport soundfile as sfsf.write('output.wav', audio, 24000)+print(f"Audio saved to output.wav")\ No newline at end of filediff --git a/kittentts/get_model.py b/kittentts/get_model.pyindex b0d47b2..e9b346d 100644--- a/kittentts/get_model.py+++ b/kittentts/get_model.py@@ -7,7 +7,7 @@ from .onnx_model import KittenTTS_1_Onnxclass KittenTTS:"""Main KittenTTS class for text-to-speech synthesis."""- def __init__(self, model_name="KittenML/kitten-tts-nano-0.1", cache_dir=None):+ def __init__(self, model_name="KittenML/kitten-tts-nano-0.8", cache_dir=None):"""Initialize KittenTTS with a model from Hugging Face.Args:@@ -23,7 +23,7 @@ class KittenTTS:self.model = download_from_huggingface(repo_id=repo_id, cache_dir=cache_dir)- def generate(self, text, voice="expr-voice-5-m", speed=1.0):+ def generate(self, text, voice="expr-voice-5-m", speed=1.0, clean_text=False):"""Generate audio from text.Args:@@ -34,7 +34,8 @@ class KittenTTS:Returns:Audio data as numpy array"""- return self.model.generate(text, voice=voice, speed=speed)+ print(f"Generating audio for text: {text}")+ return self.model.generate(text, voice=voice, speed=speed, clean_text=clean_text)def generate_to_file(self, text, output_path, voice="expr-voice-5-m", speed=1.0, sample_rate=24000):"""Generate audio from text and save to file.@@ -51,7 +52,7 @@ class KittenTTS:@propertydef available_voices(self):"""Get list of available voices."""- return self.model.available_voices+ return self.model.all_voice_namesdef download_from_huggingface(repo_id="KittenML/kitten-tts-nano-0.1", cache_dir=None):diff --git a/kittentts/onnx_model.py b/kittentts/onnx_model.pyindex 7ea20b3..88009fc 100644--- a/kittentts/onnx_model.py+++ b/kittentts/onnx_model.py@@ -100,9 +100,10 @@ class KittenTTS_1_Onnx:'expr-voice-2-m', 'expr-voice-2-f', 'expr-voice-3-m', 'expr-voice-3-f','expr-voice-4-m', 'expr-voice-4-f', 'expr-voice-5-m', 'expr-voice-5-f']+ self.all_voice_names = ['Bella', 'Jasper', 'Luna', 'Bruno', 'Rosie', 'Hugo', 'Kiki', 'Leo']self.voice_aliases = voice_aliases- self.preprocessor = TextPreprocessor()+ self.preprocessor = TextPreprocessor(remove_punctuation=False)def _prepare_inputs(self, text: str, voice: str, speed: float = 1.0) -> dict:"""Prepare ONNX model inputs from text and voice parameters."""@@ -125,6 +126,7 @@ class KittenTTS_1_Onnx:# Add start and end tokenstokens.insert(0, 0)+ tokens.append(10)tokens.append(0)input_ids = np.array([tokens], dtype=np.int64)diff --git a/kittentts/preprocess.py b/kittentts/preprocess.pyindex ecbe0db..8f2c780 100644--- a/kittentts/preprocess.py+++ b/kittentts/preprocess.py@@ -149,7 +149,7 @@ _RE_EMAIL = re.compile(r"\b[\w.+-]+@[\w-]+\.[a-z]{2,}\b", re.IGNORECASE)_RE_HASHTAG = re.compile(r"#\w+")_RE_MENTION = re.compile(r"@\w+")_RE_HTML = re.compile(r"<[^>]+>")-_RE_PUNCT = re.compile(r"[^\w\s]")+_RE_PUNCT = re.compile(r"[^\w\s.,?!;:\-\u2014\u2013\u2026]")_RE_SPACES = re.compile(r"\s+")# Number: do NOT match a leading minus if it is immediately preceded by a letter@@ -646,7 +646,7 @@ def remove_mentions(text: str, replacement: str = "") -> str:def remove_punctuation(text: str) -> str:- """Remove all punctuation characters."""+ """Remove non-prosodic punctuation, keeping marks that affect speech rhythm and intonation."""return _RE_PUNCT.sub(" ", text)