From 00cae6dc525bac99afb1352033cec7a4f48052b9 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 15 Aug 2021 00:03:52 +0100 Subject: [PATCH] Fix up silence detection from last commit --- app/songdb.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/songdb.py b/app/songdb.py index 51aa2cf..42063cd 100755 --- a/app/songdb.py +++ b/app/songdb.py @@ -168,7 +168,8 @@ def leading_silence(audio_segment, silence_threshold=Config.DBFS_SILENCE, return min(trim_ms, len(audio_segment)) -def fade_point(audio_segment, chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE): +def fade_point(audio_segment, fade_threshold=0, + chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE): """ Returns the millisecond/index of the point where the volume drops below the maximum and doesn't get louder again. @@ -182,7 +183,8 @@ def fade_point(audio_segment, chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE): segment_length = audio_segment.duration_seconds * 1000 # ms trim_ms = segment_length - chunk_size max_vol = audio_segment.dBFS - fade_threshold = max_vol + if fade_threshold == 0: + fade_threshold = max_vol while ( audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold