Transcript
What a recording says, as cues that follow it as it plays.
On this page
A transcript is what a recording says, as a list of cues, each with the time it begins. It follows the recording as it plays: the cue being spoken is strong on a raised sheet, the cues already heard turn quiet and the ones still to come wait in the body's ink. Choose a cue and the recording plays from there. The transcript behavior connects it to a player or to a plain <audio> or <video>, named by its id in aria-controls.
Transcript
<div class="grid gap-sm max-w(480) mx-auto"> <div class="player" id="talk" role="group" aria-label="A short recording"> <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio> <div class="player-controls"> <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false"> <svg class="icon player-off" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M7.633 4.7883L14.865 8.9606A1.2 1.2 0 0 1 14.865 11.0394L7.633 15.2117A1.2 1.2 0 0 1 5.8333 14.1723L5.8333 5.8277A1.2 1.2 0 0 1 7.633 4.7883Z" /> </svg> <svg class="icon player-on" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <rect x="5" y="3.75" width="3.3333" height="12.5" rx="0.8" /><rect x="11.6667" y="3.75" width="3.3333" height="12.5" rx="0.8" /> </svg> </button> <span class="player-elapsed">0:00</span> <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek"> <span class="player-duration">0:00</span> </div> </div> <section class="transcript" aria-label="Transcript" aria-controls="talk" style="--transcript-height: 12rem"> <ol class="transcript-list scroll-area"> <li class="transcript-cue" data-start="0.3"> <button type="button" class="transcript-time">0:00</button> <p class="transcript-text"> This is a short recording, made to show the player and its transcript. </p> </li> <li class="transcript-cue" data-start="4.7"> <button type="button" class="transcript-time">0:04</button> <p class="transcript-text"> Each line of the transcript is a cue, with the time it begins. </p> </li> <li class="transcript-cue" data-start="8.7"> <button type="button" class="transcript-time">0:08</button> <p class="transcript-text"> The line being spoken is marked, and the transcript keeps it in view. </p> </li> <li class="transcript-cue" data-start="13.06"> <button type="button" class="transcript-time">0:13</button> <p class="transcript-text"> Lines you have heard turn quiet. The ones still to come wait in plain ink. </p> </li> <li class="transcript-cue" data-start="17.65"> <button type="button" class="transcript-time">0:17</button> <p class="transcript-text"> Choose any line to jump to it, or scroll away and come back later. </p> </li> <li class="transcript-cue" data-start="21.79"> <button type="button" class="transcript-time">0:21</button> <p class="transcript-text">That is the whole recording. Thank you for listening.</p> </li> </ol> <button type="button" class="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import PlayIcon from '@master/icons-react/native/20/soft/play'import PauseIcon from '@master/icons-react/native/20/soft/pause'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="grid gap-sm max-w(480) mx-auto"> <div className="player" id="talk" role="group" aria-label="A short recording"> <audio className="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio> <div className="player-controls"> <button type="button" className="player-button player-play" aria-label="Play" aria-pressed="false"> <PlayIcon className="icon player-off" /> <PauseIcon className="icon player-on" /> </button> <span className="player-elapsed">0:00</span> <input type="range" className="slider player-seek" min="0" max="0" step="any" defaultValue="0" aria-label="Seek" /> <span className="player-duration">0:00</span> </div> </div> <section className="transcript" aria-label="Transcript" aria-controls="talk" style={{ '--transcript-height': '12rem' } as React.CSSProperties}> <ol className="transcript-list scroll-area"> <li className="transcript-cue" data-start="0.3"> <button type="button" className="transcript-time">0:00</button> <p className="transcript-text"> This is a short recording, made to show the player and its transcript. </p> </li> <li className="transcript-cue" data-start="4.7"> <button type="button" className="transcript-time">0:04</button> <p className="transcript-text"> Each line of the transcript is a cue, with the time it begins. </p> </li> <li className="transcript-cue" data-start="8.7"> <button type="button" className="transcript-time">0:08</button> <p className="transcript-text"> The line being spoken is marked, and the transcript keeps it in view. </p> </li> <li className="transcript-cue" data-start="13.06"> <button type="button" className="transcript-time">0:13</button> <p className="transcript-text"> Lines you have heard turn quiet. The ones still to come wait in plain ink. </p> </li> <li className="transcript-cue" data-start="17.65"> <button type="button" className="transcript-time">0:17</button> <p className="transcript-text"> Choose any line to jump to it, or scroll away and come back later. </p> </li> <li className="transcript-cue" data-start="21.79"> <button type="button" className="transcript-time">0:21</button> <p className="transcript-text">That is the whole recording. Thank you for listening.</p> </li> </ol> <button type="button" className="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section> </div> )}<script> import { attach } from '@master/ui/behaviors' import PlayIcon from '@master/icons-svelte/native/20/soft/play' import PauseIcon from '@master/icons-svelte/native/20/soft/pause'</script><div class="grid gap-sm max-w(480) mx-auto" {@attach attach}> <div class="player" id="talk" role="group" aria-label="A short recording"> <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio> <div class="player-controls"> <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false"> <PlayIcon class="icon player-off" /> <PauseIcon class="icon player-on" /> </button> <span class="player-elapsed">0:00</span> <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek"> <span class="player-duration">0:00</span> </div> </div> <section class="transcript" aria-label="Transcript" aria-controls="talk" style="--transcript-height: 12rem"> <ol class="transcript-list scroll-area"> <li class="transcript-cue" data-start="0.3"> <button type="button" class="transcript-time">0:00</button> <p class="transcript-text"> This is a short recording, made to show the player and its transcript. </p> </li> <li class="transcript-cue" data-start="4.7"> <button type="button" class="transcript-time">0:04</button> <p class="transcript-text"> Each line of the transcript is a cue, with the time it begins. </p> </li> <li class="transcript-cue" data-start="8.7"> <button type="button" class="transcript-time">0:08</button> <p class="transcript-text"> The line being spoken is marked, and the transcript keeps it in view. </p> </li> <li class="transcript-cue" data-start="13.06"> <button type="button" class="transcript-time">0:13</button> <p class="transcript-text"> Lines you have heard turn quiet. The ones still to come wait in plain ink. </p> </li> <li class="transcript-cue" data-start="17.65"> <button type="button" class="transcript-time">0:17</button> <p class="transcript-text"> Choose any line to jump to it, or scroll away and come back later. </p> </li> <li class="transcript-cue" data-start="21.79"> <button type="button" class="transcript-time">0:21</button> <p class="transcript-text">That is the whole recording. Thank you for listening.</p> </li> </ol> <button type="button" class="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import PlayIcon from '@master/icons-vue/native/20/soft/play'import PauseIcon from '@master/icons-vue/native/20/soft/pause'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="grid gap-sm max-w(480) mx-auto"> <div class="player" id="talk" role="group" aria-label="A short recording"> <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio> <div class="player-controls"> <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false"> <PlayIcon class="icon player-off" /> <PauseIcon class="icon player-on" /> </button> <span class="player-elapsed">0:00</span> <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek"> <span class="player-duration">0:00</span> </div> </div> <section class="transcript" aria-label="Transcript" aria-controls="talk" style="--transcript-height: 12rem"> <ol class="transcript-list scroll-area"> <li class="transcript-cue" data-start="0.3"> <button type="button" class="transcript-time">0:00</button> <p class="transcript-text"> This is a short recording, made to show the player and its transcript. </p> </li> <li class="transcript-cue" data-start="4.7"> <button type="button" class="transcript-time">0:04</button> <p class="transcript-text"> Each line of the transcript is a cue, with the time it begins. </p> </li> <li class="transcript-cue" data-start="8.7"> <button type="button" class="transcript-time">0:08</button> <p class="transcript-text"> The line being spoken is marked, and the transcript keeps it in view. </p> </li> <li class="transcript-cue" data-start="13.06"> <button type="button" class="transcript-time">0:13</button> <p class="transcript-text"> Lines you have heard turn quiet. The ones still to come wait in plain ink. </p> </li> <li class="transcript-cue" data-start="17.65"> <button type="button" class="transcript-time">0:17</button> <p class="transcript-text"> Choose any line to jump to it, or scroll away and come back later. </p> </li> <li class="transcript-cue" data-start="21.79"> <button type="button" class="transcript-time">0:21</button> <p class="transcript-text">That is the whole recording. Thank you for listening.</p> </li> </ol> <button type="button" class="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section> </div></template>#Following and scrolling away
As the recording plays, the behavior marks the current cue with aria-current="true": the last cue whose data-start has passed, so the place is kept through a pause between two cues. Every cue before it is drawn as played, by the stylesheet alone.
The list keeps the current cue in its middle. It scrolls itself and nothing around it, so a page with a transcript on it never moves under the reader; it glides, or jumps for a reader who asks for reduced motion. When the reader scrolls the list with the wheel, a finger, the keys or the scrollbar and the current cue leaves the view, the list stops following, and transcript-return, a small pill at its lower edge, brings it back. Choosing a cue, or scrolling the current cue back into view, follows again.
The list scrolls inside --transcript-height, 20rem unless set. Add scroll-area to the list for its thin scrollbar and the fades at the edges where it goes on.
#From a WebVTT track
When the list is empty, the behavior writes the cues from the media's first captions or subtitles track, read through the TextTrack API: the time, the words without their tags, and the speaker a voice tag names (<v Ana>). A track loads its cues only once it is not disabled, so the behavior sets a disabled track to hidden, which shows nothing over a picture. Here the transcript follows a plain <audio> with the browser's controls.
From a track
<div class="grid gap-sm max-w(480) mx-auto"> <audio id="talk-audio" class="w-full" src="/demo/recording.m4a" controls preload="metadata"> <track kind="captions" src="/demo/recording.vtt" srclang="en" label="English"> </audio> <section class="transcript" aria-label="Transcript" aria-controls="talk-audio" style="--transcript-height: 15rem"> <ol class="transcript-list scroll-area"></ol> <button type="button" class="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="grid gap-sm max-w(480) mx-auto"> <audio id="talk-audio" className="w-full" src="/demo/recording.m4a" controls preload="metadata"> <track kind="captions" src="/demo/recording.vtt" srcLang="en" label="English" /> </audio> <section className="transcript" aria-label="Transcript" aria-controls="talk-audio" style={{ '--transcript-height': '15rem' } as React.CSSProperties}> <ol className="transcript-list scroll-area"></ol> <button type="button" className="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section> </div> )}<script> import { attach } from '@master/ui/behaviors'</script><div class="grid gap-sm max-w(480) mx-auto" {@attach attach}> <audio id="talk-audio" class="w-full" src="/demo/recording.m4a" controls preload="metadata"> <track kind="captions" src="/demo/recording.vtt" srclang="en" label="English"> </audio> <section class="transcript" aria-label="Transcript" aria-controls="talk-audio" style="--transcript-height: 15rem"> <ol class="transcript-list scroll-area"></ol> <button type="button" class="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="grid gap-sm max-w(480) mx-auto"> <audio id="talk-audio" class="w-full" src="/demo/recording.m4a" controls preload="metadata"> <track kind="captions" src="/demo/recording.vtt" srclang="en" label="English"> </audio> <section class="transcript" aria-label="Transcript" aria-controls="talk-audio" style="--transcript-height: 15rem"> <ol class="transcript-list scroll-area"></ol> <button type="button" class="btn btn-sm btn-pill transcript-return" hidden> Back to current </button> </section> </div></template>#The behavior
transcript takes the root, the element with the transcript class, and returns the function that detaches it.
import { transcript } from '@master/ui/behaviors/transcript.js'const detach = transcript(document.querySelector('.transcript'))- The media is the one
aria-controlsnames: a player, whoseplayer-mediait takes, or an<audio>or<video>. The behavior looks each time the media speaks, so a media written after the transcript, or another one named later, is followed. Themediaoption names an element instead. - A cue is an
liwithdata-start, the second it begins, holding atranscript-timebutton and atranscript-text. A press anywhere on a cue plays from its start, unless the reader is selecting its words; Enter on its time does the same. - Rows written elsewhere. The behavior reads the list each time and keeps none of it, so a renderer may write the cues and change them.
draw: falseleaves an empty list to the renderer;trackchooses the track the cues are written from. The rows it wrote are removed when it detaches.
| Option | Default | |
|---|---|---|
media | from aria-controls | The media element to follow |
track | the first captions or subtitles track | The track an empty list is written from |
draw | true | Whether to write an empty list from the track |
Without the behavior the cues are a list a reader reads; nothing is marked, nothing follows, and a cue does not seek.
#Keyboard
The times are one tab stop, the current cue's, and the arrows move between them, so a long transcript is not a long walk through the tab order.
| Keys | Action |
|---|---|
| Tab | Enter the list at the time of the current cue, or of the first, and leave it again: the list is one tab stop |
| ArrowDown, ArrowUp | Move to the time of the next or the previous cue |
| Home, End | Move to the time of the first or the last cue |
| Enter, Space | Play from the focused cue's time, as the native button does |
#Accessibility
- Name the transcript with
aria-labelor a heading it points to witharia-labelledby, and name its media inaria-controls. - The current cue is
aria-current="true"; the stylesheet draws it in ink and depth, not in a hue, and in forced colors with a system outline. - The transcript never takes focus by itself as the recording plays. Focus moves only when the reader moves it, and back to the current cue when the way back is chosen.
- A transcript is what a recording without a picture needs to be understood without sound. Write it in the page when the page has to be read without script.
#React, Svelte and Vue
The transcript component writes the cues from cues, each a start, its text and an optional speaker, names the media given as media, and attaches the behavior, which marks and follows them. Copy it into the project with npx master-ui add transcript; React, Svelte and Vue says how the components are built and used.
#Classes
| Class | Description |
|---|---|
transcript | The transcript, beside its media. Give it an aria-label and aria-controls with the id of the player or the media element it follows |
transcript-list | The cues, on an ol, scrolling inside --transcript-height. Add scroll-area to fade its edges |
transcript-cue | One cue, an li with data-start, the second it begins: its time, then its words. Quiet once played, strong on a raised sheet while current. A press anywhere on it plays from its time |
transcript-time | When the cue begins, in small tabular figures, on a button that plays from there. The list's tab stop |
transcript-text | The words of the cue |
transcript-speaker | Who speaks, over the words, when the recording has several voices |
transcript-return | Back to the current cue: a small pill button at the list's lower edge, hidden until the reader scrolls the current cue out of view |
The way back is a button, btn btn-sm btn-pill, with the transcript-return part.
#Custom properties
| Property | Default | Description |
|---|---|---|
--transcript-height | 20rem | The tallest the list grows before it scrollsSet on transcript |
#Related
- PlayerControls of the page's own over a native audio or video element.
- Scroll areaA scrolling region whose edges fade where content continues.
- TimelineEvents in the order they happened.