> ## Documentation Index
> Fetch the complete documentation index at: https://docs.m-star.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Kokoro

> Install the English pronunciation model, choose a voice and save a WAV.

Choose Kokoro for a small, single-GPU speech service with preset voices. The checkpoint synthesizes text or precomputed phonemes and returns 24 kHz audio.

## Install and start

Text input needs Python 3.12 for the `misaki` pronunciation packages. On Python 3.13 or later, send precomputed `phonemes`. For English, install the spaCy tagger before starting.

### `kokoro`

Text → audio. The default `kokoro.yaml` uses 1 GPU. The [weights](https://huggingface.co/hexgrad/Kokoro-82M) use Apache-2.0.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[kokoro]"
python -m spacy download en_core_web_sm
mstar serve kokoro
```

[Send the request](#synthesize).

## Send a request

Run either client example in a second terminal after `/health` returns 200.

### Synthesize a sentence

Save the synthesized speech as `reply.wav`.

**Python SDK**

```python theme={null}
from mstar import MStarClient

client = MStarClient("http://localhost:8000")
reply = client.tts(
    'The next stop is Central.',
    voice='af_heart',
)
reply.to_wav("reply.wav")
```

Use `client.voices()` to list names, or mix two with `voice="af_bella+af_sky"`. For voice applications, the [LiveKit Agents example](https://github.com/mstar-project/mstar/blob/main/examples/livekit_kokoro.py) and [Pipecat example](https://github.com/mstar-project/mstar/blob/main/examples/pipecat_kokoro.py) stream PCM from the server through their OpenAI TTS plugins.

**curl**

```bash theme={null}
curl -fsS http://localhost:8000/v1/audio/speech \
  -H 'Content-Type: application/json' \
  -d '{"input": "The next stop is Central.", "response_format": "wav", "voice": "af_heart"}' -o reply.wav
```

## Deployment configs

| File | GPUs | Use |
| - | - | - |
| `kokoro.yaml` | 1 | Default; the model runs in float32 |
| `kokoro_bf16.yaml` | 1 | The vocoder trunk in bfloat16 for more throughput; float32 is the parity-tested path |

To use an alternative, pass `--config configs/<file>` after the launcher name. From a wheel installation, [copy the shipped YAML](https://docs.m-star.org/serving.md#custom-configs) and pass its local path.

## Settings and defaults

Request fields (on `/v1/audio/speech` the non-OpenAI ones go in `extra_body`):

| Field | Default | Effect |
| - | - | - |
| `voice` | `af_heart` | A bundled voice, or a blend such as `af_bella+af_sky` or `af_bella(2)+af_sky(1)`. |
| `speed` | 1.0 | 0.25 to 4.0. |
| `lang_code` | the voice's prefix | G2P language: `a` American English, `b` British, `e` Spanish, `f` French, `h` Hindi, `i` Italian, `p` Portuguese, `j` Japanese, `z` Mandarin. |
| `phonemes` | none | Skip G2P and synthesize this phoneme string. |

Install `misaki[ja]>=0.9.4` for Japanese or `misaki[zh]>=0.9.4` for Mandarin. Install `misaki[en]>=0.9.4` for the English espeak-ng fallback. Without that fallback, Kokoro can skip English words outside its pronunciation dictionary.

Deployment `model_kwargs` (see the comments in `configs/kokoro.yaml`):

| Knob | Default | Effect |
| - | - | - |
| `lang_code` | per voice | Fixes the G2P language for every request. |
| `espeak_fallback` | `true` | `false` skips espeak-ng even when it is installed. |
| `default_voice` | `af_heart` | The voice when a request names none. |
| `chunk_target_phonemes`, `first_chunk_target_phonemes` | 200, 80 | Sentence packing. A short first chunk gives early first audio. |
| `text_buckets`, `frame_buckets`, `capture_batch_sizes`, `max_batch_frames` | see config | The CUDA graphs captured at startup. Use fewer buckets on a smaller GPU. |
| `compile_decoder` | `true` | `false` skips `torch.compile` of the vocoder: startup in seconds, lower throughput. |
| `decoder_dtype` | `float32` | `bfloat16` runs the vocoder trunk in bf16. |

## Limits

* Text input only. An empty `voice` or `lang_code`, or a `speed` outside 0.25 to 4.0, is a 400.
* Text synthesis with a missing G2P package returns HTTP 400.
* Text is cut at sentence boundaries into chunks of at most 510 phonemes, the PL-BERT window.
* `temperature` and `top_p` are ignored: Kokoro does not sample.
* With the default `compile_decoder: true`, the first start on a GPU compiles the vocoder; see [Cold start](https://docs.m-star.org/cold-start.md#compile-cache).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.