Audio player
A recording with its own controls: a voice note, a call, a podcast clip. Play, a scrubber (over a waveform if you have one), the time, speed, and a transcript that follows along.

Needs Alpine and the package's script for its own controls. Without them it is the browser's audio player, and a transcript is plain text. See getting started.
Use it
<x-ds::audio-player
:src="$note->url"
:title="$note->title"
:artist="$note->author->name"
:duration="$note->seconds"
:waveform="$note->peaks"
:download="true"
/>
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
src | string | — | The recording. Or sources. |
sources | array | [] | Rows of src and type; the browser plays the first it can. |
tracks | array | [] | Rows of src, kind, srclang, label, default: passed through as <track>. |
title | string | — | Names the player, and goes to the system's media controls. |
artist | string | — | For the system's media controls. |
label | string | Recording | Names the player when there is no title. |
duration | number | — | Seconds, if you know them: shown before the file has loaded. |
waveform | array | — | Peaks, one per bar, on any scale: drawn as bars that light as it plays. Compute them once on the server (for example with audiowaveform or ffmpeg). |
cues | array | [] | Rows of start, end (seconds), text and optionally speaker: a transcript that follows along. |
variant | full compact | full | Compact is one row, for a chat bubble. |
speeds | array | [0.75, 1, 1.25, 1.5, 2] | What the speed button steps through. |
download | bool or string | false | A download link: true for src, or a URL. |
independent | bool | false | Plays alongside others instead of pausing them. |
preload | none metadata auto | metadata | Passed to the audio element. |
Instead of cues, a transcript slot takes your own markup; mark each line
data-ds-audio-cue with data-start and data-end and it follows along too.
How it behaves
- One at a time. Starting a player pauses any other that is playing,
unless one of them is
independent. - The transcript marks the line being spoken and keeps it in view. Each line's time is a button that plays from there.
- Events:
play,pauseandended, andtimeupdateat most once a second, with{ currentTime, duration }, so a host can save where the reader got to.
Accessibility
- A named
group. Play is one button whose name changes, Play and Pause. - The scrubber is a native slider named "Seek", whose value is said in words: "1 minute 12 seconds of 4 minutes". The words change once a second, not on every frame.
- Speed says its value ("Playback speed 1.5×"); Mute is a toggle with
aria-pressed. Volume is left out on touch screens, where the device's buttons do it. - An error is said in a status region.
| Key | Does |
|---|---|
| Space | Play or pause, from anywhere in the player but a button, link or field |
| Left / Right, Down / Up (on the scrubber) | Back / forward 5 seconds |
| Page Down / Page Up (on the scrubber) | Back / forward 30 seconds |
| Home / End (on the scrubber) | The start / the end |
Don't
- Don't autoplay. Nothing starts it but a press.
- Don't compute the waveform in the browser. Decoding the whole file to draw bars is the cost the server pays once.
- Don't leave out a transcript for speech that matters: it is the only way some readers get it.
More in specs/audio-player.md.
From the package repo: edit this page on GitHub.