Skip to content

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

Merged
Yash-Singh1 merged 31 commits into
pingdotgg:feat/read-aloud-providersfrom
gruckion:feat/read-aloud-word-highlight
Nov 25, 2026
Merged

Yash-Singh1 merged 31 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.

  • No setting: highlighting is always on.

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

Reading controls

These controls bring back what an earlier version of this work had:

  • Click to jump: while a reply plays, a click on a paragraph (web, desktop) or a tap on it (mobile) starts reading from that paragraph. Links, buttons, code blocks, maths, double-clicks, modifier clicks and clicks with a text selection do not jump.
  • Read from here: the selection toolbar on a reply has "Read from here". It starts reading at the paragraph that holds the selection.
  • Paragraphs without a position: Words writes source positions only on list items. So the highlight and click-to-jump find a paragraph by its first and last words.

ReadAloudController.start() now takes an optional markdown offset. Speech is made only from that block onward, and the highlight offsets still match the whole reply.

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, 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.
  • The reading controls have unit tests for the start offset and the block mapping.
  • I checked click-to-jump by hand with ElevenLabs in the desktop app and on a physical iPhone.
  • After the merge of feat(read-aloud): add optional speech playback across clients #35910's head, the tarball swap and the removal of pause, Stop and the setting: vp run check:changed origin/feat/read-aloud-providers passes (format, lint, knip, typecheck of 44 packages, 447 tests in 18 files, React Compiler). Settings saved with highlightWords still decode.
  • 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
The base branch moved chat Markdown from react-markdown to Words, so the
speech offsets now tag the hast in the chat Markdown renderer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the 📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. label Nov 24, 2026
gruckion and others added 9 commits November 24, 2026 14:12
Also rebuilds the Enriched Markdown tarball so it keeps the fork's iOS
tall code block and blockquote lift fixes next to the highlight ranges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Words writes data-sourcepos only on list items, so paragraphs, headings and
table rows had no speech offsets and the highlighter found no block to paint.
Fall back to the innermost block whose text holds the block's first and last words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Packs pingdotgg/enriched-markdown#17 at edfcf852 with the fork's iOS fixes
(commit 35a9c280).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read aloud always started at the top of a reply. `start` now takes a
markdown offset and makes speech only from the first block that ends
after it, so the highlight keeps the reply's own offsets. `jump` reads
the reply being read again from a new place with the same settings, and
`readAloudSourceAtShown` maps a place in a renderer's own text back to
the markdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While a reply is read aloud, a plain click on one of its paragraphs,
headings, list items, or table rows reads from that block. Links,
controls, code blocks, math, and clicks that select text keep their
behavior. The assistant selection toolbar also offers "Read from here",
which starts reading at the selection. Words writes source positions
only on list items, so other blocks are found by matching their words
to the reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While a reply is read aloud, tapping one of its paragraphs reads from
that paragraph. The tap handler is set only while the reply is read, so
taps on other replies keep their native behavior.

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

The controller now marks a reading as started once it plays audio.
`readAloudButtonMode` uses this: a reply that plays or waits for its
next chunk can pause and offers a separate Stop; only the first speech
generation cancels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While a reply plays, its read-aloud button pauses it at the current
word, and pressing it again resumes from there. A small stop button
shows next to it while the reply plays or is paused. While the first
speech is made, the button still cancels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reply's read-aloud button pauses and resumes like on the web, and
a stop button shows next to it while the reply plays or is paused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yash-Singh1 and others added 8 commits November 25, 2026 01:06
The archive came from a personal branch on the old upstream base. It now
comes from pingdotgg/enriched-markdown t3/mobile-tarball (11817aa2):
upstream main plus one commit per carried change, with highlight ranges
squashed from software-mansion/enriched-markdown#1218. The highlight API
read aloud uses is unchanged.

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

This reverts commit 65b6be2.

# Conflicts:
#	apps/mobile/src/i18n/translations/de.json
#	apps/mobile/src/i18n/translations/en.json
#	apps/mobile/src/i18n/translations/es.json
#	apps/mobile/src/i18n/translations/fr.json
#	apps/mobile/src/i18n/translations/ja.json
#	apps/mobile/src/i18n/translations/ko.json
#	apps/mobile/src/i18n/translations/pt-BR.json
#	apps/mobile/src/i18n/translations/ru.json
#	apps/mobile/src/i18n/translations/sv.json
#	apps/mobile/src/i18n/translations/zh.json
…button"

This reverts commit e1ef1f7.

# Conflicts:
#	apps/web/src/i18n/translations/de.json
#	apps/web/src/i18n/translations/en.json
#	apps/web/src/i18n/translations/es.json
#	apps/web/src/i18n/translations/fr.json
#	apps/web/src/i18n/translations/ja.json
#	apps/web/src/i18n/translations/ko.json
#	apps/web/src/i18n/translations/pt-BR.json
#	apps/web/src/i18n/translations/ru.json
#	apps/web/src/i18n/translations/sv.json
#	apps/web/src/i18n/translations/zh.json
ReadAloudMarkdownText subscribes to the controller and asks whether its
reply is being read, which the mock did not provide, so nine preview
tests failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Highlighting is how read aloud shows its place, so it is always on. The
Highlight words setting, its saved field and its strings are removed;
settings saved with the field still decode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yash-Singh1
Yash-Singh1 merged commit 6024593 into pingdotgg:feat/read-aloud-providers Nov 25, 2026
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. 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.

2 participants