Audio component
Shipped in OINK v1.7.0, documented in the Audio guide, and governed by the Components contract. Shared decisions are in the overview.
| Record | Value |
|---|---|
| Status | Accepted and shipped in OINK v1.7.0 (implemented 2026-11-27) |
| Owner | OINK maintainers |
| Delivery stage | S2, with video files |
| Form | Native: a block Markdown image whose destination is an audio file |
| New public API | None beyond accepting audio destinations; attributes caption, id, and preload |
| Runtime | Shared js/chunks/media.js for the control row and single-active playback |
| Affected surface | The media partial shared with Video, a stylesheet section, a new guide at /docs/components/audio/ |
Summary
An audio file renders as a figure: the bracket text as a visible title, the
browser’s native <audio controls>, and an optional caption. The transcript,
show notes, or lyrics are ordinary content after it; a folded callout keeps
them out of the way in HTML and expanded in Print.
Problem
Podcast episodes, text-to-speech and voice-model samples, pronunciation guides,
music excerpts, and recorded talks need a player inside prose. Today
 warns and drops, and raw <audio> has no title, caption,
Print, or RSS form. A bare player tells the reader nothing about what it plays.
Design principles
- Same syntax and branch as video. One media partial owns detection, lookup, and static outputs for both.
- The name is visible. A video shows its picture; audio has none, so the bracket text doubles as the visible title and the player’s accessible name.
- The page owns the controls; the browser owns playback. The native
<audio controls>is the no-JavaScript player. With the runtime, one theme control row with a single seek bar replaces it in every browser (revised 2026-11-28; the native strip first stood as the player). - Compose, don’t absorb. A transcript is content, and OINK already has a folded container that prints expanded. The component does not grow a body.
Goals and non-goals
Goals
- Local, bundle, global-asset,
static/, and object-storage audio files. - A visible, accessible title; an optional caption.
- Static Print, RSS, Markdown, and LLMS forms with a usable link.
- Native playback works without JavaScript. The shared runtime draws the control row and pauses other audible players.
Non-goals
- An
audioshortcode or a transcript body inside the component. - Hand-typed metadata that can drift from the file:
duration,artist. - Codec fallbacks (
mp3=,ogg=,m4a=). - In the first stage: cover art, chapters, waveforms.
- Podcast feeds or RSS
<enclosure>elements; podcast distribution is a site concern.
Proposed behavior
Detection
A block image is audio when its destination ends in mp3, m4a, aac,
oga, ogg, opus, wav, or flac in any letter case (a page or global
resource, a static/ path, or an HTTPS URL), or is a resource whose Hugo
media type is audio/*. Hugo defines no audio/* type by default, so the
media type only matters when a site declares one. Resolved local resources
preserve query strings and fragments (such as Media Fragments #t=30,60) with
their percent-encoding as written. An inline
audio destination renders as a plain link.
Attributes
| Attribute | Rule |
|---|---|
caption |
Plain text below the title, linked via aria-describedby |
id |
Validated like other figure IDs; an ID that another unnumbered audio or video figure or a numbered Book target already uses warns and is dropped from whichever comes second. Heading and plain image IDs are not compared |
preload |
metadata or none; defaults to metadata for the first 6 audio players on a page and none from the 7th onward |
num, poster, autoplay, track, width, height, link, command,
and options warn and are dropped. Book numbering is left out because
OINK’s numbered kinds are figures, tables, equations, and examples; calling a
recording a figure would mislabel it. An empty bracket text warns and the file
name becomes the title.
Rendering
Audio is always a figure (without .td-figure, so its header stays
start-aligned), because it always has a visible title. The player spans the
reading width; consecutive audio figures and an immediately following
.td-callout--details transcript use :has() positive margins so each
audio-transcript pair groups tighter than adjacent pairs: 8px between a
recording and its transcript, 16px between consecutive recordings, and the
ordinary media margins, 1.5rem above and 1.75rem below, around each group
(:where(.td-media):not(.td-figure), one class of weight above Bootstrap’s
figure reset). Presets style the
frame and title (the card takes --td-code-radius like callouts; Paper and Ink align its surface with adjacent callouts;
Terminal uses --td-brand-line-strong and --td-ui-font-family); the control
row follows the preset and color mode in every browser (see
Components), and the
no-JavaScript native player keeps the browser’s look.
preload="metadata" lets the browser show the duration without downloading
the file; switching the default to preload="none" from the seventh audio
player onward prevents connection bursts on long sample pages.
Outputs
| Output | Result |
|---|---|
| HTML | <audio controls>, replaced by the theme control row from js/chunks/media.js |
Title, caption, and the file URL as a visible .td-media__link on screen and paper (paper-palette overrides in @media print) |
|
| Markdown / LLMS | The authored source; a following transcript callout stays readable text |
| RSS | Title as a direct link to the file (absolute URL) and the caption |
| Rich copy | Start-aligned figure preserving title, caption, and clickable URL link |
The callout hook already renders folded callouts as static, expanded blocks in
dedicated Print and RSS, and Markdown keeps their source. A transcript written
as > [!DETAILS]- is therefore complete in every static output without any
audio-specific rule.
Large files
The Video guidance applies: prefer object storage for long recordings; page-bundle audio is committed to Git.
Trade-offs and alternatives
| Option | Decision | Reason |
|---|---|---|
First-draft {{< audio >}} with src, mp3, ogg, m4a, title, artist, cover, duration, chapters, caption, preload, loop, download, compact, and a transcript body |
Rejected | Codec fallbacks are obsolete, duration and artist are facts that drift from the file, cover and compact create two layouts, and the body duplicates a folded callout |
| A runtime for a speed toggle and chapters | Speed adopted 2026-11-28; chapters deferred | The theme control row cycles speed in every browser; chapters need WebVTT evidence before growing the UI. The shared media script handles single-active playback |
| Hidden bracket text, as for images | Rejected | A bare player is unlabeled for sighted readers |
| Numbering as a Book figure | Rejected | A recording is not a figure; a numbered audio kind would need its own Book index, which nothing requests |
Costs of the chosen form: no podcast-style card with cover art, and the player looks slightly different in each browser. Both are acceptable for a first stage whose job is to make audio publishable at all.
Later candidates
Each needs its own evidence and adds to js/chunks/media.js, which video
already introduces:
- Chapters: from a WebVTT
chapterstrack (the standard carrier) rather than a parameter mini-language. - Cover art:
posteron audio, if podcast pages ask for it.
Compatibility
Additive; today an audio destination warns and renders nothing.
Implementation plan
Audio lands with video files in S2 and reuses the same lookup extraction, media partial, and fixtures. Specific work:
- Audio detection, the figure layout, and static outputs in
content/media.html. - Fixtures: each source kind, an empty bracket text, an unsupported attribute, inline audio, consecutive samples, and a transcript callout in each output.
- Owning checks:
check-media-primitives.py,check-output.py,check-output-security.py,check-goldens.py,check-stylesheets.py,tests/js/media.test.js,tests/js/rich-copy.test.js, andtests/browser/audio.spec.mjs. No locale key is needed. - EN/ZH guide and cheatsheet row; contract update.
Acceptance criteria
- A single player shows elapsed time in the page accent. Starting a second audible player pauses the first.
- Each audio figure has a visible title and an accessible name via
aria-labelledby(plusaria-describedbywhen captioned). - Print, RSS, Markdown, and LLMS contain no
<audio>element and keep a usable link (visible on screen and paper in Print; linked title in RSS). - A following
> [!DETAILS]-transcript is expanded in dedicated Print and pairs tightly with its player on screen.
Open decisions
- Title placement. Resolved: above the player, start-aligned.
- Single-active playback in S2. Resolved: the same runtime handles progress for every file player and coordinates multiple audible players.
Decision log
- 2026-11-27 (first draft).
audioshortcode with chapters, speed control, mutex runtime, cover, duration, and transcript body. - 2026-11-27 (review). Native image syntax with
captionandid; transcripts composed from a folded callout; runtime features deferred. - 2026-11-27 (implementation). Implemented in the shared media partial and
assets/css/td/media.css; no runtime and no locale key. Two invalid-input cases were added tobin/check-media-primitives.py. - 2026-11-27 (review revision). Addressed deep-review findings: dedicated Print now uses visible
.td-media__link;@media printresets audio cards to paper-palette tokens in dark mode; removed.td-figurefrom audio and enforced start alignment; switched<audio>accessible naming toaria-labelledby/aria-describedby(withrender-block.htmlID rewriting); preserved query strings and#t=Media Fragments on local resources; replaced negative margins with:has()positive margins for consecutive cards and Audio+Transcript pairing; aligned Paper and Terminal frame/title styling; preserved audio URL and start alignment inrich-copy.js; addedpreloadattribute with 6-player auto-threshold (nonefrom 7th onward); added unnumbered duplicate#iddetection and accurateaudio:warning prefix; enabled single-active playback injs/chunks/media.jsonly when 2+ players exist on a page; added nested<a>guard incheck-output.py, expandedcheck-media-primitives.py, JS unit tests, andtests/browser/audio.spec.mjs. - 2026-11-27 (adversarial review fixes). Restored the 24px/28px margins that
:where(.td-media)had lost to Bootstrap’sfigure { margin: 0 0 1rem }(now:where(.td-media):not(.td-figure)), so the 8px/24px pairing holds; single-active playback now treats any muted or zero-volume player as silent and also reacts tovolumechange, so unmuting a playing loop pauses other audio and an author’s own muted loop is left alone;book/register-target.htmlchecks unnumbered media IDs, making the duplicate-ID check two-way; local fragments keep their percent-encoding (EscapedFragment);preloadwarns only in HTML; the audio card takes--td-code-radiusin every preset and Ink’s callout surface. The browser suite asserts absolute spacing and uses realplay();check_audio_matrix()covers upper-case extensions, a site-definedaudio/*media type, encoded fragments, Book-target ID clashes in both orders, and a subpathbaseURL. - 2026-11-28 (control row). The owner judged the native strip plus the theme’s separate accent strip as two progress bars and asked for one bar that tells played and loaded time apart by color, styled per preset. Firefox and Safari do not expose their native track, so
js/chunks/media.jsnow removescontrolsand draws one control row (play, time, a single seek bar, speed, mute and volume) with eightui_media_*labels in all 32 locales; the native player remains the no-JavaScript fallback. Played, buffered and unloaded time keep at least 3:1 between played and each neutral in every preset and mode.