Live captions from SpeechRecognition, with the Translator API for a second language
Speech is turned into a caption element that the canvas draws over the video, with a translation under the frame. Press Play. The page starts with a recorded transcript of the clip, which works in every browser. Then choose speech recognition on the clip's sound or on the microphone, and a second language.
The video hasn't been played yet.
No speech recognition events yet.
Show the code recognition, translation, a caption element, a recording
- The markup. The video, a control bar and the caption element are children of the canvas.
- Recognise speech.
continuousandinterimResultsgive words as they are heard.start(track)recognises a sound track in place of the microphone. - The clip's own sound.
video.captureStream()has an audio track for the element's sound. - Words into elements. One
<span>per word. Only the words that changed are replaced. - Translate.
Translator.create()for the language pair, thentranslate()for each result. Interim results are translated one at a time and overtaken ones are dropped. - Draw. The caption element is drawn twice with a clip: its first line over the bottom of the frame, its second line under the control bar.
- WebVTT out. Each final result has a start and an end time, which is all a cue needs.
- The recorded transcript. The cue file of the clip, fed in word by word at each word's time stamp.
- The CSS.
How it works
- Every source of words calls one function,
feed({ text, final }). An interim result replaces the words on screen. A final result ends the caption and is stored with its start and end time. - With "speech recognition on the clip's sound", the page takes the audio track of
video.captureStream()and passes it torecognition.start(track). No microphone is opened. This needs a browser whoseSpeechRecognitionaccepts a track, which the page tests for by looking forprocessLocally, added in the same release. - The translation comes from
Translatorwhen the browser has it for the language pair. A model that isn't on the device yet is downloaded after the tap on the language menu. WhenTranslatorcan't be used, the page shows recorded translations of the clip's six sentences and says so under the player. - The caption element is ordinary HTML in the canvas, so the words are in
canvas.captureStream(). Record writes the canvas and the clip's sound to a file withMediaRecorder. - The recognition events are listed under the player, because a phone has no console.
Live checks
Each check builds its own small video and canvas in a corner of the window. The player above isn't touched. No check opens the microphone or starts a download.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157 headless, 2026-11-21. The rows above and the two status blocks under the player say what your browser does.
- Works: captions as elements in the picture. Words fed in as interim and final results are drawn over the frame, and the translation under it. Both are in a
MediaRecorderfile of the canvas. - Found: an element drawn twice has one hit-test box, at its last draw. The caption element's box under the bar reached up over the Play button, and taps on the button went to the caption (reported from a phone, 2026-11-21). The bar is now drawn after the captions, because the element drawn last is on top for taps.
- Works: only revised words change. When an interim result differs from the last one, the words that stayed the same keep their elements, so only new and revised words animate.
- Works: WebVTT from results. The file made from the final results loads back into a
<track>with the same number of cues. - Not run here: recognition. Headless Chromium 157 has
SpeechRecognitionwithprocessLocally,phrases,available()andinstall(), but no recognition service. The eighth check records whatstart(track)did. - Not run here: translation.
Translator.availability()didn't settle in headless Chromium 157 and no model can be downloaded in the test container. The page falls back to the recorded translations there. - Not verified: whether Chrome 159 on Android accepts
start(track)with a track fromvideo.captureStream(), whether it needsprocessLocallyfor that, how late interim results are against the sound, and the speed ofTranslatoron a phone. The line under the player shows the time of the last translation. - The recorded Spanish, French, German and Japanese were written by a language model for this page and haven't been checked by a speaker.