Most TTS solutions require API calls (ElevenLabs, OpenAI) or sound robotic (espeak, basic pyttsx3). Kokoro-82M hits a sweet spot — it runs locally, sounds natural, and fits on modest hardware.
Why Kokoro?
82M parameters means it runs on CPU just fine, but really shines on GPU. It's a neural TTS model trained on high-quality voice data that produces natural prosody — proper emphasis, pitch variation, and pacing. No robotic monotone.
Installation
git clone https://github.com/hexgrad/Kokoro-82M
cd Kokoro-82M
pip install -r requirements.txt
The model downloads automatically on first run. It's about 300MB — small enough to not worry about storage.
Basic Usage
The simplest way to generate speech:
from kokoro import KPipeline
import soundfile as sf
pipeline = KPipeline(lang_code='a') # 'a' for American English
audio = pipeline(
"This is a test of Kokoro text-to-speech. It sounds natural and runs locally.",
voice='af_bella', # Voice preset
speed=1.0,
split_pattern=r'\n+' # Split on newlines for long text
)
sf.write('output.wav', audio, 24000)
Available Voices
Kokoro comes with several built-in voice presets:
af_bella— Female, warm and clearam_adam— Male, neutralaf_nicole— Female, slightly deeperam_michael— Male, authoritativeaf_sky— Female, soft
Each voice handles different text styles differently. af_bella is the best all-rounder for tutorials and narration. am_michael works well for technical content.
Using It From the CLI
For quick testing, wrap it in a shell script:
#!/bin/bash
echo "$1" | python3 -c "
import sys
from kokoro import KPipeline
import soundfile as sf
p = KPipeline(lang_code='a')
audio = p(sys.stdin.read(), voice='af_bella', speed=1.0)
sf.write('output.wav', audio, 24000)
"
Then: ./tts.sh "Your text here"
Serving It As an API
For web integration, Kokoro can run as a simple Flask endpoint:
from flask import Flask, request, send_file
from kokoro import KPipeline
import soundfile as sf
import io
app = Flask(__name__)
pipeline = KPipeline(lang_code='a')
@app.route('/tts', methods=['POST'])
def tts():
text = request.json['text']
voice = request.json.get('voice', 'af_bella')
audio = pipeline(text, voice=voice, speed=1.0)
buf = io.BytesIO()
sf.write(buf, audio, 24000, format='wav')
buf.seek(0)
return send_file(buf, mimetype='audio/wav')
app.run(host='0.0.0.0', port=5000)
Performance
On a GPU: renders faster than real-time. A 30-second audio clip generates in about 2-3 seconds. On CPU only: real-time or slightly slower. A 30-second clip takes 20-30 seconds.
Practical Tips
Punctuation matters. Periods and commas affect pacing. Add line breaks for longer pauses. Kokoro respects punctuation more than most TTS engines.
Speed adjustment. 0.9-1.0 for tutorials. 1.1-1.2 for casual content. Past 1.3 starts to sound rushed.
Long form. For articles longer than a few paragraphs, split the text at sentence boundaries and feed each chunk separately. Concatenate the audio files afterward.
Kokoro is one of those rare tools that just works. Set it up once and you have unlimited, natural TTS with zero API costs.