fix(postprocess): drop tiny carry-over text
Build & Push Docker Image / test (push) Successful in 11s
Build & Push Docker Image / build-and-push (push) Successful in 43s

Collapse one-word and very short caption carry-over fragments so reprocessed YouTube transcripts do not retain residual prefix chains.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-11 23:14:31 +02:00
co-authored by Copilot
parent 672b161cda
commit 6beb436687
2 changed files with 27 additions and 2 deletions
+9 -2
View File
@@ -78,6 +78,10 @@ function isMeaningfulPhrase(words: string[]): boolean {
return words.length >= MIN_MEANINGFUL_WORDS && words.join(' ').length >= MIN_MEANINGFUL_CHARS;
}
function isShortCarryover(seg: Segment, words: string[]): boolean {
return seg.end - seg.start <= 0.2 || words.length <= 2 || words.join(' ').length <= 16;
}
function trimLeadingWords(text: string, count: number): string {
return splitWords(text).slice(count).join(' ').trim();
}
@@ -115,7 +119,7 @@ function collapseIncrementalSegments(segments: Segment[]): Segment[] {
if (
currentWords.length > lastWords.length &&
startsWithWords(currentWords, lastWords) &&
isMeaningfulPhrase(lastWords)
(isMeaningfulPhrase(lastWords) || isShortCarryover(last, lastWords))
) {
last.text = current.text;
last.end = current.end;
@@ -123,7 +127,10 @@ function collapseIncrementalSegments(segments: Segment[]): Segment[] {
continue;
}
if (endsWithWords(lastWords, currentWords) && isMeaningfulPhrase(currentWords)) {
if (
endsWithWords(lastWords, currentWords) &&
(isMeaningfulPhrase(currentWords) || isShortCarryover(current, currentWords))
) {
last.end = Math.max(last.end, current.end);
continue;
}