Skip to content

Commit

Permalink
Added extra error handling to generate_automated_labels
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
JacobGlennAyers committed Apr 8, 2022
1 parent 75cca40 commit 18e5bf7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions PyHa/IsoAutio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 18e5bf7

Please sign in to comment.