Change algorithm to detect fade point
This commit is contained in:
parent
b4da349a8c
commit
427afee8da
@ -168,11 +168,10 @@ def leading_silence(audio_segment, silence_threshold=Config.DBFS_SILENCE,
|
|||||||
return min(trim_ms, len(audio_segment))
|
return min(trim_ms, len(audio_segment))
|
||||||
|
|
||||||
|
|
||||||
def fade_point(audio_segment, fade_threshold=Config.DBFS_FADE,
|
def fade_point(audio_segment, chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE):
|
||||||
chunk_size=Config.AUDIO_SEGMENT_CHUNK_SIZE):
|
|
||||||
"""
|
"""
|
||||||
Returns the millisecond/index of the point where the fade is down to
|
Returns the millisecond/index of the point where the volume drops below
|
||||||
fade_threshold and doesn't get louder again.
|
the maximum and doesn't get louder again.
|
||||||
audio_segment - the sdlg_search_database_uiegment to find silence in
|
audio_segment - the sdlg_search_database_uiegment to find silence in
|
||||||
fade_threshold - the upper bound for how quiet is silent in dFBS
|
fade_threshold - the upper bound for how quiet is silent in dFBS
|
||||||
chunk_size - chunk size for interating over the segment in ms
|
chunk_size - chunk size for interating over the segment in ms
|
||||||
@ -182,6 +181,9 @@ def fade_point(audio_segment, fade_threshold=Config.DBFS_FADE,
|
|||||||
|
|
||||||
segment_length = audio_segment.duration_seconds * 1000 # ms
|
segment_length = audio_segment.duration_seconds * 1000 # ms
|
||||||
trim_ms = segment_length - chunk_size
|
trim_ms = segment_length - chunk_size
|
||||||
|
max_vol = audio_segment.dBFS
|
||||||
|
fade_threshold = max_vol
|
||||||
|
|
||||||
while (
|
while (
|
||||||
audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold
|
audio_segment[trim_ms:trim_ms + chunk_size].dBFS < fade_threshold
|
||||||
and trim_ms > 0): # noqa W503
|
and trim_ms > 0): # noqa W503
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user