fix(postprocess): drop tiny carry-over text
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user