From b4ba1ff19f4dff780a70ad35f9a3f410bf14ca74 Mon Sep 17 00:00:00 2001 From: milahu Date: Wed, 15 May 2024 13:02:19 +0200 Subject: [PATCH 1/2] fix split_silence.py - ignore last chunk with negative duration --- examples/split_silence.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/split_silence.py b/examples/split_silence.py index 90b46d95..5cca7e02 100755 --- a/examples/split_silence.py +++ b/examples/split_silence.py @@ -88,8 +88,16 @@ def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time chunk_starts.append(start_time) if len(chunk_starts) > len(chunk_ends): - # Finished with non-silence. - chunk_ends.append(end_time or 10000000.) + if chunk_starts[-1] < end_time: + # Finished with non-silence. + chunk_ends.append(end_time or 10000000.) + else: + # ignore last chunk with negative duration + # this happens when silence_end comes after time + # example: 52.79 < 52.83 + # line 'size=N/A time=00:20:52.79 bitrate=N/A speed= 30x ' + # line '[silencedetect @ 0x20f8fc0] silence_end: 1252.83 | silence_duration: 6.27579' + chunk_starts.pop() return list(zip(chunk_starts, chunk_ends)) From db3c14ba9dc4093de6f4df2dfae0313e605840b3 Mon Sep 17 00:00:00 2001 From: milahu Date: Sun, 19 May 2024 12:22:26 +0200 Subject: [PATCH 2/2] FIXUP handle missing end_time --- examples/split_silence.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/split_silence.py b/examples/split_silence.py index 5cca7e02..656cafc1 100755 --- a/examples/split_silence.py +++ b/examples/split_silence.py @@ -87,10 +87,14 @@ def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time # No silence found. chunk_starts.append(start_time) + if end_time is None: + # use a fake end time + end_time = 10000000. + if len(chunk_starts) > len(chunk_ends): if chunk_starts[-1] < end_time: # Finished with non-silence. - chunk_ends.append(end_time or 10000000.) + chunk_ends.append(end_time) else: # ignore last chunk with negative duration # this happens when silence_end comes after time