diff --git a/crepe/core.py b/crepe/core.py index 8ecb564..6885484 100644 --- a/crepe/core.py +++ b/crepe/core.py @@ -312,9 +312,18 @@ def process_file(file, output=None, model_capacity='full', viterbi=False, """ try: sr, audio = wavfile.read(file) - except ValueError: - print("CREPE: Could not read %s" % file, file=sys.stderr) - raise + except ValueError as wavfile_error: + # scipy.wavfile cannot read 24-bit files and is in general prone to failing. + # If it fails reading, let's fall back on wavio, a library that works most of the times. + print(wavfile_error) + print('CREPE: scipy.wavfile cannot read the file. Attempting with the wavio library...') + try: + import wavio + _f = wavio.read(file) + sr, audio = _f.rate, _f.data + except: + print("CREPE: Could not read %s" % file, file=sys.stderr) + raise time, frequency, confidence, activation = predict( audio, sr, diff --git a/requirements.txt b/requirements.txt index 6055387..efff00a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ h5py>=2.7.0,<3.0.0 hmmlearn>=0.2.0,<0.3.0 imageio>=2.3.0 scikit-learn>=0.16 +wavio==0.0.4