From 45368f8a77db0e8d515e303fa5248d32ddcf8223 Mon Sep 17 00:00:00 2001 From: Paul Pham <148553+cryptogoth@users.noreply.github.com> Date: Thu, 4 May 2023 17:14:26 -0400 Subject: [PATCH] Try / catch block so that sound clips that are too small get skipped. --- .../berkshire-meetings/1994/noise_cleanup.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/voice-training-sets/berkshire-meetings/1994/noise_cleanup.py b/voice-training-sets/berkshire-meetings/1994/noise_cleanup.py index 6726d35..c0ee347 100644 --- a/voice-training-sets/berkshire-meetings/1994/noise_cleanup.py +++ b/voice-training-sets/berkshire-meetings/1994/noise_cleanup.py @@ -19,6 +19,8 @@ for filepath in paths: if (str(filepath) == str(target_filepath)): raise ValueError("Source and target path are identical: " + str(target_filepath)) + if (os.path.exists(target_filepath)): + print(f"Output already exists, skipping {target_filepath}") print("From: " + str(filepath)) print("To: " + str(target_filepath)) @@ -39,10 +41,13 @@ for filepath in paths: # measure the loudness first meter = pyln.Meter(rate) # create BS.1770 meter - loudness = meter.integrated_loudness(data) + try: + loudness = meter.integrated_loudness(data) - # loudness normalize audio to -25 dB LUFS - loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -25.0) + # loudness normalize audio to -25 dB LUFS + loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -25.0) + except ValueError as e: + print(f"ValueError: ${str(e)}") sf.write(target_filepath, data=loudness_normalized_audio, samplerate=22050)