Skip to content

Stabilize TTS playback state transitions and harden Media Session handling#2

Merged
hansai-art merged 29 commits into
mainfrom
copilot/research-competitors-advantage
Apr 11, 2026
Merged

Stabilize TTS playback state transitions and harden Media Session handling#2
hansai-art merged 29 commits into
mainfrom
copilot/research-competitors-advantage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

This change tightens the playback path where voice changes, restarts, and browser media controls could drift out of sync with current state. It also removes the remaining hook dependency issues that were masking those edge cases.

  • TTS state synchronization

    • Memoizes derived paragraph data in useTTS so callback dependencies stop churning on each render.
    • Moves active playback position and selected voice reads behind refs to avoid stale closures during replay, engine switches, and voice changes.
    • Routes voice-change replay through a stable function ref instead of depending on a callback recreated from stateful closures.
  • Playback restart semantics

    • Extracts the short post-stop replay delay into a named constant.
    • Documents why replay waits briefly before re-speaking with the new voice.
  • Browser integration hardening

    • Guards navigator.mediaSession.setActionHandler(...) registration and cleanup so unsupported or partial browser implementations fail safely.
    • Adds explicit warning logs for registration/cleanup failures instead of silently swallowing them.
  • Hook correctness on input flow

    • Adds the missing translation dependency in AddArticlePage so clipboard/import side effects stay aligned with the active language function.

Example of the state-stable replay path:

const speakSentenceRef = useRef<(pIdx: number, sIdx: number) => void>(() => {});

useEffect(() => {
  speakSentenceRef.current = speakSentence;
}, [speakSentence]);

setTimeout(() => {
  if (playingRef.current) {
    speakSentenceRef.current(currentParagraphIndex, currentSentenceIndex);
  }
}, VOICE_CHANGE_DELAY_MS);

Copilot AI and others added 29 commits April 10, 2026 19:39
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/49b00265-8844-4adf-ae98-38dd97408ba1

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/49b00265-8844-4adf-ae98-38dd97408ba1

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/49b00265-8844-4adf-ae98-38dd97408ba1

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/65032962-304c-4be0-b9b5-2e1b103d4e6c

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/f2bc025c-dc76-45be-a91b-404ee5f37a5b

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/074af2d7-d310-4ac6-a809-5228b278432c

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/074af2d7-d310-4ac6-a809-5228b278432c

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/c6121c02-dd55-4b3a-af87-2b0eb0de9cd3

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/d9fef9be-22bf-4adb-8fe2-af52aee494ef

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/d9fef9be-22bf-4adb-8fe2-af52aee494ef

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/f885334d-5a4c-4def-bf72-63025bbc18ce

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/000ea9f5-99a8-46c7-be9f-0c5b6a0e5aff

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/000ea9f5-99a8-46c7-be9f-0c5b6a0e5aff

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/000ea9f5-99a8-46c7-be9f-0c5b6a0e5aff

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/bdf39230-a5bf-4328-87ef-3d626bbdc3a9

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/bdf39230-a5bf-4328-87ef-3d626bbdc3a9

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/51656337-4778-4d75-be77-fe6fdd64d38f

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hansai-art/article-voice-reader/sessions/51656337-4778-4d75-be77-fe6fdd64d38f

Co-authored-by: hansai-art <132933660+hansai-art@users.noreply.github.com>
Copilot AI self-assigned this Apr 11, 2026
@hansai-art hansai-art marked this pull request as ready for review April 11, 2026 16:03
@hansai-art hansai-art merged commit bdc3b64 into main Apr 11, 2026
1 check passed
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