pythonpython-2.7scipywavaudio-processing

Scipy io read wavfile error


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)


Solution

  • 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).