Repository navigation
feat(reader): TTS prosody v2a Phase C — Android Markdown narration segments - #647
Conversation
…erload Kotlin counterpart of iOS's NarrationSegment (#634/#640), kept in sync in shape. TtsEngine gets a default speak(segments) that flattens to plain text and calls speak(text) — engines that aren't taught to render segments yet (Pocket/Cloud) get this for free. Part of #636 (TTS v2a Phase C: Android Markdown narration segments).
Adds extractNarrationSegments alongside (not replacing) stripMarkdownSyntax, reusing the same regexes to classify bold/italic (Emphasis), block quotes (Quote), headings (Heading), list items (Sentence pause), paragraph breaks (Paragraph pause), and thematic breaks (SceneBreak pause on the segment that follows) instead of discarding the classification. Also fixes ReaderViewModelTest's `speak(any())` mockk calls, which became ambiguous now that TtsEngine.speak is overloaded — pinned to any<String>(). Part of #636.
… chain New speak(segments) override splices TextToSpeech.playSilentUtterance in ahead of each segment per its pauseBefore hint, interleaved with the segment's own (possibly split) text chunks. This required generalizing the internal playback model from "one utterance chunk at a time" to a List<PlaybackItem> (Speech | Silence) queue that's enqueued upfront via QUEUE_ADD and replayed from the current index on resume/rate-change, replacing the old QUEUE_FLUSH + manual onDone-driven chaining — a single silence item has no "next chunk" to chain from other than the queue itself, so the old one-at-a-time model doesn't generalize. speak(text) now funnels through the same PlaybackItem queue (as all-Speech, no silences), so pause/resume/stop/setSpeechRate only need to reason about one shape. Part of #636.
…d-markdown-segments
QA verification — PR #647 vs issue #636Acceptance criteria (issue #636 "What's needed")
Explicitly-out-of-scope items (Android EPUB #637, iOS #634/635, Pocket rendering #638) are untouched — confirmed via the diff (only Test suite run (real, foreground, this checkout)
Test quality (checking these exercise real code, not a mock past the broken part)
Gap found — missing coverage (AGENTS.md violation)
Not a blocker I'm raising: AGENTS.md conventions
VerdictOne concrete, cheap-to-fix gap (a missing pure-JVM unit test for QA verdict: FAIL |
| QA failed its first round — routing back to the dev agent for one automated retry. |
QA follow-up on PR #647 (issue #636): the pure-JVM fallback flattening path TtsEngine.speak(segments)'s default implementation uses for every engine without segment-aware rendering had zero test coverage. Covers all four PauseHint branches, the first-segment empty-builder edge case, and a mixed multi-segment join.
Fix for QA gap (round 2)Addressed the one gap QA found:
No other changes — scope stayed limited to the QA-reported gap. |
📱 iOS Build Status: PASSED⏭️ iOS Simulator Build & Unit Tests - skipped iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those. |
QA verification — PR #647 vs. issue #636Acceptance criteria (issue #636 "What's needed")
Scope note (not a criterion, but worth confirming isn't silent scope-cutting): Tests run
Confirmed fresh (not stale-cached) execution of the relevant suites via test-result XML timestamps matching the run:
Test-quality check (this repo's known failure mode — tests mocking past the broken part): All the new/changed tests call the pure functions ( One pre-existing, honestly-documented limitation carried forward unchanged by this PR: Regressions / related areas: Diffed AGENTS.md conventions: Tests present for all non-trivial new code paths, JUnit 5 + backtick names followed, no hardcoded versions, commits are Conventional-Commits-formatted and reasonably scoped (the QA verdict: PASS |
Principal review — verdict:
|
Closes #636.
What this adds
Part of #499's v2a phased breakdown. Mirrors iOS Phase A (#634, PR #640): same
NarrationSegmentshape, kept in sync across platforms, though Android's extraction stays line-oriented regex (matchingMarkdownTtsTextExtractor's existing style) rather than an AST walk.NarrationSegment.kt(core/tts) — the shared(text, kind, pauseBefore)type, plusjoinToNarrationText()(fallback flattening for engines with no segment awareness, mirroring iOS'splainText).MarkdownTtsTextExtractor.extractNarrationSegments— new function alongside (not replacing)stripMarkdownSyntax, reusing the same regexes to classify bold/italic →EMPHASIS, block quotes →QUOTE, headings →HEADING, list items →SENTENCEpause, paragraph breaks →PARAGRAPHpause, thematic breaks →SCENE_BREAKpause on the segment that follows (and the break line itself is dropped, same asstripMarkdownSyntax). Consecutive same-kind lines with no blank line between them (a soft-wrapped paragraph, a multi-line block quote) merge into one segment sopauseBefore == NONEsegments never need an implicit separator.TtsEngine.speak(segments: List<NarrationSegment>)— new default-implemented overload that flattens to plain text and callsspeak(text). Pocket/Cloud engines get this for free, no regression, no new capability yet.AndroidTtsEngine— the one real override. Converts segments into aList<PlaybackItem>(Speech|Silence), translatingpauseBeforeinto aTextToSpeech.playSilentUtteranceduration (150/500/900ms for Sentence/Paragraph/SceneBreak) spliced in ahead of each segment. This required generalizing the internal playback model from "one utterance chunk at a time viaQUEUE_FLUSH+ manualonDone-driven chaining" to enqueueing the whole remaining sequence upfront viaQUEUE_ADD— a silence item has no "next chunk" to chain from other than Android's own queue.speak(text)now funnels through the same queue (as all-Speech, no silences), so pause/resume/stop/setSpeechRateonly reason about one shape.Scope note on the issue's own text
The issue says
TextToSpeech.queueSilence(...). The real, documented Android API for this isTextToSpeech.playSilentUtterance(durationInMs, queueMode, utteranceId)(added API 21; this repo'sminSdkis 31). Used the real method name — flagging the discrepancy here rather than silently "fixing" the issue text without comment.Not done here (not asked for by this issue's own scope)
This issue's "What's needed" list (data model, extractor,
TtsEngineoverload,AndroidTtsEnginerendering) does not include wiringReaderChapter/ReaderViewModelto actually callspeak(segments)for the Markdown reader's mini-bar — unlike iOS Phase A's issue (#634), which explicitly listedAppStatewiring as a numbered step. Read that omission as deliberate:ReaderChapteris a shared cross-format type also touched by the explicitly-separate Phase D (Android EPUB, #637), so wiring it now risks rework once that phase also wants segments. Flagging this explicitly rather than silently deciding to either add or skip that wiring on my own judgment — happy to do it here if a human disagrees and wants it in scope now.Explicitly out of scope here (per issue)
Testing
MarkdownTtsTextExtractorTest(segment classification/merging/pauses),AndroidTtsEngineTest(buildPlaybackItems— the one piece of the rendering path reachable without a realandroid.speech.tts.TextToSpeech, same constraint as this file's existingsplitIntoUtterancestests).fakeTtsEngine.speak(any())mockk calls inReaderViewModelTestthat became ambiguous oncespeakwas overloaded — pinned toany<String>()../gradlew testDebugUnitTest --continuepasses locally, including after rebasing ontodev's latest commit (fix(player): stop MediaController listener race from swallowing real playback failures (#642) #649, unrelatedfeature:playerfix).