Word-by-word highlighting from SpeechSynthesis boundary events

Press Speak and the browser reads the paragraph aloud. Each boundary event names the word being started, and the canvas draws an effect on that word. Tap any word to start from it. If the voice sends no boundary events, the words are stepped by a timer and the line under the buttons says so.

The browser is reading this paragraph aloud. Each time it starts a word, the speech engine fires a boundary event that carries the position of that word in the text. The page turns the position into a range and asks for its rectangle, and the canvas draws the effect there. Tap any word to start from it.

Nothing has been spoken yet.

Show the code boundary event, range, rectangle, effect
  1. The markup. One drawable article in a canvas.
  2. Speak and listen for boundary. charIndex is the position of the word in the utterance text. charLength is missing from some engines.
  3. Position to rectangle. A Range over the word and getClientRects(), made relative to the article.
  4. Draw. The paragraph dimmed, the spoken part at full ink through a clip, then the effect on the current word.
  5. The magnified copy. The nine-argument drawElementImage() takes the word's rectangle as its source. A last draw with an empty clip puts the hit-test region back on the paragraph.
  6. Tap a word. caretPositionFromPoint() gives the text offset under the finger.
  7. The CSS. Including the two ::highlight() rules of the fourth effect.
  8. The whole speech file. With the timer used when no boundary events arrive.

How it works

Live checks

Each check builds its own small canvas in a corner of the window. The paragraph above isn't touched. The last check speaks three words at zero volume.

ResultExperimentDetail

Findings

From Chromium 157 headless, 2026-11-21, which has no voices. The rows above and the line under the buttons say what your browser does.