From 5c0d72e4dbf2e44d433b9a07eab8d86eabbaeee0 Mon Sep 17 00:00:00 2001 From: Sergiy Matusevych Date: Wed, 10 Nov 2021 19:24:53 -0800 Subject: [PATCH] dd some defensive code if audio file cannot be read - issue #42 --- audiolib.py | 1 + noisyspeech_synthesizer_singleprocess.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/audiolib.py b/audiolib.py index c58b0ae0cc1..f4d889dce5e 100644 --- a/audiolib.py +++ b/audiolib.py @@ -41,6 +41,7 @@ def audioread(path, norm=False, start=0, stop=None, target_level=-25): audio, sample_rate = sf.read(path, start=start, stop=stop) except RuntimeError: # fix for sph pcm-embedded shortened v2 print('WARNING: Audio type not supported') + return (None, None) if len(audio.shape) == 1: # mono if norm: diff --git a/noisyspeech_synthesizer_singleprocess.py b/noisyspeech_synthesizer_singleprocess.py index 30bb951f485..d69db7fc47e 100644 --- a/noisyspeech_synthesizer_singleprocess.py +++ b/noisyspeech_synthesizer_singleprocess.py @@ -6,6 +6,7 @@ # speech sourcefile once, as it does not randomly sample from these files import os +import sys import glob import argparse import ast @@ -80,6 +81,9 @@ def build_audio(is_clean, params, index, audio_samples_length=-1): idx = (idx + 1) % np.size(source_files) input_audio, fs_input = audioread(source_files[idx]) + if input_audio is None: + sys.stderr.write("WARNING: Cannot read file: %s\n" % source_files[idx]) + continue if fs_input != fs_output: input_audio = librosa.resample(input_audio, fs_input, fs_output)