From 842a632cd5eab6e69282598222fb595a2a765614 Mon Sep 17 00:00:00 2001 From: Enno Hermann Date: Tue, 14 Nov 2023 13:37:43 +0100 Subject: [PATCH] refactor(audio.processor): use find_endpoint from numpy_transforms --- TTS/utils/audio/processor.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/TTS/utils/audio/processor.py b/TTS/utils/audio/processor.py index 136cfeff..2e298c07 100644 --- a/TTS/utils/audio/processor.py +++ b/TTS/utils/audio/processor.py @@ -14,6 +14,7 @@ from TTS.utils.audio.numpy_transforms import ( compute_f0, db_to_amp, deemphasis, + find_endpoint, griffin_lim, mel_to_spec, millisec_to_length, @@ -527,13 +528,14 @@ class AudioProcessor(object): Returns: int: Last point without silence. """ - window_length = int(self.sample_rate * min_silence_sec) - hop_length = int(window_length / 4) - threshold = db_to_amp(x=-self.trim_db, gain=self.spec_gain, base=self.base) - for x in range(hop_length, len(wav) - window_length, hop_length): - if np.max(wav[x : x + window_length]) < threshold: - return x + hop_length - return len(wav) + return find_endpoint( + wav=wav, + trim_db=self.trim_db, + sample_rate=self.sample_rate, + min_silence_sec=min_silence_sec, + gain=self.spec_gain, + base=self.base, + ) def trim_silence(self, wav): """Trim silent parts with a threshold and 0.01 sec margin"""