diff --git a/static/js/audiobook-segmentation.js b/static/js/audiobook-segmentation.js index 3a79314..0ff334d 100644 --- a/static/js/audiobook-segmentation.js +++ b/static/js/audiobook-segmentation.js @@ -13,12 +13,14 @@ function _abImplausibleDialoguePiece(text) { function audiobookSplitByQuotes(text) { const spans = []; - for (let i = 0; i < text.length; i++) { + let next = 0; + while (next < text.length) { + const i = next++; const open = text[i], close = AB_QUOTE_PAIRS[open]; if (!close) continue; const minStart = spans.length ? spans[spans.length - 1].end : 0; const orphan = _abOrphanClosingQuoteSpan(text, i, minStart); - if (orphan) { spans.push(orphan); i = orphan.end - 1; continue; } + if (orphan) { spans.push(orphan); next = orphan.end; continue; } if ((open === '«' || open === '»') && i > 0 && !/[\s([{—–-]/.test(text[i - 1])) continue; const raw = text.slice(i + 1); const closeIdx = raw.indexOf(close); @@ -27,7 +29,7 @@ function audiobookSplitByQuotes(text) { if (!quote) continue; const consumedClose = closeIdx >= 0 && endInRaw === closeIdx; spans.push({ start: i, end: i + 1 + endInRaw + (consumedClose ? 1 : 0), quote }); - i = spans[spans.length - 1].end - 1; + next = spans[spans.length - 1].end; } if (!spans.length) return [{ speaker: 'Narrator', type: 'narration', text, emotion: '' }]; const out = []; let last = 0;