Unverified Commit 39d55d9a authored by Dan Ellis's avatar Dan Ellis Committed by GitHub
Browse files

Tolerate missing soundfile module. (#8039)

* Update slim include.

* Force installation of tensorflow 1.14 (not tf2).

* Code will run without soundfile (but die if you attempt to read a sound file).
parent e9233425
......@@ -21,7 +21,17 @@ import resampy
import mel_features
import vggish_params
import soundfile as sf
try:
import soundfile as sf
def wav_read(wav_file):
wav_data, sr = sf.read(wav_file, dtype='int16')
return wav_data, sr
except ImportError:
def wav_read(wav_file):
raise NotImplementedError('WAV file reading requires soundfile package.')
def waveform_to_examples(data, sample_rate):
......@@ -81,7 +91,7 @@ def wavfile_to_examples(wav_file):
Returns:
See waveform_to_examples.
"""
wav_data, sr = sf.read(wav_file, dtype='int16')
wav_data, sr = wav_read(wav_file)
assert wav_data.dtype == np.int16, 'Bad sample type: %r' % wav_data.dtype
samples = wav_data / 32768.0 # Convert to [-1.0, +1.0]
return waveform_to_examples(samples, sr)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment