A web component for an interactive transcript built from WebVTT cues.
> Create interactive transcripts for media elements
A dependency-free web component (custom element + shadow DOM) for creating interactive transcripts via the WebVTT API.
Operates in two modes:
- Track to transcript: parse an existing element to generate a transcript automatically.
- Transcript to track: parse an existing transcript to create a synthetic TextTrack for your media.
``sh`
npm install media-transcript
There are two modes for using the element.
Both start by binding a to your media element (
`html`
If you already have captions for your media and just want to create a transcript from those captions,
simply bind the media to the .
When using this mode, the captions must be .vtt format.
This is because uses the native WebVTT and TextTrack APIs to parse the track..srt
The format does not implement these APIs.
`html`
View the track-to-transcript example
If your has elements already set in the HTML, binding it to media will cause that media to display the transcript as captions.
Note that user agents do not provide an interface for
`html`
kind="captions"
label="English captions"
srclang="la"
>
odio? >
Start by adding the custom elements to your page.
Various builds are available to accomplish this, provided by microbundle.
All bundles ship with both the and custom elements.
The UMD bundle includes MediaCue & MediaTranscript and will work in all browsers.
`html`
If you're using a browser that supports ES modules, you can load the custom elements as modules.
This can also be done via the bundle or as independent modules.
`html`
If you're working in a Node.js environment, you can just import and use the JavaScript API.
`javascript
import { MediaCue, MediaTranscript } from "media-transcript";
const transcript = new MediaTranscript({
/ transcript options /
});
const cue = new MediaCue({
/ cue options /
});
transcript.appendChild(cue);
document.body.appendChild(transcript);
`
Since and are custom elements,
there is both a JavaScript API and an HTML API (attributes).
| Attribute | Description | Values |
| --------- | ----------- | ------ |
| media | an id reference (IDREF) that corresponds to the media element's id | Any valid string |timestamp
| | enable timestamps for all child elements | boolean (i.e., or for proper conformance) |role
| | set a role to make the transcript interactive. | listbox: treat the transcript as a listbox widget, automatically enhancing the elements with [role="option"], managed roving focus, and proper aria-selected values.aria-orientation
| | Change keyboard behavior when an interactive mode is enabled | vertical: only up/down arrow keys control focushorizontal: only left/right arrow keys control focus
| Attribute | Description | Values |
| --------- | ----------- | ------ |
| start | the cue's start time | decimal number string. Assumed to be 0 when omitted. |end
| | the cue's end time | decimal number string. |timestamp
| | enable the cue's built-in timestamp (set as a