Deploy Kokoro TTS API

FastAPI Wrapper for Kokoro Text to Speech

Deploy Kokoro TTS API

Just deployed

Deploy and Host Kokoro-FastAPI on Railway

Kokoro-FastAPI is a Dockerized FastAPI wrapper for the Kokoro-82M text-to-speech model. It provides OpenAI-compatible endpoints for multi-language speech synthesis with support for multiple audio formats, streaming, and voice combinations.

About Hosting Kokoro-FastAPI

Deploying Kokoro-FastAPI on Railway gives you an OpenAI-compatible text-to-speech API. The service supports multiple output formats (MP3, WAV, Opus, FLAC, M4A, PCM), streaming audio with configurable chunk sizes, and multi-language synthesis including English, Japanese, and Chinese. Advanced features include weighted voice combinations, word-level timestamped captions, and natural boundary detection for automatic sentence-based splitting. A built-in web UI and API documentation are included.

Common Use Cases

  • Drop-in replacement for OpenAI's text-to-speech API
  • Generating audio content in multiple languages
  • Creating custom voices by combining existing voice profiles
  • Producing captioned audio with word-level timestamps
  • Streaming audio generation for real-time applications

Dependencies for Kokoro-FastAPI Hosting

  • Docker container runtime
  • Kokoro-82M model (Apache 2.0 licensed)

Deployment Dependencies

Implementation Details

OpenAI-compatible client usage:

from openai import OpenAI

client = OpenAI(
    base_url="https://your-app.up.railway.app/v1",
    api_key="your-api-key"
)

response = client.audio.speech.create(
    model="kokoro",
    voice="af_bella",
    input="Hello world!"
)
response.stream_to_file("output.mp3")

Voice combinations with weighted ratios:

response = client.audio.speech.create(
    model="kokoro",
    voice="af_bella(2)+af_sky(1)",  # 67% bella, 33% sky
    input="Hello world!"
)

API Endpoints:

EndpointPurpose
POST /v1/audio/speechOpenAI-compatible speech synthesis
GET /v1/audio/voicesList available voices
POST /v1/audio/voices/combineCreate weighted voice combinations
POST /dev/captioned_speechGenerate audio with timestamps

Web Interfaces:

  • API Documentation: /docs
  • Web UI: /web

Why Deploy Kokoro-FastAPI on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Kokoro-FastAPI on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

View Template
openui
Deploy OpenUI: AI-powered UI generation with GitHub OAuth and OpenAI API.

View Template
firecrawl
firecrawl api server + worker without auth, works with dify