Skip to content

Commit

Permalink
fixes start index of text nodes when there is more than one text node
Browse files Browse the repository at this point in the history
  • Loading branch information
aferditamuriqi committed Aug 11, 2022
1 parent ea78fb3 commit 9fdd8df
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/modules/TTS/TTSModule2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,27 @@ export class TTSModule2 implements ReaderModule {
}

utterance = new SpeechSynthesisUtterance(textToBeSpoken);
log.log(selectionInfo);
log.log(
textToBeSpoken,
selectionInfo.range?.commonAncestorContainer.textContent
);
log.log(ttsQueueItem);
log.log(ttsQueueItem.item.textNodes);
log.log(startIndex);
for (let i = 0; i < ttsQueueItem.item.textNodes.length; i++) {
let node: any = ttsQueueItem.item.textNodes[i];
if (node === selectionInfo.range?.commonAncestorContainer) {
break;
}
log.log(node.length);
startIndex += node.length;
}
let node = ttsQueueItem.item.textNodes.filter((node) => {
return node === selectionInfo.range?.commonAncestorContainer;
})[0];
log.log(node);

utterance.onboundary = (ev: SpeechSynthesisEvent) => {
this.updateTTSInfo(
ttsQueueItem,
Expand Down

0 comments on commit 9fdd8df

Please sign in to comment.