A conference editor asked how to keep a timestamped transcript beside a recording and show the right words during playback. If you already have timed captions, you can do this in a browser while leaving the video file untouched. The example below uses a fictional three-cue interview. You can use any video at least 12 seconds long to check the timings. The sample dialogue will only match the audio if you supply a matching recording.

Connect the caption file

Download interview-sample.json from the sources below. Put it beside your player page on the same web server. Add a video element with controls and a working media source. In a module script after that element, run the following three statements in order.

const video = document.querySelector('video'); const response = await fetch('./interview-sample.json'); if (!response.ok) throw new Error('Caption download failed: ' + response.status); const rows = await response.json();

const track = video.addTextTrack('captions', 'Interview captions', 'en'); track.mode = 'showing';

for (const row of rows) { const words = row.text.replaceAll('&', '&amp;').replaceAll('<', '&lt;'); track.addCue(new VTTCue(row.startMs / 1000, row.endMs / 1000, words)); }

The file stores milliseconds. VTTCue takes seconds. For example, 1125 becomes 1.125. Passing 1125 directly schedules the first line more than 18 minutes into the video. The two replacements keep literal characters such as < visible as dialogue when the browser parses cue text.

Check three positions before shipping

Seek to 2 seconds. You should see the host ask which shot opens the sequence. Seek to 4.6 seconds and the caption area should clear. That quarter-second gap is present in the file. At 5 seconds you should see both Mei’s reply and the host’s follow-up. They share a single cue with a line break. To reveal those lines separately, time the change from the recording and split the cue there.

If playback drifts after an edit

Compare the first and last spoken lines with the media you actually serve. A constant offset suggests the captions and video start at different points. If they agree near the beginning and diverge after a cut, inspect the first line after that cut before shifting the whole transcript. An untimed transcript needs timing first. This player displays the intervals you supply.