Why Kokoro TTS?#
ElevenLabs charges $5-99/month for voice synthesis. Their free tier gives you 10,000 characters per month — that’s about 15 minutes of audio. For anything serious, you’re paying.
Kokoro TTS is an open-source text-to-speech engine that runs locally. It generates natural, expressive speech from text. No subscription. No API limits. No data leaving your machine. 10,000 characters per month? Try unlimited.
Kokoro vs Alternatives#
| Tool | Quality | Cost | Local | Voices |
|---|
| Kokoro TTS | Excellent | Free | Yes | Multiple |
| ElevenLabs | Excellent | $5-99/mo | No | Many |
| Piper | Good | Free | Yes | Many |
| Coqui TTS | Good | Free | Yes | Few |
| Google TTS | decent | Free tier | No | Limited |
Kokoro produces speech that rivals ElevenLabs in quality. The voices have natural prosody, emotional range, and clarity that sounds human.
What You Need#
- Python 3.10+
- 4GB RAM minimum (8GB recommended)
- GPU optional but much faster (even a 3060 Ti cuts generation time by 5x)
- 2GB disk space for models
Installation#
Linux#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| # Clone Kokoro
git clone https://github.com/remsy/Kokoro-FastAPI
cd Kokoro-FastAPI
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Download model files
python download_models.py
# Launch the API server
python api_server.py
|
The API server runs on http://localhost:8000.
Windows#
1
2
3
4
5
6
7
| git clone https://github.com/remsy/Kokoro-FastAPI
cd Kokoro-FastAPI
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
python download_models.py
python api_server.py
|
Docker (Recommended for Homelab)#
1
2
3
4
5
6
| docker run -d \
--gpus all \
-p 8000:8000 \
-v kokoro-models:/app/models \
--name kokoro-tts \
remsy/kokoro-fastapi:latest
|
Generating Your First Audio#
Via API#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| import requests
response = requests.post(
"http://localhost:8000/api/v1/audio/speech",
json={
"model": "kokoro",
"input": "Welcome to Self-Hosted Tech, where we run real AI on real hardware.",
"voice": "af_heart",
"response_format": "wav"
}
)
with open("output.wav", "wb") as f:
f.write(response.content)
|
Via CLI#
1
| python generate.py --text "Hello world" --voice af_heart --output hello.wav
|
Available Voices#
Kokoro ships with multiple voices, each with distinct characteristics:
| Voice ID | Character | Best For |
|---|
| af_heart | Warm, female | Narration, general purpose |
| af_jessica | Professional, female | Tutorials, presentations |
| af_nicole | Soft, female | Intimate, calm content |
| am_michael | Deep, male | Documentary, authority |
| am_adam | Energetic, male | Excited, fast-paced |
| bf_emma | British female | European content |
Post-Processing with FFmpeg#
Raw TTS output is good, but a little post-processing makes it studio quality:
Pitch Shifting#
1
2
| # Raise pitch by ~0.32 semitones
ffmpeg -i input.wav -af "asetrate=24000*1.0185,aresample=24000" output.wav
|
Speed Adjustment#
1
2
3
4
5
| # Slow down to 88% speed (more relaxed narration)
ffmpeg -i input.wav -af "atempo=0.88" output.wav
# Combined: slow + pitch shift
ffmpeg -i input.wav -af "atempo=0.88,asetrate=24000*1.0185,aresample=24000" output.wav
|
Normalize Volume#
1
| ffmpeg -i input.wav -af "loudnorm=I=-16:LRA=11:TP=-1.5" output.wav
|
Convert to MP3#
1
| ffmpeg -i input.wav -codec:a libmp3lame -b:a 128k output.mp3
|
Automating TTS in n8n#
Here’s how we use Kokoro in our automation pipeline:
- n8n workflow triggers on new article publish
- Ollama summarizes the article into a script
- Kokoro TTS generates the narration audio
- FFmpeg post-processes (pitch, speed, normalize)
- ComfyUI generates thumbnail images
- FFmpeg combines audio + images into a video
- YouTube API uploads the finished video
All local. All free. All automated. This is the pipeline behind our YouTube channel — and it costs $0 per video.
n8n HTTP Request Node#
1
2
3
4
5
6
7
8
9
10
| {
"method": "POST",
"url": "http://localhost:8000/api/v1/audio/speech",
"body": {
"model": "kokoro",
"input": "={{ $json.script }}",
"voice": "af_heart",
"response_format": "wav"
}
}
|
| Hardware | Generation Speed | 1 Minute Audio |
|---|
| RTX 3090 | ~50x realtime | ~1.2s |
| RTX 3060 Ti | ~20x realtime | ~3s |
| CPU (Ryzen 5950X) | ~5x realtime | ~12s |
| CPU (i5-12600H) | ~3x realtime | ~20s |
Even on CPU, Kokoro is fast enough for batch processing. A 10-minute narration takes 2-3 minutes on CPU.
Troubleshooting#
“CUDA out of memory”#
- Close other GPU applications
- Use CPU fallback:
CUDA_VISIBLE_DEVICES="" python api_server.py
Audio sounds robotic#
- Try a different voice model
- Check input text for unusual characters
- Add SSML tags for better prosody control
Model download fails#
- Download manually from HuggingFace
- Place files in
models/ directory
Next Steps#
Kokoro TTS is open source. Support the project on GitHub.