From 18e5bf7e3ff1160f71b05b889104c032e6e7a1ef Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 8 Apr 2022 10:07:47 -0700 Subject: [PATCH] Added extra error handling to generate_automated_labels - Caught the case where an empty wav file is successfully loaded in - Problem was that in these cases the script would crash whenever the signal was downsampled --- PyHa/IsoAutio.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/PyHa/IsoAutio.py b/PyHa/IsoAutio.py index ae56626..f18621e 100644 --- a/PyHa/IsoAutio.py +++ b/PyHa/IsoAutio.py @@ -729,11 +729,14 @@ def generate_automated_labels( # downsample the audio if the sample rate isn't 44.1 kHz # Force everything into the human hearing range. # May consider reworking this function so that it upsamples as well - if SAMPLE_RATE != Normalized_Sample_Rate: - rate_ratio = Normalized_Sample_Rate / SAMPLE_RATE - SIGNAL = scipy_signal.resample( - SIGNAL, int(len(SIGNAL) * rate_ratio)) - SAMPLE_RATE = Normalized_Sample_Rate + try: + if SAMPLE_RATE != Normalized_Sample_Rate: + rate_ratio = Normalized_Sample_Rate / SAMPLE_RATE + SIGNAL = scipy_signal.resample( + SIGNAL, int(len(SIGNAL) * rate_ratio)) + SAMPLE_RATE = Normalized_Sample_Rate + except: + print("Failed to Downsample" + audio_file) # resample produces unreadable float32 array so convert back # SIGNAL = np.asarray(SIGNAL, dtype=np.int16)