Skip to content

Commit 97ecec2

Browse files
committed
fix: improve heuristic for not combining paragraphs
this changes the detection heuristic for overly long sentences from the previous "longer than 30s" to a word based approach of "more than 161 words". moreover it gets rid of the stateful approach that we would disable all recombination after the first overly long paragraph. overall this is not a perfect approach but produces saner results than before. this should temporarily fix the situation in which transcribee generates only one word per paragraph. the proper fix is resetting the whisper state from time to time and will land in the future.
1 parent 47d0bfd commit 97ecec2

2 files changed

Lines changed: 8 additions & 109 deletions

File tree

worker/tests/data/test_strict_sentence_paragraphs-doest_combine_long_para.json

Lines changed: 0 additions & 90 deletions
This file was deleted.

worker/transcribee_worker/whisper_transcribe.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,18 @@ def strict_sentence_paragraphs(
8787
) -> Iterator[Paragraph]:
8888
acc_paragraph = None
8989
acc_used_paras = []
90-
combination_active = True
9190
for paragraph in iter:
92-
if not combination_active:
93-
yield paragraph
94-
continue
95-
elif acc_paragraph is None:
91+
if acc_paragraph is not None and len(acc_paragraph.children) > 161:
92+
# it seems like whisper is on some path that does not involve sentence breaks
93+
# as a workaround we just emit the raw whisper bars
94+
yield from acc_used_paras
95+
acc_paragraph = None
96+
97+
if acc_paragraph is None:
9698
acc_paragraph = Paragraph(
9799
lang=paragraph.lang, speaker=paragraph.speaker, children=[]
98100
)
99101
acc_used_paras = []
100-
elif (
101-
(start := acc_paragraph.start()) is not None
102-
and (end := paragraph.end()) is not None
103-
and end - start > 30
104-
):
105-
# It seems like whisper doesn't produce sentence breaks. Ignore the
106-
# current `acc_paragraph` and yield the original paras instead,
107-
# disable this step until the end of the document
108-
combination_active = False
109-
for para in acc_used_paras:
110-
yield para
111-
yield paragraph
112-
continue
113102
elif (
114103
acc_paragraph.lang != paragraph.lang
115104
or acc_paragraph.speaker != paragraph.speaker
@@ -160,7 +149,7 @@ def strict_sentence_paragraphs(
160149
children=paragraph.children[acc_yield_offset:],
161150
)
162151
)
163-
if acc_paragraph is not None and acc_paragraph.children and combination_active:
152+
if acc_paragraph is not None and acc_paragraph.children:
164153
yield acc_paragraph
165154

166155

0 commit comments

Comments
 (0)