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

# Audio

> Log and view audio data in Pluto

## Logging

Audio files can be logged via a file path or a NumPy array containing audio data shaped as `frames × channels`.

To log audio, instantiate the `pluto.Audio` class:

```python theme={null}
audio = pluto.Audio(
    data=Union[str, np.ndarray],
    rate=int | None = 48000,
    caption=str | None = None,
)
pluto.log({"audio/0": audio}, step=step)
```

| **Parameter** | **Type**                 | **Description**                                                         |
| ------------- | ------------------------ | ----------------------------------------------------------------------- |
| `data`        | `Union[str, np.ndarray]` | The audio data to log. Can be a path to an audio file or a NumPy array. |
| `rate`        | `int`                    | The sample rate of the audio data. Defaults to 48000.                   |
| `caption`     | `str`                    | A caption for the audio.                                                |

### Examples

#### Logging from File Paths

```python theme={null}
import httpx
r = httpx.get(
    "https://actions.google.com/sounds/v1/alarms/digital_watch_alarm_long.ogg"
)
with open(f"test.ogg", "wb") as f:
    f.write(r.content)

pluto.log({"audio": pluto.Audio(data="test.ogg")}, step=step)
```

#### Logging from NumPy Arrays

```python theme={null}
data = np.array([[1, 1, 1], [1, 1, 1]], dtype=np.float32)
pluto.log({"audio": pluto.Audio(data=data)}, step=step)
```

## Viewing

Logged audio files appear as player widgets with playback controls, volume adjustment, and per-file **Analyze** and **Download** buttons. When comparing multiple runs, each audio card shows the run name with its assigned color.

<Frame caption="Comparing multi-sample audio logs across runs.">
  <video autoPlay loop muted playsInline controls className="w-full rounded-xl" src="https://mintcdn.com/trainy/ck7WI5896eYTYADa/images/pluto/audio-viewing.mp4?fit=max&auto=format&n=ck7WI5896eYTYADa&q=85&s=86c94a43ed5a947cd0983c5e854b7849" data-path="images/pluto/audio-viewing.mp4" />
</Frame>

### Adding to a dashboard

Audio players show up automatically in the Compare view. To place them on a [custom dashboard](/pluto/dashboards), open **Add Widget**, choose the **Files** tab, and search for your audio log name.

<img src="https://mintcdn.com/trainy/ck7WI5896eYTYADa/images/pluto/add-widget-files-audio.png?fit=max&auto=format&n=ck7WI5896eYTYADa&q=85&s=e7b71fe377b92bc48d21bd8a4f3da117" alt="Adding a Files widget from the Add Widget modal" width="1352" height="1656" data-path="images/pluto/add-widget-files-audio.png" />

### Playback Controls

Each audio player includes:

* **Play / Pause** with a progress slider you can drag to seek
* **Skip forward / back** buttons (5-second jumps)
* **Volume slider** with mute toggle
* **Download** — saves the audio file locally
* **Analyze** — opens the audio analysis dialog (see below)

### Step Navigation

If you log audio at multiple training steps, use the step slider below the players to browse through different steps. This is useful for tracking how generated audio (e.g., text-to-speech) improves over the course of training.

When multiple audio groups are displayed in the same section, their step sliders can be **linked** so that changing the step on one group changes all of them simultaneously. Click the **lock icon** on the step navigator to toggle sync on or off.

### Multi-Sample Logging

Log **several clips at the same step under one log name** by passing a list. Every clip renders inside the same card with a per-cell `◀  i / N  ▶` nav row below the player:

```python theme={null}
pluto.log({
    "samples": [pluto.Audio(a), pluto.Audio(b)],
}, step=10)
```

<img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/multi-index-nav-audio.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=59992ec2a64d21ff3968cd7cbdd54503" alt="Two runs' audio players showing 1/4 and 3/4 multi-sample nav" style={{ maxWidth: '85%' }} width="1092" height="872" data-path="images/pluto/multi-index-nav-audio.png" />

#### Sync Sample Indices

A **Sync Sample Indices** selector in the media settings popover controls how the sample index is shared:

* **Off** — each run steps through its samples independently.
* **Across runs** — every run in the same widget shares the sample index.
* **Across widgets** (default) — every run on every media widget (image, video, and audio) advances the sample index in tandem.

The selector is always available, so you can opt a single widget out of cross-widget sync. Where a card has fewer samples than the shared index, it clamps to its own last sample, and single-sample cards show no nav row.

### Pinning Runs at a Step

The global step slider forces every run to be viewed at the same step, which makes it hard to compare runs at their respective best checkpoints — different runs converge at different steps. Pinning lets you freeze individual runs at a specific step while the global slider keeps driving everything else.

Each pinned card shows a colored badge with the pinned step. Click the pin button on an audio card to choose the pin scope:

| Symbol | Scope                     | Effect                                                                                                                                |
| ------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| ◇      | **Pin in this panel**     | Freezes only this card's run inside this audio widget. Other widgets for the same run still follow the global stepper.                |
| ◈      | **Pin across all panels** | Freezes this run at the chosen step in every audio widget on the page that shows it.                                                  |
| ★      | **Pin to best step**      | Pinned by a column-header action (see [Best-Step Pinning](#best-step-pinning) below), computed per run from a metric's argmin/argmax. |

<img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/pin-menu-audio.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=d44671250b05acf14e9017d11b86ceb6" alt="Pin scope menu on an audio card" width="1002" height="344" data-path="images/pluto/pin-menu-audio.png" />

#### Unpinning

Cross-panel and best-step pins offer two unpin options: **Unpin this audio** removes the pin from this widget only, while **Unpin across all panels** removes it everywhere. Local single-panel pins keep the simpler one-click unpin.

<img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/unpin-menu-audio.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=1aeca78df11171381b872b43099dca7b" alt="Unpin menu on a pinned audio card" width="976" height="344" data-path="images/pluto/unpin-menu-audio.png" />

#### Clear All Pins

Click **Clear All Pins** to remove every pin (local, cross-panel, and best-step) at once for the current page.

### Best-Step Pinning

For metric-driven exploration (e.g. "play each run at its best loss"), pin every run on the page to its own argmin/argmax step in one click. Open a metric column's header menu in the runs table, then choose **Find best step** → one of:

| Action                               | What it pins to                                                       |
| ------------------------------------ | --------------------------------------------------------------------- |
| **Pin steppers at min value**        | Each run pinned at the step where the metric is lowest                |
| **Pin steppers at max value**        | Each run pinned at the step where the metric is highest               |
| **Pin steppers at min (with media)** | Lowest metric value among steps that *also* have a clip for that run  |
| **Pin steppers at max (with media)** | Highest metric value among steps that *also* have a clip for that run |

The **(with media)** variants (grouped under *Pin to nearest media step*) are useful when your metric and audio cadences don't perfectly overlap — without them, the chosen step might land on a step that has no clip, so the card falls back to the **No audio at step N** placeholder.

<img src="https://mintcdn.com/trainy/ck7WI5896eYTYADa/images/pluto/find-best-step-audio.png?fit=max&auto=format&n=ck7WI5896eYTYADa&q=85&s=af99740ca3cc5fc40230e0efd834cf8b" alt="Find best step menu" width="974" height="794" data-path="images/pluto/find-best-step-audio.png" />

#### Tolerance Window

Even with the **(with media)** variants, your metric and audio cadences may not align exactly. The best-step picker handles this with a **nearest-snap with tolerance**: each metric step snaps to its closest clip step within a step-distance limit `K` (default `K = 20`).

You can edit `K` directly in the **Find best step** submenu — type a value, press Enter or click any of the four pin buttons.

**Widen the window if pins come up empty.** In the `tol-demo-gap` run below, the metric is logged at steps 0/50/100/150/200 and clips only at 25/75/125/175, so every metric step sits exactly 25 steps from the nearest clip. At the default `K = 20` nothing is within tolerance and the run stays **unpinned** (plain pin icon, no step badge); raise `K` to 25 and the min-loss step (100) snaps to audio step 125 — the provenance even notes the tie with step 75, broken toward the later step.

<div style={{ display: 'flex', gap: '1rem', flexWrap: 'wrap', alignItems: 'flex-start' }}>
  <img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/tolerance-audio-nopin.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=dfe09b8c9cd18dac7e8ad350f88469da" alt="tol-demo-gap unpinned at K=20" style={{ width: '48%', minWidth: '260px', borderRadius: '8px' }} width="686" height="312" data-path="images/pluto/tolerance-audio-nopin.png" />

  <img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/tolerance-audio-pinned.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=de53dfcfae4592ad59c1e72733499dee" alt="tol-demo-gap pinned at K=25" style={{ width: '48%', minWidth: '260px', borderRadius: '8px' }} width="902" height="484" data-path="images/pluto/tolerance-audio-pinned.png" />
</div>

**A wider window can also find a *better* step.** When the metric keeps improving past the nearest media step, a tight window snaps to a worse value. In `tol-demo-sparse` below, `K = 10` only reaches metric step 40 (loss 0.85), while `K = 25` reaches metric step 55 — the true minimum (loss 0.1). The pinned clip is the same in both (step 30); only the provenance popover reveals which metric step drove the pick.

<div style={{ display: 'flex', gap: '1rem', flexWrap: 'wrap', alignItems: 'flex-start' }}>
  <img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/tolerance-audio-bad.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=3343d1c9c4f2c83f3d3c07def79acffc" alt="tol-demo-sparse at K=10 reaching loss 0.85" style={{ width: '48%', minWidth: '260px', borderRadius: '8px' }} width="730" height="448" data-path="images/pluto/tolerance-audio-bad.png" />

  <img src="https://mintcdn.com/trainy/RSBzmM6c9FBJXx6L/images/pluto/tolerance-audio-good.png?fit=max&auto=format&n=RSBzmM6c9FBJXx6L&q=85&s=b97e67004b4305f67736d59a8ee97130" alt="tol-demo-sparse at K=25 reaching loss 0.1" style={{ width: '48%', minWidth: '260px', borderRadius: '8px' }} width="730" height="448" data-path="images/pluto/tolerance-audio-good.png" />
</div>

#### Pin Provenance

Every best-step pinned card shows an **info icon (ⓘ)** next to the run name. Hover for a popover that explains why this step was chosen:

* A headline with the metric and extreme that drove the pick (e.g. *Pinned at min train/loss = 0.006667*)
* The metric step that drove the pick
* How far the chosen clip is from that metric step (or that it matches exactly)

<img src="https://mintcdn.com/trainy/ck7WI5896eYTYADa/images/pluto/best-step-example-audio.png?fit=max&auto=format&n=ck7WI5896eYTYADa&q=85&s=43696dacf2877f643d08686c8748e09a" alt="A best-step pinned audio card with its provenance popover" width="890" height="480" data-path="images/pluto/best-step-example-audio.png" />

### Audio Analysis

Click **Analyze** on any audio player to open a dialog with three tabs:

* **Spectrum** — Real-time frequency spectrum visualization that animates during playback
* **Waveform** — Time-domain waveform drawn from the audio buffer
* **Statistics** — Peak amplitude, RMS level, duration, sample rate, number of channels, and dynamic range

<video autoPlay muted loop playsInline src="https://mintcdn.com/trainy/aYE6TEOOjuWImSUp/images/pluto/audio-analysis-demo.mp4?fit=max&auto=format&n=aYE6TEOOjuWImSUp&q=85&s=4a5dbc7c61fcb2268bd8f80e9f1da662" style={{ width: "100%", borderRadius: "8px" }} data-path="images/pluto/audio-analysis-demo.mp4" />
