Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently,
TtsNavigator.go(locator)starts playback at the containing text element, even when the locator identifies a specific sentence usinglocations.domRange.start.This PR adds sentence-accurate seeking to the existing TTS navigator. When a valid HTML DOM range is provided, playback starts at the sentence containing the specified DOM position.
The same behavior applies to
initialLocatorwhen creating a TTS navigator.Use case
I want to start TTS from a specific sentence within a paragraph, rather than always starting from the beginning of that paragraph.
For example, consider a paragraph containing:
When the reader taps a word in "Second sentence.", I want to pass a locator representing that DOM position to
TtsNavigator.go(locator)and have TTS start reading "Second sentence.", skipping the preceding sentence.This is useful for tap-to-speak interactions in EPUB readers, where users expect playback to begin at the text they selected or tapped.
The locator's
locations.domRange.startprovides the precise DOM position, allowing the existing TTS navigator to determine the corresponding sentence.Implementation
Publicationextension that resolvesdomRange.startto a normalized character offset within the containing HTML block, using Jsoup.textNodeIndex, and UTF-16charOffsetto preserve the original DOM position.<br>.The additional DOM parsing is necessary because Readium's Content API exposes extracted text and element locators, but not the original DOM text-node coordinates.