Skip to content

Add real-time speaking highlight for sentence analysis#6

Open
yjpark wants to merge 1 commit intomainfrom
claude/animate-token-highlight-7Cy2u
Open

Add real-time speaking highlight for sentence analysis#6
yjpark wants to merge 1 commit intomainfrom
claude/animate-token-highlight-7Cy2u

Conversation

@yjpark
Copy link
Copy Markdown
Contributor

@yjpark yjpark commented Feb 10, 2026

Summary

This PR adds visual feedback that highlights which token is currently being spoken when using the text-to-speech feature in the sentence analysis panel. As the speech synthesis engine processes the sentence, the corresponding token is highlighted with an animated glow effect in both the token flow view and the token details table.

Key Changes

  • Speech tracking with Web Speech API boundary events: Implemented speak_with_tracking() function that uses the onboundary event to track character positions during speech synthesis and dispatch custom events to the Rust component.

  • Character-to-token mapping: Added char_index_to_token() and build_char_offset_ranges() functions to accurately map character indices from the Web Speech API to token indices, accounting for multi-byte UTF-8 characters in Japanese text.

  • Real-time state updates: Integrated a polling mechanism that listens for boundary events and updates the speaking_token_idx signal to track which token is currently being spoken.

  • Visual highlighting animations: Added three new CSS animations:

    • speaking-glow: Pulsing glow effect for token chips with color shift and scale transform
    • speaking-row-flash: Subtle background flash for table rows
    • btn-pulse: Pulse animation for the active speak button
  • Dynamic class binding: Updated both token chip and table row rendering to conditionally apply the speaking class based on the current speaking token index.

  • Enhanced speak button: Replaced the simple SpeakButton component call with a custom button that uses speak_with_tracking() and shows active state during speech.

Implementation Details

  • Character offsets use character counts (not byte counts) to align with Web Speech API behavior
  • Boundary events are captured via a custom kumou-boundary event dispatched from JavaScript
  • Polling interval is set to 50ms for responsive highlighting without excessive overhead
  • The implementation gracefully handles edge cases like tokens not found or speech ending

https://claude.ai/code/session_018ANiNAw1R6prwWozJwmxxh

Use Web Speech API boundary events to track speaking progress and
highlight the current token with a glowing pulse animation in both
the token flow chips and the detail table.

https://claude.ai/code/session_018ANiNAw1R6prwWozJwmxxh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants