# Voices endpoints

A voice is a saved speaker: a `clone`, made from clips of a real speaker, or a
`builtin`, one of a model's own voices. Avatars are on
[Artwork endpoints](https://mirli.app/docs/api-artwork/index.md); transcription is
[Transcribe speech](https://mirli.app/docs/api-speech/index.md#transcribe-speech).

Each endpoint lists the errors it returns itself. Any endpoint can also return
the [common errors](https://mirli.app/docs/api-errors/index.md#common-errors). A `400` from a model error
has `detail` and a [failure object](https://mirli.app/docs/api-errors/index.md#failure-object).

## Voice object

The voice endpoints return this object:

| Field | Type | Description |
|---|---|---|
| `id`, `name`, `created_at` | string | Id, display name, ISO 8601 creation time |
| `kind` | string | `clone`, `builtin` or `trained` (see [Trained singing voices](#trained-singing-voices)) |
| `reference_file` | string or null | `clone`: the file the model reads, `/files/<FILE>.wav` |
| `voice_id` | string or null | `builtin`: the model's own voice id |
| `model_id` | string or null | The model it speaks through. Null on old clones |
| `notes` | string or null | Free text; its avatar's prompt |
| `artwork` | string or null | Avatar URL, `/artwork/<FILE>.png` |
| `read_count` | integer | Its single-voice reads and conversions |
| `samples` | object[] | `clone`: its clips, oldest first, each with `id`, `file` (`/files/<FILE>.wav`), `duration_s`, `created_at` and `reference_text`. `trained`: its training clips |
| `trained` | object | `trained` only: `status` (`draft`, `training` or `ready`), `f0_median_hz`, `sample_rate`, `epochs`, `has_index`, `dataset_s`, `train_s`, `trained_at` and `last_error` |

A clip's `reference_text` is its exact transcript, up to 20,000 characters
(**Reference Transcript** in Voice Lab). `duration_s` is null on old clips.

A clone holds 1 to 5 clips of one speaker, joined into the one file audio.cpp
reads: each mono, levelled to the set's median loudness, 0.3 s apart.
`reference_file` is that file or the only clip, and its URL changes with
them. A clip under 1 s, over 60 s or almost silent is refused, and a voice's
clips total under 90 s, since models read only the start of a longer
reference.

For Fish Audio, every clip needs a non-blank transcript: speech and segment
generation return `400` before any work if one is missing, naming the
voice and clips. The transcripts, joined in clip order, become
`request_options.reference_text`. Other models need none.

`tidy` (off by default over the API, on in the app) removes DC offset, trims
near-silence from both ends, leaving some padding, and pulls a peak over full
scale back under. It never boosts a clip or changes its tone, and the result
is rechecked.

## List voices

`GET /api/voices`

Returns every voice a script can be read in (`clone` and `builtin`), newest
first. `?kind=trained` returns the trained singing voices instead; nothing
else is accepted for `kind`.

This request lists the voices:

```bash
curl http://127.0.0.1:17494/api/voices
```

A successful response is `200 OK` with the voices:

```json
[
  {
    "id": "8d0f3a52-6b1e-4c7a-9f24-3e5b7c1d9a60",
    "name": "Ada",
    "kind": "clone",
    "created_at": "2026-11-29T10:00:00.000Z",
    "reference_file": "/files/voice-8d0f3a52-6b1e-4c7a-9f24-3e5b7c1d9a60.wav",
    "voice_id": null,
    "model_id": "audiocpp-chatterbox",
    "notes": "Warm, low, unhurried",
    "artwork": null,
    "read_count": 3,
    "samples": [
      {
        "id": "8d0f3a52-6b1e-4c7a-9f24-3e5b7c1d9a60",
        "file": "/files/voice-8d0f3a52-6b1e-4c7a-9f24-3e5b7c1d9a60.wav",
        "duration_s": 8.2,
        "created_at": "2026-11-29T10:00:00.000Z",
        "reference_text": "The quick brown fox jumps over the lazy dog."
      }
    ]
  }
]
```

This endpoint returns only the common errors.

## Get a voice

`GET /api/voices/<VOICE_ID>`

Returns one voice.

| Name | Type | Required | Description |
|---|---|---|---|
| `<VOICE_ID>` | string | Yes | The voice's id |

This request reads one voice:

```bash
curl "http://127.0.0.1:17494/api/voices/<VOICE_ID>"
```

A successful response is `200 OK` with the [voice object](#voice-object).

| Status | Cause |
|---|---|
| `404` | No voice has this id |

## Create a voice

`POST /api/voices`

Saves a `builtin`, or a `clone` from a copy of a library sound.

| Name | Type | Required | Description |
|---|---|---|---|
| `name` | string | Yes | 1 to 120 characters |
| `kind` | string | No | `clone` (default) or `builtin` |
| `voice_id` | string | For `builtin` | The model's voice id, up to 120 characters |
| `model_id` | string | No | For a clone, a `tts` model that clones |
| `notes` | string | No | Up to 2,000 characters |
| `source_sound_id` | string | For `clone` | The library sound to copy |
| `reference_text` | string | No | The clip's transcript, up to 20,000 characters |
| `tidy` | boolean | No | Tidies the clip. Default `false` |

This request clones a library sound:

```bash
curl -X POST "http://127.0.0.1:17494/api/voices" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Ada",
    "model_id": "audiocpp-chatterbox",
    "source_sound_id": "<SOUND_ID>",
    "reference_text": "The quick brown fox jumps over the lazy dog.",
    "tidy": true
  }'
```

A successful response is `201 Created` with the new
[voice object](#voice-object).

| Status | Cause |
|---|---|
| `400` | `model_id` is unknown or unfit, `voice_id` is missing or not the model's, `source_sound_id` is missing or not a sound, or the clip breaks the rules |

## Create a voice from a file

`POST /api/voices/upload`

Saves a `clone` from a WAV body up to 64 MB (`audio/wav`, `audio/x-wav`,
`audio/wave` or `application/octet-stream`) and URL-encoded query
parameters.

| Name | Type | Required | Description |
|---|---|---|---|
| `?name` | string | Yes | 1 to 120 characters |
| `?notes`, `?model_id`, `?reference_text`, `?tidy` | string, boolean | No | As on [Create a voice](#create-a-voice) |

This request clones a voice from `ada.wav`:

```bash
curl -X POST "http://127.0.0.1:17494/api/voices/upload?name=Ada&tidy=true" \
  -H 'Content-Type: audio/wav' \
  --data-binary @ada.wav
```

A successful response is `201 Created` with the new
[voice object](#voice-object).

| Status | Cause |
|---|---|
| `400` | The body is not a readable WAV, `model_id` is unfit, or the clip breaks the rules |
| `413` | The body is over 64 MB |
| `422` | `name` is missing |

## Update a voice

`PATCH /api/voices/<VOICE_ID>`

Changes a voice's name, notes or clip transcripts, not its audio.

| Name | Type | Required | Description |
|---|---|---|---|
| `<VOICE_ID>` | string | Yes | The voice's id |
| `name` | string | No | 1 to 120 characters |
| `notes` | string or null | No | Up to 2,000 characters; `null` clears |
| `samples` | object[] | No | Up to 5 `{ "id", "reference_text" }` transcript changes |

This request sets one clip's transcript:

```bash
curl -X PATCH "http://127.0.0.1:17494/api/voices/<VOICE_ID>" \
  -H 'Content-Type: application/json' \
  -d '{"samples": [{"id": "<SAMPLE_ID>", "reference_text": "Halt."}]}'
```

A successful response is `200 OK` with the updated
[voice object](#voice-object).

| Status | Cause |
|---|---|
| `400` | A clip id in `samples` is not this voice's |
| `404` | No voice has this id |

## Delete a voice

`DELETE /api/voices/<VOICE_ID>`

Deletes the voice and its clip and reference files.

| Name | Type | Required | Description |
|---|---|---|---|
| `<VOICE_ID>` | string | Yes | The voice's id |

This request deletes one voice:

```bash
curl -X DELETE -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/voices/<VOICE_ID>"
```

A successful response is `204 No Content`.

| Status | Cause |
|---|---|
| `404` | No voice has this id |

## Add a clip

`POST /api/voices/<VOICE_ID>/samples`

Adds a clip to a clone and rebuilds its reference file. The body is JSON, or a
WAV up to 64 MB with the fields as query parameters.

| Name | Type | Required | Description |
|---|---|---|---|
| `<VOICE_ID>` | string | Yes | The voice's id |
| `source_sound_id` | string | For JSON | The library sound to add |
| `reference_text`, `tidy` | string, boolean | No | As on [Create a voice](#create-a-voice) |

This request adds a library sound as a clip:

```bash
curl -X POST "http://127.0.0.1:17494/api/voices/<VOICE_ID>/samples" \
  -H 'Content-Type: application/json' \
  -d '{"source_sound_id": "<SOUND_ID>", "reference_text": "Halt."}'
```

A successful response is `201 Created` with the updated
[voice object](#voice-object).

| Status | Cause |
|---|---|
| `400` | The WAV is unreadable, the voice is `builtin` or full, the clips would pass 90 s, the sound does not exist, or the clip breaks the rules |
| `404` | No voice has this id |
| `413` | The body is over 64 MB |

## Remove a clip

`DELETE /api/voices/<VOICE_ID>/samples/<SAMPLE_ID>`

Removes a clip and its file and rebuilds the reference file.

| Name | Type | Required | Description |
|---|---|---|---|
| `<VOICE_ID>` | string | Yes | The voice's id |
| `<SAMPLE_ID>` | string | Yes | The clip's id |

This request removes one clip:

```bash
curl -X DELETE -H 'X-Soundbox: 1' \
  "http://127.0.0.1:17494/api/voices/<VOICE_ID>/samples/<SAMPLE_ID>"
```

A successful response is `200 OK` with the updated
[voice object](#voice-object).

| Status | Cause |
|---|---|
| `400` | It is the only clip |
| `404` | No such voice, or no such clip on it |

## Export a voice

`GET /api/voices/<VOICE_ID>/export`

Returns the voice as a download, `<NAME>.soundbox-voice.json`, where the name
keeps only ASCII letters, digits, spaces, `_` and `-` (else `voice`). Each clip
travels as base64 WAV, oldest first. The joined file, which import rebuilds,
and the avatar, which can be redrawn from the notes, are left out.

| Name | Type | Required | Description |
|---|---|---|---|
| `<VOICE_ID>` | string | Yes | The voice's id |

This request saves a voice to a file:

```bash
curl -o Ada.soundbox-voice.json \
  "http://127.0.0.1:17494/api/voices/<VOICE_ID>/export"
```

A successful response is `200 OK` with the export. The example shortens the
base64:

```json
{
  "format": "soundbox-voice",
  "version": 1,
  "exported_at": "2026-11-29T10:00:00.000Z",
  "voice": {
    "name": "Ada",
    "kind": "clone",
    "voice_id": null,
    "model_id": "audiocpp-chatterbox",
    "notes": "Warm, low, unhurried"
  },
  "samples": [
    {
      "wav_base64": "UklGRiQAAABXQVZF",
      "duration_s": 8.2,
      "reference_text": "The quick brown fox jumps over the lazy dog."
    }
  ]
}
```

| Status | Cause |
|---|---|
| `404` | No voice has this id |

## Import a voice

`POST /api/voices/import`

Copies an exported voice under a new id. A taken name gets " (2)", " (3)"
and so on, and a clone's unknown `model_id` is dropped. Clips are checked
against the clip rules, untidied; one bad clip undoes the import.

| Name | Type | Required | Description |
|---|---|---|---|
| `format` | string | Yes | `soundbox-voice` |
| `version` | integer | Yes | `1` |
| `voice` | object | Yes | As in an [export](#export-a-voice) |
| `samples` | object[] | No | Up to 5 clips, as in an export. `exported_at` is ignored |

This request imports a voice from a file:

```bash
curl -X POST "http://127.0.0.1:17494/api/voices/import" \
  -H 'Content-Type: application/json' \
  --data-binary @Ada.soundbox-voice.json
```

A successful response is `201 Created` with the new
[voice object](#voice-object).

| Status | Cause |
|---|---|
| `400` | A `builtin`'s model or `voice_id` is not on this Mirli, a clone has no clips, or a clip is unreadable or breaks the clip rules |
| `413` | The body is over 64 MB |

## Trained singing voices

A `trained` voice is a model of one singer's voice, trained on this machine
from their recordings. It only [converts](https://mirli.app/docs/api-speech/index.md#convert-a-voice)
recordings; speaking or reading a script in one is refused. It is listed with
`GET /api/voices?kind=trained`, not with the speech voices. Training runs
[Applio](https://github.com/IAHispano/Applio)'s RVC v2 trainer in its own
Python environment; conversion runs on `audiocpp-rvc`. Measurements and
licences: [singing-voice-training.md](https://github.com/HamSanders/soundbox/blob/main/docs/singing-voice-training.md).

A trained voice moves from `draft` (gathering clips) to `training` to
`ready`. A run that fails or is cancelled goes back to where it was, with
`trained.last_error` set, and keeps the clips; a retrain that fails keeps the
previous model. Deleting one is refused while it trains.

| Endpoint | What it does |
|---|---|
| `GET /api/trainer` | Whether training can run here: `installed`, `source` (`env` or `managed`), `python`, `applio_dir`, `install_job_id`, and `problem` (why it can't, or null) |
| `POST /api/trainer/install` | `202` with a `job_id`: sets up the trainer under `<data dir>/runtimes/rvc-train` with [uv](https://docs.astral.sh/uv/), about 7 GB. Needs the `downloads` capability |
| `POST /api/voices/trained` | `201` with a new `draft` voice. Body: `name`, optional `notes`, and `consent`, which must be `true`. Anything else is `422` |
| `POST /api/voices/<VOICE_ID>/training-clips` | `201` with the voice. Body: a WAV (up to 1 GB), or JSON `{ "source_sound_id": ... }`. A clip under 1 s, or a set over 60 minutes, is refused |
| `POST /api/voices/<VOICE_ID>/training-clips/folder` | Adds every `.wav` in a folder on this machine, in name order. Body: `{ "path": ... }`. Answers `{ voice, added, skipped }`. Needs the `filesystem` capability |
| `DELETE /api/voices/<VOICE_ID>/samples/<SAMPLE_ID>` | Removes a training clip, as for a clone's clip |
| `POST /api/voices/<VOICE_ID>/train` | `202` with a `job_id` (kind `train_voice`). Body, optional: `epochs` (10 to 1000, default 200) and `batch_size` (1 to 32, default 8). Needs at least 60 s of clips and an installed trainer. Cancel it with `POST /api/jobs/<JOB_ID>/cancel` |

`MIRLI_RVC_PYTHON` and `MIRLI_RVC_APPLIO_DIR` point Mirli at a Python and an
Applio checkout you installed yourself, instead of its own.

This request trains a voice from a folder of takes:

```bash
VOICE=$(curl -s -X POST http://127.0.0.1:17494/api/voices/trained   -H 'Content-Type: application/json'   -d '{"name": "My voice", "consent": true}' | jq -r .id)
curl -X POST "http://127.0.0.1:17494/api/voices/$VOICE/training-clips/folder"   -H 'Content-Type: application/json' -d '{"path": "C:/takes"}'
curl -X POST "http://127.0.0.1:17494/api/voices/$VOICE/train"   -H 'Content-Type: application/json' -d '{"epochs": 200}'
```
