Skip to content

feat(read-aloud): highlight the paragraph and word being read - #39836

Open
gruckion wants to merge 13 commits into
pingdotgg:feat/read-aloud-providersfrom
gruckion:feat/read-aloud-word-highlight
Open

gruckion wants to merge 13 commits into
pingdotgg:feat/read-aloud-providersfrom
gruckion:feat/read-aloud-word-highlight

Conversation

@gruckion

@gruckion gruckion commented Nov 20, 2026 •

Copy link
Copy Markdown

Problem

When read aloud plays a long reply, the user cannot see which part is being read. If the user scrolls or looks away, the place is lost.

Change

This PR is stacked on #35910. Its base is feat/read-aloud-providers, so the diff shows only this work. While read aloud plays, the app tints the current paragraph and the current word. It also scrolls to follow them. This works on web, desktop and mobile.

  • Timing source: each provider in the catalog has an optional wordTimings:

    • provider: timestamps from the provider's API. ElevenLabs now uses /stream/with-timestamps.
    • boundary: boundary events from system voices.
    • estimated: an estimate from the text length and the audio duration.

    Clients do not branch on provider names.

  • Server: SynthesisBackend gets an optional alignedAudio path. Words in later 1000-character pieces are shifted by text position and by audio time. The audio time comes from the MP3 frame headers. The timings go on a separate endpoint, POST /api/voice/synthesis/timings, with the same token. The MP3 stream does not change.

  • Shared: readAloudSpeech maps the spoken text back to markdown offsets. readAloudText keeps its output.

  • Client runtime: words follow the media clock. The highlight has its own subscription, so only the message that is read re-renders.

  • Web: the CSS Custom Highlight API with light and dark tokens. Follow-scroll stops when the user scrolls away, and starts again when the word is back in view.

  • Mobile: the app gives ranges to EnrichedMarkdownText.

  • Setting: "Highlight words" is on by default, with strings in all locales.

This PR does not change the local-model stack, OpenRouter or xAI.

Scope

This is a feature on top of #35910, not a bug fix. No maintainer asked for it, so I understand it can be closed. It depends on #35910, so I made it a follow-up and did not add it to that PR.

Verification

  • Format, lint, knip, typecheck (38 packages) and i18n:check pass.
  • New tests: the shared offset map and rendered-text matching, server timing shifts across pieces, client-runtime word following, a web browser test, and mobile follow-scroll.
  • I checked the alignment against the real ElevenLabs API. In one sample, the MP3 is 5.93 s and the last word ends at 5.90 s.
  • Manual checks:
    • Web in Chromium, with ElevenLabs, in light and dark mode.
    • Mobile on an iPhone 17 Pro Max simulator (iOS 26.5): the paragraph and word tints, follow-scroll, the pause after a drag, the setting turned off, and selection and Copy while reading.
    • Android on a Pixel 8 emulator (Android 15): the tints and follow-scroll in light mode.
  • Not checked: Android dark mode and the drag pause on Android, the Electron window, and physical devices.
  • ChatMarkdown.permissions.browser.test.tsx has 2 failing tests (Shift+F10 menu). They fail the same way on feat(read-aloud): add optional speech playback across clients #35910's head without this PR.

Demo video (desktop and iOS, ElevenLabs):

t3code-read-aloud-highlight-narrated.mp4

Model and harness: Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

gruckion and others added 13 commits November 20, 2026 12:20
readAloudSpeech returns the spoken text with the markdown offset of each
character and the spoken and source range of each block, so a client can
find the word being read in the rendered message. readAloudText and
splitReadAloudText keep their behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The synthesis catalog says where a provider's word timings come from,
a new endpoint reads the timings of a started synthesis by its token,
and a highlightWords setting turns follow-along highlighting off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ElevenLabs now streams from its with-timestamps endpoint. Its character
alignment becomes words, moved to each piece's place in the request text
and to where that piece's audio starts, counted from MP3 frame headers.
Synthesis jobs keep the words and the audio length, and
/api/voice/synthesis/timings long-polls them by the stream token. The MP3
stream is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The read-aloud controller keeps the speech's map back to the markdown and
publishes the current block and word, as markdown ranges plus text cues,
on a separate subscription so only the message being read re-renders.

Playbacks report words. Environment audio uses createTimedWords, which
follows the environment's word timings on the media clock with one timer
per word, and estimates them from the audio length when the provider has
none. System voices use boundary events on web and mobile.
startSpeechSynthesis also returns the stream token for the timings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rendered block elements carry their markdown range. While a reply is read,
the block and word are found in that element's text and painted with the
CSS Custom Highlight API, so the DOM and copied text stay unchanged. The
colours are theme tokens for light and dark. The timeline scrolls to keep
the word in view until the user scrolls away, and follows again once the
word is back in view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Highlight words sits in Settings → Voice → Read aloud on web and mobile,
on by default, with every locale translated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… view

useReadAloudHighlight returns the block and word being read in a
message. The native view cannot draw ranges yet, so the assistant
message marks where to pass it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A real browser renders a reply and checks that the block range survives
the markdown pipeline, that the repeated word painted is the one being
read, and that stopping clears both highlights.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fork adds highlights, onRenderedTextChange and onHighlightLayout so
read aloud can tint the paragraph and word it reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Native markdown views report the text they show, not where it came from
in the markdown. readAloudShownText matches the reply's spoken words to
the shown words in order and returns the paragraph and word ranges to
tint. A word without a safe match is left unhighlighted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replies pass the native markdown view the paragraph and word being read
as ranges of the text it shows, tinted with the web's light and dark
read-aloud colours. Code blocks and tables are tinted whole. The feed
keeps the word in view, pausing after the user scrolls until they bring
it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s from

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Nov 20, 2026
@gruckion

Copy link
Copy Markdown
Author

@Yash-Singh1 nice work with the TTS PR. I had my own version with an additional highlight the paragraphs and follow along with each word as it reads aloud. So I've made a PR for it here. Let me know if you have any questions.

@github-actions

Copy link
Copy Markdown
Contributor

This PR conflicts with feat/read-aloud-providers. Rebase it or merge feat/read-aloud-providers into it. If it still conflicts after 7 days with no activity, it will be closed automatically.

See the conflict window.

@github-actions github-actions Bot added the needs-rebase Conflicts with its base branch. Closes after 7 days with no activity. label Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Conflicts with its base branch. Closes after 7 days with no activity. size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant