Here is a complete Python example showing how to generate and save a voice file with KittenTTS:
from kittentts import KittenTTS
import soundfile as sf
# 初始化模型(可选voice参数选择语音)
tts = KittenTTS(voice='female_soft')
# 输入待转换文本
text = "这是一个演示示例,展示KittenTTS的轻量级语音合成能力。"
# 生成语音数据
audio, sample_rate = tts.generate(text)
# 保存为WAV文件
sf.write("demo_output.wav", audio, sample_rate)
print("语音文件已生成")
Key point note: Pre-installation required soundfile
The library processes audio files; the first run downloads about 25MB of model weights; generation time is dependent on text length and device performance.
This answer comes from the articleKittenTTS: Lightweight Text-to-Speech ModelingThe