Skip to content

Commit c6c0a69

Browse files
Fix merge by gap in the transcript resizer dialog (#1658)
Co-authored-by: Raivis Dejus <raivisd@scandiweb.com>
1 parent c02e63f commit c6c0a69

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

‎buzz/widgets/transcription_viewer/transcription_resizer_widget.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def get_transcript(self, audio, **kwargs) -> dict:
6767
for buzz_segment in buzz_segments:
6868
words.append({
6969
'word': buzz_segment.text + separator,
70-
'start': buzz_segment.start_time / 100,
71-
'end': buzz_segment.end_time / 100,
70+
'start': buzz_segment.start_time / 1000,
71+
'end': buzz_segment.end_time / 1000,
7272
})
7373
text += buzz_segment.text + separator
7474

@@ -123,8 +123,8 @@ def run(self):
123123
for segment in result.segments:
124124
segments.append(
125125
Segment(
126-
start=int(segment.start * 100),
127-
end=int(segment.end * 100),
126+
start=int(segment.start * 1000),
127+
end=int(segment.end * 1000),
128128
text=segment.text
129129
)
130130
)

‎tests/widgets/transcription_viewer_test.py‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,46 @@ def test_transcription_worker_calls_stable_whisper(self, qtbot: QtBot, transcrip
286286
finished_spy.assert_called_once()
287287
emitted_segments = finished_spy.call_args[0][0]
288288
assert len(emitted_segments) == 1
289-
assert emitted_segments[0].start == 100
290-
assert emitted_segments[0].end == 200
289+
assert emitted_segments[0].start == 1000
290+
assert emitted_segments[0].end == 2000
291291
assert emitted_segments[0].text == "Hello"
292292

293+
def test_transcription_worker_merges_segments_closer_than_gap(
294+
self, qtbot: QtBot, transcription_dao, transcription_segment_dao, transcription_service
295+
):
296+
id = uuid.uuid4()
297+
transcription_dao.insert(
298+
Transcription(
299+
id=str(id),
300+
status="completed",
301+
file=test_audio_path,
302+
task=Task.TRANSCRIBE.value,
303+
model_type=ModelType.WHISPER.value,
304+
whisper_model_size=WhisperModelSize.TINY.value,
305+
)
306+
)
307+
# 150 ms apart, below the 0.2 s merge gap
308+
transcription_segment_dao.insert(TranscriptionSegment(40, 1000, "Bien.", "", str(id)))
309+
transcription_segment_dao.insert(TranscriptionSegment(1150, 2000, "Venue.", "", str(id)))
310+
311+
mock_transcription_options = MagicMock()
312+
mock_transcription_options.extract_speech = False
313+
worker = TranscriptionWorker(
314+
transcription=transcription_dao.find_by_id(str(id)),
315+
transcription_options=mock_transcription_options,
316+
transcription_service=transcription_service,
317+
regroup_string="mg=0.2",
318+
)
319+
finished_spy = MagicMock()
320+
worker.finished.connect(finished_spy)
321+
322+
worker.run()
323+
324+
emitted_segments = finished_spy.call_args[0][0]
325+
assert len(emitted_segments) == 1
326+
assert emitted_segments[0].start == 40
327+
assert emitted_segments[0].end == 2000
328+
293329
# TODO - Fix this test on Windows, should work.
294330
# Possibly the `on_loop_toggle_changed` gets triggered on setChecked
295331
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Skipping on Windows")

0 commit comments

Comments
 (0)