Python, speech_recognition tool does not recognize .wav file
From a brief look at the code in the speech_recognition
package, it appears that it uses wave
from the Python standard library to read WAV files. Python's wave
library does not handle floating point WAV files, so you'll have to ensure that you use speech_recognition
with files that were saved in an integer format.
SciPy's function scipy.io.wavfile.write
will create an integer file if you pass it an array of integers. So if data
is a floating point numpy array, you could try this:
from scipy.io import wavfile
# Convert `data` to 32 bit integers:
y = (np.iinfo(np.int32).max * (data/np.abs(data).max())).astype(np.int32)
wavfile.write(wav_path, fs, y)
Then try to read that file with speech_recognition
.
Alternatively, you could use wavio
(a small library that I created) to save your data to a WAV file. It also uses Python's wave
library to create its output, so speech_recognition
should be able to read the files that it creates.