Skip to content

ktos/kittentts-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KittenTTS API

OpenAI-compatible TTS API built with FastAPI and the great (and fast and tiny) KittenTTS.

Using kitten-tts-mini (80M) model by default, the model used can be configured via environment variable. Model is automatically downloaded and loaded on startup.

Features

  • OpenAI-compatible /v1/audio/speech endpoint
  • Multiple output formats: WAV, MP3, OGG

Quick Start

Using Docker

# Pull the image
docker pull ghcr.io/ktos/kittentts-api:latest

# Run the container
docker run -d -p 8000:8000 ghcr.io/ktos/kittentts-api:latest

API Usage

cURL

curl -X POST http://localhost:8000/v1/audio/speech \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "Hello world!",
    "voice": "Jasper",
    "response_format": "mp3"
  }' \
  -o output.mp3

OpenAI Python Client

from openai import OpenAI

client = OpenAI(
    api_key="dummy",
    base_url="http://localhost:8000/v1"
)

response = client.audio.speech.create(
    model="tts-1",
    input="Hello world!",
    voice="Jasper",
    response_format="mp3"
)

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

API Endpoints

Endpoint Description
POST /v1/audio/speech Generate speech audio
GET /v1/models List available models (tts-1 for compatibility)

Configuration

You can specify the KittenTTS model to use by setting the KITTEN_TTS_MODEL environment variable. Available models:

  • KittenML/kitten-tts-mini-0.8 (default, 80M parameters)
  • KittenML/kitten-tts-micro-0.8
  • KittenML/kitten-tts-nano-0.8
  • KittenML/kitten-tts-nano-0.8-int8

Example:

docker run -e KITTEN_TTS_MODEL=KittenML/kitten-tts-nano-0.8 -p 8000:8000 kittentts-api

Development

Local Setup

# Install dependencies
pip install -r requirements.txt

# Install ffmpeg (required for MP3/OGG)
# Ubuntu/Debian:
sudo apt install ffmpeg
# macOS:
brew install ffmpeg
# Windows:
winget install ffmpeg

# Run the server
uvicorn main:app --reload

Build Docker Image

docker build -t kittentts-api .

License

AGPLv3

About

An OpenAI API compatible wrapper for KittenTTS

Topics

Resources

License

Stars

Watchers

Forks

Packages