Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

Kokoro-FastAPI

> 后端框架
Open source

Dockerized FastAPI wrapper for Kokoro-82M text-to-speech model w/multiplatform CPU, AMD, NVIDIA GPU PyTorch support, handling, and auto-stitching

5.3K stars0 likes0 views
WebsiteGitHub

About

Dockerized FastAPI wrapper for Kokoro-82M text-to-speech model w/multiplatform CPU, AMD, NVIDIA GPU PyTorch support, handling, and auto-stitching


Dockerized FastAPI wrapper for Kokoro-82M text-to-speech model. Generate hours of high quality speech in minutes.

  • OpenAI-compatible Speech endpoint, multi-language support
    • English (US/GB), Spanish, French, Hindi, Italian, Japanese, Brazilian Portuguese, Mandarin Chinese
  • Custom voicepack generation via Inno Clone-Tuner
  • Optional integrated WebUI; read-along long-generation
  • Inline multi-speaker generation & voice mixing + aliasing weighted combinations, SSML support
  • Per-word, or per-chunk timestamped caption generation
  • Phoneme endpoints: generate phonemes from text, or generate audio from phonemes
  • Prebuilt multiplatform images
    • CPU and NVIDIA GPU (CUDA): linux/amd64 + linux/arm64
    • AMD GPU (ROCm, experimental): linux/amd64 only
  • Apple Silicon (MPS) supported when running directly via UV (no image)

Integration & Guides

Community projects that use, recommend, or enable Kokoro-FastAPI as a backend:

  • Home Assistant: wyoming_openai, openai_tts, Kokoro-TTS
  • App stores and templates: Umbrel, Unraid Apps, GPUStack, jetson-containers
  • Readers and audiobooks: openreader, epub_to_audiobook, audiobook-creator, Zotero-TTS
  • Assistants and agents: xiaozhi-esp32-server, call-me, agent-cli, voice-chat-ai
  • Browser: kokoro-extension, customtts

Get Started

Quickest Start (docker run)

Pre-built multi-arch images with models baked in.

:latest is available, but please pin to a release tag for stable usage.

No GPU (laptop, CPU-only server)

bash
docker run -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-cpu:latest

NVIDIA (GTX 900-series through RTX 40; ships cu126)

bash
docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest

NVIDIA RTX 50-series / Blackwell (ships cu128)

bash
docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest-cu128

NVIDIA arm64 (Jetson, GH200; same tag, ships cu129)

bash
docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest

AMD GPU (ROCm, experimental, x86_64 only)

bash
docker run --device=/dev/kfd --device=/dev/dri -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-rocm:latest

Apple Silicon (native MPS clone; the CPU image also works)

bash
./start-gpu_mac.sh

gpu:latest is the same image as gpu:latest-cu126. Configuration via environment variables, see the configuration guide.

Quick Start (docker compose)
  1. Install prerequisites, and start the service using Docker Compose (Full setup including UI):
    • Install Docker
    • Clone the repository:
…

Configuration guide covers image vs build, the volume mounts, and env vars.

Direct Run (via uv)
  1. Install prerequisites:
    • Install astral-uv

    • Install espeak-ng in your system if you want it available as a fallback for unknown words/sounds. The upstream libraries may attempt to handle this, but results have varied.

    • Clone the repository:

      bash
      git clone https://github.com/remsky/Kokoro-FastAPI.git
      cd Kokoro-FastAPI

      Run the model download script if you haven't already

      Start directly via UV (with hot-reload)

      Linux and macOS

      bash
      ./start-cpu.sh OR
      ./start-gpu.sh 

      Windows

      powershell
      .\start-cpu.ps1 OR
      .\start-gpu.ps1 
Up and Running?

Run locally as an OpenAI-Compatible Speech Endpoint

python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8880/v1", api_key="not-needed"
)

with client.audio.speech.with_streaming_response.create(
    model="kokoro",
    voice="af_sky+af_bella", #single or multiple voicepack combo
    input="Hello world!"
  ) as response:
      response.stream_to_file("output.mp3")
  • The API will be available at http://localhost:8880

  • API Documentation: http://localhost:8880/docs

  • Web Interface: http://localhost:8880/web

Features

Core

OpenAI-Compatible Speech Endpoint
python
# Using OpenAI's Python library
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8880/v1", api_key="not-needed")
response = client.audio.speech.create(
    model="kokoro",  
    voice="af_bella+af_sky", # see /api/src/core/openai_mappings.json to customize
    input="Hello world!",
    response_format="mp3"
)

response.stream_to_file("output.mp3")

Or Via Requests:

python
import requests

response = requests.get("http://localhost:8880/v1/audio/voices")
voices = [v["id"] for v in response.json()["voices"]]

# Generate audio
response = requests.post(
    "http://localhost:8880/v1/audio/speech",
    json={
        "model": "kokoro",  
        "input": "Hello world!",
        "voice": "af_bella",
        "response_format": "mp3",  # Supported: mp3, wav, opus, flac, aac, pcm
        "speed": 1.0
    }
)

# Save audio
with open("output.mp3", "wb") as f:
    f.write(response.content)

Quick tests (run from another terminal):

bash
python examples/assorted_checks/test_openai/test_openai_tts.py # Test OpenAI Compatibility
python examples/assorted_checks/test_voices/test_all_voices.py # Test all available voices
Streaming Support
…

Or via requests:

python
import requests

response = requests.post(
    "http://localhost:8880/v1/audio/speech",
    json={
        "input": "Hello world!",
        "voice": "af_bella",
        "response_format": "pcm"
    },
    stream=True
)

for chunk in response.iter_content(chunk_size=1024):
    if chunk:
        # Process streaming chunks
        pass

Key Streaming Metrics:

  • First token latency @ chunksize
    • ~300ms (GPU) @ 400
    • ~3500ms (CPU) @ 200 (older i7)
    • ~<1s (CPU) @ 200 (M3 Pro)
  • Adjustable chunking settings for real-time playback

Note: Artifacts in intonation can increase with smaller chunks

Multiple Output Audio Formats
  • mp3
  • wav
  • opus
  • flac
  • aac
  • pcm

Voices

Voice Combination
  • Weighted voice combinations using ratios (e.g., "af_bella(2)+af_heart(1)" for 67%/33% mix)
  • Ratios are automatically normalized to sum to 100%
  • Available through any endpoint by adding weights in parentheses
  • Saves generated voicepacks for future use

Combine voices and generate audio:

…

Voice Aliases

Weighted mixes can get long fast. voice_aliases maps a short name per request, for both the voice field and [voice:...] tags:

  • Aliases prefer to match case-insensitively (keep lowercase to avoid inconsistencies).
  • An alias pointing at a nonexistent voice returns a 400.
  • The web UI's cast exports in the same format e.g. {"voice_aliases": {...}}; interchangeable for API calls.
python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8880/v1", api_key="not-needed")

client.audio.speech.create(
    model="kokoro",
    voice="narrator",
    input="[voice:narrator] Once upon a time. [voice:villain] Never!",
    extra_body={
        "allow_voice_tags": True,
        "voice_aliases": {"narrator": "af_bella(2)+af_sky", "villain": "am_michael"},
    },
)

or

bash
curl -X POST http://localhost:8880/v1/audio/speech \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kokoro",
    "voice": "narrator",
    "input": "[voice:narrator] Once upon a time. [voice:villain] Never!",
    "allow_voice_tags": true,
    "voice_aliases": {"narrator": "af_bella(2)+af_sky", "villain": "am_michael"},
    "response_format": "mp3"
  }' --output aliased.mp3
Voice Tuning (reference clip)

POST /dev/tune takes a 3 to 30 s clip of one English speaker and speaks with a voice tuned toward it, via inno-kokoro. A tuner, not a cloner: expect the same neighbourhood, not a match. Only tune voices you have permission to use.

bash
curl -s http://localhost:8880/dev/tune -F [email protected] -F 'request={"input":"Hello there."}' -o out.mp3
curl -s http://localhost:8880/dev/tune -F [email protected] -F return_voice_pack=true -o ref.pt
curl -s http://localhost:8880/dev/tune -F [email protected] -F save_voice=am_ref   # saves am_ref_tuned, needs ALLOW_LOCAL_VOICE_SAVING=true
  • request is the /v1/audio/speech body minus voice; the pack only exists for the length of the response unless save_voice keeps it in VOICES_DIR
  • Names follow the existing language prefix pattern (am_, bf_, ax_, etc.) and saved voices get a _tuned suffix. Bundled tuned voices end in _inno
  • Knobs: prosody_head (default on), fmax pitch ceiling in Hz (default auto)
  • Off by default:
    • ENABLE_INNO_TUNER=true enables with a web player tab
    • ALLOW_LOCAL_VOICE_SAVING=true allows saving them to the live server.
  • Full reference in docs/inno-tune.md
Multi-Speaker / Dialogue
  • [voice:...] tags switch speakers inline, anywhere input is accepted
  • /v1/audio/speech needs allow_voice_tags: true per request; /dev/dialogue allows them by default
  • ENABLE_VOICE_TAGS=false opts out server-wide: the parameter is refused and /dev/dialogue 403s
bash
curl -X POST http://localhost:8880/v1/audio/speech \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kokoro",
    "voice": "af_heart",
    "input": "The narrator opens. [voice:af_bella] Did it land? [pause:0.3s] [voice:am_michael] It did.",
    "allow_voice_tags": true,
    "response_format": "mp3"
  }' --output dialogue.mp3

With the official OpenAI client, pass the param in extra_body:

python
client.audio.speech.create(
    model="kokoro",
    voice="af_jadzia",
    input="The narrator opens. [voice:af_bella] Did it land?",
    extra_body={"allow_voice_tags": True},
)

`POST /dev/dialogu

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonfastapihuggingface-spaceskokorokokoro-tts

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架