# Voice and story tools

Tools that read text aloud and build stories. A story is a persistent script whose lines each carry a lane, a start
time and, once read, a sound. For the order an agent calls them in, see
[Sequence story calls](https://mirli.app/docs/agents-story-calls/index.md).

| Tool | Description |
|---|---|
| [`soundbox.list_voices`](#soundboxlist_voices) | List saved voices |
| [`soundbox.speak`](#soundboxspeak) | Read a line or a dialogue into one sound |
| [`soundbox.create_story`](#soundboxcreate_story) | Start a story |
| [`soundbox.list_stories`](#soundboxlist_stories) | List stories |
| [`soundbox.get_story`](#soundboxget_story) | Read a story |
| [`soundbox.add_lines`](#soundboxadd_lines) | Add lines, pauses or sounds |
| [`soundbox.update_line`](#soundboxupdate_line) | Edit or move a line |
| [`soundbox.speak_story`](#soundboxspeak_story) | Read every silent line |
| [`soundbox.delete_line`](#soundboxdelete_line) | Delete a line |
| [`soundbox.split_line`](#soundboxsplit_line) | Split a voiced line in two |
| [`soundbox.export_story`](#soundboxexport_story) | Mix a story to one sound |

## Shared behaviour

**Model selection.** `speak` and `speak_story` choose a model for each line, first match wins:

| Order | Model | When |
|---|---|---|
| 1 | The `model` argument | Passed |
| 2 | The line's voice's `model_id` | That model is installed |
| 3 | A ready text-to-speech model, preferring the loaded one; never one that bills per read | Otherwise |

A line that falls to order 3 although its voice has a model gets an entry in the result's `notes`.

**Delivery.** `delivery` is an object of parameter names to values, taken from the model's `delivery` list in
`list_models`. Unknown names are ignored without an error. The narrowest level wins:

| Set on | Applies to |
|---|---|
| `create_story` | Every line without its own |
| `add_lines`, per line | That line |
| `update_line` | That line; `{}` returns it to the story's |
| `speak` | The whole read |

Changing a delivery does not re-read a line.

**Story summary.** `create_story`, `add_lines`, `speak_story`, `delete_line`, `split_line`, `remove_track` and
`open_in_studio` return `story_id`, `title`, `lines`, `pauses`, `voiced`, `tracks` (when more than one), `duration_s`,
`delivery` (when set) and `open_in_studio`, a URL that opens the story in the app.

**Errors.** Every story tool fails with `No story with id <STORY_ID>` or `No line with id <LINE_ID>` for an unknown id.

## Voices

### `soundbox.list_voices`

Lists the saved voices a line can be cast to. Takes no arguments.

**Result:** an array of voices with `id`, `name`, `kind`, `model_id` (the model the voice was made on) and `notes`.

**Errors:** none.

### `soundbox.speak`

Reads one line, or a dialogue, into one finished sound in the library, and blocks until the audio is on disk.

| Argument | Type | Required | Description |
|---|---|---|---|
| `lines` | `{ text, voice_id?, speaker? }[]` | Yes | 1–200 lines. `text` is 1–20,000 characters, `speaker` up to 80. Different `voice_id`s make a dialogue |
| `model` | string | No | One text-to-speech model for every line. See [Shared behaviour](#shared-behaviour) |
| `gap_s` | number | No | Silence between lines, 0–5. Default `0.4` |
| `name` | string | No | The sound's name in the library, up to 200 characters |
| `delivery` | object | No | How the read is performed |

**Result:** an array of sounds, each with `models` (lines per model id) when the read spanned model families, and
`notes`.

**Errors:** no text-to-speech model ready; the read failed.

## Stories

### `soundbox.create_story`

Creates an empty story.

| Argument | Type | Required | Description |
|---|---|---|---|
| `title` | string | No | The story's title, up to 200 characters |
| `delivery` | object | No | The default delivery for every line |

**Result:** the story summary.

**Errors:** none.

### `soundbox.list_stories`

Lists stories, most recently worked on first.

| Argument | Type | Required | Description |
|---|---|---|---|
| `limit` | integer | No | 1–200. Default `20` |

**Result:** an array of stories.

**Errors:** none.

### `soundbox.get_story`

Reads a story with every line and every touched lane.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |

**Result:** the story's fields, `open_in_studio`, `tracks` (each touched lane's mix and device chain) and `lines`. Each
line has `id`, `kind`, `position`, `text`, `speaker`, `voice_id`, `track_index`, `start_s`, `duration_s`,
`trim_start_s`, `muted`, `gain_db`, `voiced`, `sound_id`, its own `delivery` when set, and `midi` for a clip placed
from the studio's MIDI panel (notes, tempo, instrument, cover prompt and strength, dry or cover, `take_id`). MIDI notes
are read-only over MCP.

**Errors:** `No story with id <STORY_ID>`.

### `soundbox.add_lines`

Appends lines to a story.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `lines` | object[] | Yes | 1–200 entries |

Each entry is one of three kinds, and any kind takes `track_index` (−16 to 16, default `0`) and `start_s` (≥ 0):

| Kind | Fields |
|---|---|
| Spoken line | `text` (up to 20,000 characters), `speaker` (up to 80), `voice_id`, `delivery` |
| Pause | `kind: "pause"`, `duration_s` (0–600) |
| Library sound | `sound_id` |

An entry without `start_s` starts where its track's last clip ends. A spoken line has no length until it is read.

Example arguments, two cast lines with a pause between them:

```json title="soundbox.add_lines arguments"
{
  "story_id": "<STORY_ID>",
  "lines": [
    {
      "speaker": "Guard",
      "voice_id": "<GUARD_VOICE_ID>",
      "text": "Who goes there?"
    },
    { "kind": "pause", "duration_s": 0.6 },
    {
      "speaker": "Thief",
      "voice_id": "<THIEF_VOICE_ID>",
      "text": "Just the wind."
    }
  ]
}
```

`<STORY_ID>` comes from `create_story`; the voice ids come from `list_voices`.

**Result:** `added` (the count) and the story summary.

**Errors:** `No story with id <STORY_ID>`.

### `soundbox.update_line`

Changes one line. Changing `text` or `delivery` does not re-read it.

| Argument | Type | Required | Description |
|---|---|---|---|
| `line_id` | string | Yes | The line |
| `text` | string | No | New words, up to 20,000 characters |
| `speaker`, `voice_id` | string or null | No | Recast. `speaker` is up to 80 characters |
| `track_index` | integer | No | −16 to 16 |
| `start_s` | number | No | Position on the timeline, ≥ 0 |
| `muted` | boolean | No | |
| `gain_db` | number | No | −40 to 24 |
| `duration_s` | number | No | How much of the clip plays, 0–600 |
| `trim_start_s` | number | No | How far into the source the clip begins, ≥ 0 |
| `delivery` | object | No | Overrides the story's; `{}` removes the override |

**Result:** the line, in the same shape as in `get_story`.

**Errors:** `No line with id <LINE_ID>`.

### `soundbox.speak_story`

Reads every line that has no audio yet, one line at a time, and blocks until all are read.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |
| `model` | string | No | One model for every line. See [Shared behaviour](#shared-behaviour) |
| `regenerate` | boolean | No | Also re-read lines that have audio. Default `false` |

**Result:** `read` (the count), `models` (lines per model id), `notes`, and the story summary.

**Errors:** a read failed, or ran past 15 minutes for one line.

### `soundbox.delete_line`

Removes one line from its story. The sound it used stays in the library.

| Argument | Type | Required | Description |
|---|---|---|---|
| `line_id` | string | Yes | The line |

**Result:** the story summary.

**Errors:** `No line with id <LINE_ID>`.

### `soundbox.split_line`

Cuts a voiced line into two clips. The text stays with the first.

| Argument | Type | Required | Description |
|---|---|---|---|
| `line_id` | string | Yes | The line |
| `at_s` | number | Yes | Seconds into the clip as it plays, after any trim. Greater than 0 |

**Result:** `halves` (the two lines) and the story summary.

**Errors:** the line has not been read yet; `at_s` falls outside the clip; the line's audio is missing.

### `soundbox.export_story`

Mixes the arrangement to one sound, honouring each clip's position, trim, gain and mute, and blocks until it is on
disk. Devices on the lanes are not applied.

| Argument | Type | Required | Description |
|---|---|---|---|
| `story_id` | string | Yes | The story |

**Result:** the new sound and `open_in_studio`.

**Errors:** the export failed or produced no audio.
