> ## 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.

# CosyVoice3

> Clone a speaker from a clip and transcript or serve a directory of preset voices.

CosyVoice3 needs either a reference clip or a voice preset supplied by the deployment. Use a transcript of the clip for zero-shot prompting.

## Install and start

The default runs the language model, flow model and vocoder on one GPU. The optional `cosyvoice3_split.yaml` layout runs the flow model and vocoder on a second worker on the same GPU under NVIDIA MPS and needs about 67 GB.

### `cosyvoice3`

Text, audio → audio. The default `cosyvoice3.yaml` uses 1 GPU. The [weights](https://huggingface.co/FunAudioLLM/Fun-CosyVoice3-0.5B-2512) use Apache-2.0.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosyvoice3]"
mstar serve cosyvoice3
```

[Send the request](#synthesize).

## Send a request

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

### Synthesize a sentence

Record “Welcome aboard.” in `speaker.wav`, or substitute a clip of a few seconds and its exact transcript. The SDK writes a WAV. curl saves the PCM samples.

**Python SDK**

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

client = MStarClient("http://localhost:8000")
reply = client.tts(
    'The next stop is Central.',
    reference_audio="speaker.wav",
    ref_text='Welcome aboard.',
)
reply.to_wav("reply.wav")
```

**curl**

```bash theme={null}
curl -fsS http://localhost:8000/generate \
  --form-string 'text=The next stop is Central.' \
  -F files=@speaker.wav \
  --form-string input_modalities=audio,text \
  --form-string output_modalities=audio \
  --form-string streaming=false \
  --form-string 'model_kwargs={"ref_text":"Welcome aboard."}' \
  | python3 -c '
import base64, json, sys

outputs = json.load(sys.stdin)["outputs"]
with open("reply.pcm", "wb") as file:
    for chunk in outputs["audio"]:
        file.write(base64.b64decode(chunk["data"]))
'
```

## Deployment configs

| File | GPUs | Layout | Use |
| - | - | - | - |
| `cosyvoice3.yaml` | 1 | LM, flow and vocoder on one worker, cap 32 | Default |
| `cosyvoice3_split.yaml` | 1 | Flow and vocoder on a second worker on the same GPU, batches of 16, `mps: true` | Throughput; about 67 GB of GPU memory |

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`, all but `voice`, `instructions`, `temperature`, `top_p` and `seed` go in `extra_body`):

| Field | Effect |
| - | - |
| `voice` | A preset in `voices_dir`. |
| `ref_audio`, `ref_text` | A clip to clone (data URL or bare base64; an http(s) URL only with `MSTAR_ALLOW_REMOTE=1`) and its transcript. |
| `instructions` | A style instruction (`instruct` on `/generate`). |
| `temperature`, `top_p`, `top_k`, `ras_window`, `ras_tau` | Speech-token sampling. `top_k` is 1 to 128. |
| `n_cfm_timesteps` | Flow Euler steps. |
| `max_new_tokens` | Speech tokens at 25 Hz. A value above the deployment's limit is refused. |
| `seed` | Fixes the LM's sampling; the flow and vocoder noise is fixed. |
| `sentence_chunking` | Long text is synthesized as ordered sentence pieces of about 80 tokens, or 60 to 80 characters for text with Chinese, as the reference frontend does. `false` sends it whole. |

Deployment `model_kwargs` (listed in `configs/cosyvoice3.yaml`):

| Knob | Default | Effect |
| - | - | - |
| `voices_dir` | none | Preset clips. |
| `flow_cache_frames` | 768 | Frames whose flow K/V a streamed row keeps in `resources.flow_kv` (about 41 GiB for 32 requests). `0` re-solves every frame each hop and frees it. |
| `flow_estimator_dtype` | `bfloat16` | `float32` runs the flow estimator at the reference's precision, with lower throughput. |
| `flow_capture_frame_buckets`, `hift_capture_frame_buckets` | captured | `[]` captures no flow or vocoder graphs: faster startup, less memory, eager steps. |
| `stream_hop_tokens` | 25 | Speech tokens in the first flow hop; later hops double up to 100. `0` decodes once at the end with full attention. |
| `llm_weights` | `llm.pt` | `llm.rl.pt` loads the checkpoint's RL-tuned LM. |

## Limits

* A request with neither `ref_audio` nor a preset `voice` is a 400, and so is a reference clip over 30 s.
* One request's prompt (transcript or instruction) and text may hold at most 512 tokens. `/v1/audio/speech` cuts long text into pieces under it; on `/generate`, split it yourself.
* Request fields are strictly typed: `ras_window` and `n_cfm_timesteps` take a number, not a string or boolean, and an out-of-range value is a 400. `voice`, `instruct` and `ref_text` must be strings.
* `speed` has no effect and is logged as ignored.
* `lm_dtype: float32` cannot be served; the paged attention runs in bfloat16 or float16.
* Japanese written in kana only, with spaces between words, is read poorly, as it is by the official model.


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