From 4beed5b1dbbe9e050bae412f64b7ef8121d6cad1 Mon Sep 17 00:00:00 2001 From: Anupama <2028121+achingacham@users.noreply.github.com> Date: Tue, 1 Aug 2023 01:07:45 +0200 Subject: [PATCH] Avoid leading/trailing silence in the RMS calculation The leading and trailing zeros (to represent silence) need to be avoided while calculating the RMS of the signal, as it impacts the overall signal distortion. --- create_mixed_audio_file.py | 1 + 1 file changed, 1 insertion(+) diff --git a/create_mixed_audio_file.py b/create_mixed_audio_file.py index 806cdfa..81706c0 100644 --- a/create_mixed_audio_file.py +++ b/create_mixed_audio_file.py @@ -29,6 +29,7 @@ def cal_amp(wf): return amptitude def cal_rms(amp): + amp = np.trim_zeros(amp) # to remove leading and trailing zeros (representing silence in the audio beginning/end) return np.sqrt(np.mean(np.square(amp), axis=-1)) def save_waveform(output_path, params, amp):