Reputation: 600
Whenever I try to read a .wav file, the following error comes.
I have searched everywhere but had no progress upon this.
CODE:
import scipy as sp
import matplotlib.pyplot as plt
sr, y = sp.io.wavfile.read(MY_FILENAME)
print sr
ERROR:
File "/usr/local/lib/python2.7/dist-packages/scipy/io/wavfile.py", line 252, in read
fmt_chunk = _read_fmt_chunk(fid, is_big_endian)
File "/usr/local/lib/python2.7/dist-packages/scipy/io/wavfile.py", line 94, in _read_fmt_chunk
raise ValueError("Unknown wave file format")
ValueError: Unknown wave file format
Update:
After I tried converting my file as suggested by @velikodniy using sox:
sox MY_FILENAME.wav MY_FILENAME.wav
But it throws another warning:
sox WARN wav: Premature EOF on .wav input file
And now if I try to play the original .wav file, it says unsupported format in the media player(previously it was playing)
Upvotes: 6
Views: 9024
Reputation: 21
I converted the wav file to specific format using code and the error got resolved.
import soundfile as sf
y, s = librosa.load(pwd+'\\ans.wav', sr=48000)
sf.write('audio_test_1.wav', y, s, "PCM_24")
rate, data = read(pwd+'\\audio_test_1.wav')
Upvotes: 0
Reputation: 863
WAVs may contain audio data in different formats. For example, MP3.scipy.io.wavfile.read
can read only PCM and floating point formats (WAVE_FORMAT_PCM and WAVE_FORMAT_IEEE_FLOAT, to be exact) at the moment.
So you must convert your audio file with an audio editor (e.g. Audacity or sox).
Upvotes: 5
Reputation: 9541
I tried many solutions, but I only had success with the following steps:
Upvotes: 2