remsky/Kokoro-FastAPI
Self-hosted Kokoro-82M speech inference over OpenAI-compatible HTTP and voice WebSockets
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
Kokoro-FastAPI serves Kokoro-82M as a self-hosted text-to-speech inference service. The Python API under api/ uses FastAPI, Uvicorn, and Pydantic around a PyTorch synthesis runtime. Dependencies include kokoro==0.9.4, inno-kokoro==0.3.0, espeakng-loader==0.2.4, and soundfile==0.13.0. Requests provide text, a voice or weighted voice mix, and output options; normalization and chunking prepare the text for synthesis, and the service can stream back encoded audio without waiting for the full passage.
The same synthesis service exposes different client contracts: /v1/audio/speech for OpenAI-style HTTP clients, /v1/realtime for OpenAI-style Realtime clients, and ElevenLabs- and Cartesia-compatible WebSockets for voice agents. OpenAI voice mappings can be customized in api/src/core/openai_mappings.json; request-scoped voice_aliases help manage longer mix names. The optional web interface at /w provides a read-along path without requiring a custom API client.
Key Capabilities & Differentiators
The service supports multilingual synthesis, voice discovery, weighted voice-pack mixing, and export of combined voice packs. The Speech API supports MP3, WAV, Opus, FLAC, AAC, and PCM. /v1/realtime emits 24 kHz PCM and accepts response.cancel; it reads supplied text as written, ignores instructions, and returns errors for audio input and conversation events. The ElevenLabs and Cartesia WebSockets support 8–48 kHz PCM, with MP3 also on the ElevenLabs route, and word timestamps where available from Kokoro, including English and eSpeak languages. Cartesia cancel stops its context; ElevenLabs close_context finishes text already submitted.
Chunk sizing directly affects both playback responsiveness and prosody. Reported first-output latency is roughly 300 ms on GPU at chunk size 400, 3.5 seconds on an older Core i7 at 200, and under a second on an M3 Pro at 200. Those are different hardware and chunk settings, not a controlled CPU–GPU comparison or a production latency guarantee. Smaller chunks can introduce intonation artifacts, so measure both time to first audio and continuity on representative scripts.
Trade-offs & Limitations
Compared with managed ElevenLabs, this service is a fit when the priority is keeping synthesis on infrastructure you control while reusing an existing TTS client. Compatibility is at the speech protocol level, not at the level of voice catalogs, output quality, or broader provider features. Compared with embedding Kokoro directly in a Python application, the service gives multiple clients a shared HTTP and WebSocket interface, at the cost of another process to operate. Its local examples use placeholder API keys; treat those as SDK configuration, not evidence of production authentication. Restrict network exposure and add access controls appropriate to the deployment.
Model eviction trades VRAM for cold-start latency. POST /dev/unload and optional idle eviction free model allocations, but the reported CUDA setup retained a 2.37 GB floor. The short and long workloads reclaimed 758 MiB and 1,656 MiB respectively, and the next request paid about 4.9–5.1 seconds to reload. The idle timer is off by default. Size capacity with concurrent streams and representative text, and keep the model resident if first-audio latency is a hard requirement unless measurements show eviction fits the budget.
Hardware & Deployment Guide
For a first deployment, run the CPU image or select the NVIDIA image that matches the host: the documented x86 defaults use CUDA 12.6, Blackwell has a -cu128 variant, and NVIDIA arm64 uses CUDA 12.9 under the regular GPU tag. AMD ROCm is experimental and x86_64-only; its container takes /dev/kfd and /dev/dri. Apple Silicon can use native MPS via ./start-gpu_mac.sh. The default service port is 8880; Docker Compose configurations include docker/gpu and docker/rocm. Direct runs use uv with Python 3.10+ and can use system eSpeak NG as a fallback.
Published images include weights and are best pinned to a release tag. The download path pins the upstream revision, verifies weights against a hardcoded SHA-256, and tries a release mirror on verification failure; if the mirror also fails validation, the server does not start. Use the bundled weights when staging deployments without network access. The v0.10.0 release added the provider-compatible WebSockets and Realtime TTS; v0.9.2 addressed normalization edge cases around decimal separators and ellipses. Set ENABLE_WEBSOCKET_TTS=false when only HTTP synthesis is needed.
/v1/audio/speech supports OpenAI SDK streaming with MP3, WAV, Opus, FLAC, AAC, and PCM output./v1/realtime and ElevenLabs- and Cartesia-compatible WebSockets for voice agents.af_bella(2)+af_heart(1), shorten names with request-scoped aliases, or export a mix as a .pt file.POST /dev/unload releases model VRAM; MODEL_AUTO_UNLOAD_TIMEOUT_SECONDS enables idle eviction and leaves reload to the next request.Teams adding local streaming TTS to voice agents, smart-home assistants, readers, or audiobook pipelines that can use Kokoro voices and have time to test target hardware.
You need a full duplex speech-to-speech API, exact parity with a managed provider’s voices and events, or a hosted service that takes infrastructure and capacity management off your plate.
Quick Start & Installation
docker run -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-cpu:latest
Comparison vs. Top Voice, Vision & Video Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| Kokoro-FastAPI ★ | 5.8k | +14 | Python | Apache-2.0 | Self-hosted Kokoro-82M speech inference over OpenAI-compatible HTTP and voice We |
| fish-speech | 34k | +84 | Python | — | Self-hosted PyTorch speech inference for directed, multi-speaker audio |
| EmotiVoice | 8.5k | — | Python | Apache-2.0 | Self-hosted PyTorch TTS for prompt-controlled Chinese and English speech |
| voicebox | 61.8k | +437 | Python | MIT | Local-first voice studio with multi-engine speech synthesis, dictation and MCP. |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/remsky/Kokoro-FastAPI.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about Kokoro-FastAPI
How do I switch an existing OpenAI TTS client to Kokoro-FastAPI?
http://localhost:8880/v1, call audio.speech with model="kokoro", and select a Kokoro voice such as af_bella. The HTTP endpoint streams audio bytes; /v1/realtime instead returns audio delta events and does not accept audio input. OpenAI SDK 2.x needs an explicit websocket_base_url="ws://localhost:8880/v1" for the local, non-TLS Realtime connection.Do I need a GPU, and how much VRAM should I budget?
Can I deploy this commercially or handle sensitive text with it?
Can I replace ElevenLabs without rewriting my voice agent?
close_context finishes text already submitted rather than stopping generation immediately. Do not assume voice parity or coverage of other provider APIs.Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy