Init view TTS with text segmentation granularity (#47)

in order to support more TTS backends

This PR also fixes a potential off-by-one error at the end boundary of the segment using `sentence` granularity.
This commit is contained in:
Huang Xin authored and GitHub committed 2025-02-13 07:52:03 +00:00
1 parent 34b9079a1b
commit 27f8b57d05
2 files changed
+6 -6

No files matched your search

+2 -2
View File
@@ -577,12 +577,12 @@ export class View extends HTMLElement {
for (const item of list) this.deleteAnnotation(item)
this.#searchResults.clear()
}
async initTTS() {
async initTTS(granularity = 'word') {
const doc = this.renderer.getContents()[0].doc
if (this.tts && this.tts.doc === doc) return
const { TTS } = await import('./tts.js')
this.tts = new TTS(doc, textWalker, range =>
this.renderer.scrollToAnchor(range, true))
this.renderer.scrollToAnchor(range, true), granularity)
}
startMediaOverlay() {
const { index } = this.renderer.getContents()[0]