KiteReadAloud
Reads an EPUB aloud with the narration it ships, its media overlays, and follows the text in the viewer of state (#36). Place it next to the viewer, and switch playing from your own controls:
val state = rememberKiteDocViewState(book)
var playing by remember { mutableStateOf(false) }
KiteDocView(state)
KiteReadAloud(state, playing, onFinished = { playing = false })The first time playing is true, it reads from the first clip whose text is on the reader's page or after it, in that chapter or the next one with an overlay. It plays each clip's audio out of the book, from the clip's clipBegin to its clipEnd, or to the end of the file without one (EPUB Reading Systems 3.3, 9.2.2). When a chapter's overlay ends, it goes on with the next chapter that has one (9.1). False pauses it, and true again goes on from there. When the reader moves the viewer to another place, by a link, the table of contents, a page turn or a scroll, the reading goes on from the first clip at or after that place once the view settles, also while it is paused (Media Overlays 3.3, navigation during playback). The page turns that the reading makes to follow its text do not count, and it turns no page while the reader moves the view.
The viewer turns to the page of the clip's text when the reading reaches another page. With bookStyles, the element of the clip gets the book's media:active-class, and its chapter's root gets the media:playback-active-class while the reading plays, through EpubDocument.markNarration (EPUB Reading Systems 3.3, 9.2.3). A chapter whose style rules use one of the classes is laid out again for each clip. Where the book's rules do not style the active class, or without bookStyles, the text of the clip gets one entry in KiteDocViewState.highlights instead, with the id READ_ALOUD_HIGHLIGHT_ID, next to the app's own entries. Assigning KiteDocViewState.highlights while it reads drops the entry until the next clip.
A clip without audio is spoken by speak, when the app gives one, and skipped otherwise. A clip whose audio the player cannot open is skipped. Leaving the composition stops the reading, closes the player and takes the highlight and the classes away. On a viewer whose document is not an EpubDocument, it does nothing.
Parameters
the viewer that shows the book, and whose highlights and page follow the reading.
reads while true, and pauses while false.
the fill of the highlight. Null paints the viewer's search highlight colour, as a KiteHighlight without a colour does.
makes the player when the reading reaches the first clip with audio, or returns null where the platform cannot play, which ends the reading there. See KiteMediaOverlay.
gives the text being read the book's own classes, as above. False keeps every chapter's layout as it is and marks the text with the highlight only.
speaks a clip without audio, from a speech engine of the app, and returns once it has said it all. It gets the clip and the text of its element, from EpubDocument.readingOrderOf, with the pronunciation hints of the book. A pause or a move by the reader cancels it, and the reading speaks the clip again from its start when it goes on. Null skips such clips.
called with each clip as its reading starts, and with null when the reading ends.
called when the reading ends: past the last clip of the book, at once for a book without narration from the reader's page on, or at the first clip with audio when there is no player. It is not called when the reading leaves the composition.