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
2025-02-13 07:52:03 +00:00
committed by GitHub
parent 34b9079a1b
commit 27f8b57d05
2 changed files with 6 additions and 6 deletions
+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]