npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

media-transcript

v2.1.0

Published

A web component for an interactive transcript built from WebVTT cues.

Downloads

62

Readme

Media Transcript

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:

Install

npm install media-transcript

Modes

There are two modes for using the <media-transcript> element. Both start by binding a <media-transcript> to your media element (<audio> or <video>) via the [media] attribute.

<audio id="my-media" src="path/to/media.mp3"></audio>
<media-transcript media="my-media"></media-transcript>

Track to transcript

If you already have captions for your media and just want to create a transcript from those captions, simply bind the media to the <media-transcript>.

When using this mode, the captions must be .vtt format. This is because <media-transcript> uses the native WebVTT and TextTrack APIs to parse the track. The .srt format does not implement these APIs.

<video id="my-video" poster="path/to/video.jpg" controls>
	<source src="/path/to/video.mp4" type="video/mp4" />
	<track
		src="path/to/video.vtt"
		kind="captions"
		label="English captions"
		srclang="en"
	/>
</video>
<media-transcript media="my-video" />

View the track-to-transcript example

Transcript to Track

If your <media-transcript> has <media-cue> 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 <audio> element TextTracks, so this mostly only makes sense for <video>.

<video id="my-video" poster="path/to/video.jpg" controls>
	<source src="/path/to/video.mp4" type="video/mp4" />
	<!-- no track necessary -->
</video>
<media-transcript
	media="my-video"
	kind="captions"
	label="English captions"
	srclang="la"
>
	<!-- cues can be nested in this mode -->
	<h2>
		<media-cue end="1">Chapter 1</media-cue>
	</h2>
	<p>
		<media-cue start="1.2" end="3"
			>Lorem ipsum dolor sit amet consectetur adipisicing elit.</media-cue
		>
		<media-cue start="3.1" end="4">Est nesciunt incidunt,</media-cue>
		<media-cue start="4" end="6.2"
			>deleniti doloremque natus ad id nam laborum amet facilis voluptatem
			odio?</media-cue
		>
		<media-cue start="6.7" end="8"
			>Incidunt rerum sunt quo eaque sapiente sit sequi.</media-cue
		>
	</p>
</media-transcript>

Usage

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 <media-transcript> and <media-cue> custom elements.

UMD

The UMD bundle includes MediaCue & MediaTranscript and will work in all browsers.

<script src="media-transcript.umd.js" defer></script>

ES Modules

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.

<script src="media-transcript.module.js" type="module"></script>

CommonJS (Node.js)

If you're working in a Node.js environment, you can just import and use the JavaScript API.

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);

API

Since <media-transcript> and <media-cue> are custom elements, there is both a JavaScript API and an HTML API (attributes).

<media-transcript> 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 <media-cue> elements | boolean (i.e., <media-transcript timestamp> or <media-transcript timestamp="timestamp"> for proper conformance) | | role | set a role to make the transcript interactive. | listbox: treat the transcript as a listbox widget, automatically enhancing the <media-cue> elements with [role="option"], managed roving focus, and proper aria-selected values.Other roles will be added | | 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 focusunset (default): all arrow keys control focus |

<media-cue> attributes

| 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 <time> element) | boolean (i.e., <media-cue timestamp> or <media-cue timestamp="timestamp"> for proper conformance) |