Skip to content

Commit

Permalink
optimize start index and compare if text node is at the beginiing
Browse files Browse the repository at this point in the history
  • Loading branch information
aferditamuriqi committed Aug 11, 2022
1 parent 9fdd8df commit 45ba7b8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/modules/TTS/TTSModule2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export class TTSModule2 implements ReaderModule {
}

utterance = new SpeechSynthesisUtterance(textToBeSpoken);

log.log(selectionInfo);
log.log(
textToBeSpoken,
Expand All @@ -338,13 +339,16 @@ export class TTSModule2 implements ReaderModule {
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(ttsQueueItem.item.combinedText);
if (!ttsQueueItem.item.combinedText?.startsWith(textToBeSpoken)) {
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;
}
log.log(node.length);
startIndex += node.length;
}
let node = ttsQueueItem.item.textNodes.filter((node) => {
return node === selectionInfo.range?.commonAncestorContainer;
Expand Down Expand Up @@ -1132,6 +1136,7 @@ export class TTSModule2 implements ReaderModule {
if (!ttsQueueItem) {
return undefined;
}
log.log(ttsQueueItem, charIndex, charLength, utteranceText);

const ttsQueueItemText = utteranceText
? utteranceText
Expand Down Expand Up @@ -1177,6 +1182,10 @@ export class TTSModule2 implements ReaderModule {
start: number,
end: number
) {
log.log(ttsQueueItemRef);
log.log(utteranceText);
log.log(charIndex, charLength, word, start, end);

if (this._ttsQueueItemHighlightsWord) {
this.delegate.highlighter?.destroyHighlights(HighlightType.ReadAloud);
this._ttsQueueItemHighlightsWord = undefined;
Expand Down

0 comments on commit 45ba7b8

Please sign in to comment.