Skip to main content

/ Treasa Ní Chonchúir

Highlighting words as media plays

I wanted to see how hard it would be to use a combination of WebVTT, Intl.Segmenter, and the Custom Highlight API to make an audio transcript that highlights the current word you’re on without explicitly marking up the words. Look, Ma, no <span>s!

Well, it turns out to be doable, but kind of a pain, mostly because Intl.Segmenter wasn’t designed to be used with the DOM.

Here’s a recording of me reading the example transcript. Try playing it. (You may need to reload this page before it’ll work for inscrutable service worker reasons I should really try to figure out at some point.)

This demo requires the Custom Highlight API and Intl.Segmenter to be implemented. If your browser doesn’t have those things, maybe try this demo in a recent STP?

Example: a transcript of the <audio> element on this page

this is the title of the article.

hello, world

this is a test of the emergency broadcast system.

This isn’t a real thing, it’s just a test.

私はオコーナーです。元気ですか?

How it works

This is implemented in words.js, which defines two functions:

Here’s how this page calls them:

Observations