Rust port of kokoro-tts — a fast wrapper around the Kokoro-82M ONNX text-to-speech model.
~1.7s to generate ~9.0s of audio (ONNX Runtime on M1 Mac)
cargo(Rust toolchain)espeak-ng(phonemization via FFI)uv(voice pack conversion script)curl(model/voice download)
git clone https://github.com/RohanAwhad/kokoro-rust.git
cd kokoro-rustDownload the ONNX model:
curl -L -o ~/Library/Caches/kokoro-tts/kokoro-v0_19.onnx \
"https://huggingface.co/hexgrad/Kokoro-82M/resolve/main/kokoro-v0_19.onnx"Linux: cache dir is
~/.cache/kokoro-tts/instead of~/Library/Caches/kokoro-tts/.
Download and convert a voice pack:
curl -L -o /tmp/af_sky.pt \
"https://huggingface.co/hexgrad/Kokoro-82M/resolve/main/voices/af_sky.pt"
mkdir -p ~/Library/Caches/kokoro-tts/voices/
./scripts/convert_voices.py /tmp/af_sky.pt \
~/Library/Caches/kokoro-tts/voices/af_sky.kokoroCLI (streams audio in real-time):
cargo run --bin kokoro-tts -- "Hello world!"Write to WAV:
cargo run --bin kokoro-tts -- -o output.wav "Hello world!"Python API:
from kokoro import Kokoro # Rust via PyO3 (future)Rust API:
use kokoro::{Kokoro, Voice};
let kk = Kokoro::new();
let audio = kk.generate("Hello world!", Voice::AfSky)?;
// audio.sample_rate == 24000
// audio.data: Vec<f32>| Voice | Language |
|---|---|
af |
American female |
af_bella |
American female |
af_sarah |
American female |
am_adam |
American male |
am_michael |
American male |
bf_emma |
British female |
bf_isabella |
British female |
bm_george |
British male |
bm_lewis |
British male |
af_nicole |
American female |
af_sky |
American female (CLI default) |
cargo build --release
# Binary: target/release/kokoro-tts