How to Run Kokoro TTS Locally: Free Offline AI Voice
Source: Age of LLMs — Kokoro TTS illustration.
Why run text-to-speech locally?
Cloud text-to-speech is convenient until the bill arrives. Every narrated article, voice prompt, and accessibility feature is metered by the character, which is a poor fit for personal projects, homelabs, and privacy-sensitive apps.
Kokoro-82M changes the equation. It is an open-weight model with just 82 million parameters, released under the Apache 2.0 license, that produces remarkably natural speech on an ordinary CPU. There is no GPU requirement, no account, and no API key. The easiest way to run it is Kokoro-FastAPI, a community server that wraps the model in an OpenAI-compatible API, so tools built for cloud speech endpoints can talk to your local server unchanged.
How Kokoro works
Text goes in, the model converts it to speech, and an audio file comes out. Version 1.0 ships with 54 voices across 8 languages. Voice names follow a simple pattern: the first letter is the language family, the second is the gender, and the rest is the name. So af_heart is an American female voice, am_adam is an American male voice, and bf_emma is a British female voice.
Source: NewsCarpenter diagram — Text in, Kokoro-82M, audio out.
Prerequisites
- A computer running Linux, macOS, or Windows with Docker installed
- About 2 GB of free RAM and 1 GB of free disk space
- No GPU, no cloud account, and no API key
If you do not have Docker yet, install Docker Desktop first and confirm it runs with docker ps.
Step 1: Start the Kokoro server
Run the CPU image in detached mode, mapping port 8880 on your machine to port 8880 in the container:
docker run -d \
--name kokoro \
--restart unless-stopped \
-p 8880:8880 \
ghcr.io/remsky/kokoro-fastapi-cpu:latest
The restart flag brings the server back after a reboot, which is what you want for a homelab service. With an NVIDIA GPU, use the GPU image with --gpus all and ghcr.io/remsky/kokoro-fastapi-gpu:latest instead. Then check the container is up:
docker ps --filter name=kokoro
If it is not listed, run docker logs kokoro to see what went wrong before moving on.
Step 2: Generate your first audio file
Send a request to the OpenAI-compatible endpoint. This example uses the af_sarah voice and saves the result as an MP3:
curl -X POST http://localhost:8880/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"model": "kokoro",
"input": "Hello from your homelab. This is Kokoro speaking, entirely offline.",
"voice": "af_sarah",
"response_format": "mp3"
}' \
--output test.mp3
Play test.mp3. The first request is slower than later ones because the model is still loading into memory. A connection refused error usually means the container is still starting, or port 8880 is already in use. You can also try the built-in web interface at http://localhost:8880/web: type text, pick a voice, and click generate. It is the fastest way to audition voices.
Step 3: Pick voices and formats
Good English voices to try first are af_heart, af_bella, af_sarah, am_adam, and am_michael for American English, and bf_emma, bf_isabella, bm_george, and bm_lewis for British English.
The API supports MP3, WAV, Opus, FLAC, AAC, and PCM. Use MP3 for small files you plan to share, and WAV for uncompressed audio you plan to edit.
Step 4: Add a voice to Open WebUI
If you already run Open WebUI for local chat, Kokoro gives it a voice with almost no extra work. Go to Settings, then Admin, then Audio, and set the engine to OpenAI, the API base URL to http://localhost:8880/v1, the API key to not-needed, the voice to a Kokoro voice such as af_bella, and the model to kokoro. If Open WebUI runs in its own container, use host.docker.internal instead of localhost.
Our earlier Open WebUI tutorial shows how to set up a ChatGPT-like interface for local models, and this step turns that interface into a talking one. Pair it with the listening half, covered in our guide to running Whisper locally for free offline transcription, and you have a fully local voice loop.
Step 5 (optional): Use the Python library instead
If you prefer a library over a server, install the official inference package. On Linux you also need espeak-ng, which handles out-of-dictionary words:
pip install kokoro>=0.9.4 soundfile
sudo apt-get install -y espeak-ng
Then generate audio in a few lines. The pipeline writes 24,000 Hz WAV files, the model's native sample rate:
from kokoro import KPipeline
import soundfile as sf
pipeline = KPipeline(lang_code='a')
generator = pipeline("Hello world, spoken entirely on this machine.", voice='af_heart')
for i, (graphemes, phonemes, audio) in enumerate(generator):
sf.write(f'{i}.wav', audio, 24000)
Use lang_code='a' for American English and 'b' for British English, matching the voice you pick. The Docker route is still the better default, because it avoids Python dependency issues and gives every tool the same API.
Troubleshooting
- Connection refused: the container is still starting, or another service owns port 8880. Check
docker psanddocker logs kokoro, or remap with-p 8881:8880and use port 8881. - First request is slow: expected while the model loads. Later requests are much faster.
- Single words sound odd: users report isolated words and homographs sometimes get strange stress. Embed the word in a full sentence, generate the audio, and trim the clip.
- Open WebUI cannot reach Kokoro: if both run in Docker,
localhostinside one container is not your host. Usehost.docker.internal. - Flat delivery: try another voice first. Voice choice matters more than any parameter, and some voices suit narration while others suit conversation.
What Kokoro is not
Kokoro is not a voice-cloning tool. It ships with fixed preset voices and cannot imitate a specific person without additional fine-tuning, and it will not match a top-tier cloud voice on every edge case of prosody. What it offers is a strong, free, private default for narration, accessibility readers, home assistants, and app voice prompts.
Closing
You now have a private text-to-speech server on your own machine: a Docker container, an OpenAI-compatible endpoint, and voices you can use as often as you like. Try narrating one article with it this week and compare it with the cloud service you used before. To add a brain to go with this voice, see our guide to running an open model locally with Ollama.


Comments
Post a Comment