Eric
Eric

Reputation: 16961

scipy.io.wavfile gives "WavFileWarning: chunk not understood" error

I'm trying to read a .wav file using scipy. I do this:

from scipy.io import wavfile

filename = "myWavFile.wav"
print "Processing " + filename

samples = wavfile.read(filename)

And I get this ugly error:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/wavfile.py:121: WavFileWarning: chunk not understood
  warnings.warn("chunk not understood", WavFileWarning)
Traceback (most recent call last):
  File "fingerFooler.py", line 15, in <module>
    samples = wavfile.read(filename)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/wavfile.py", line 127, in read
    size = struct.unpack(fmt, data)[0]
struct.error: unpack requires a string argument of length 4

I'm using Python 2.6.6, numpy 1.6.2, and scipy 0.11.0

Here's a wav file that causes the problem.

Any thoughts? What's wrong here?

Upvotes: 19

Views: 38833

Answers (6)

Maximilian Treitler
Maximilian Treitler

Reputation: 11

Solved this problem when exporting from Reaper: simply deselect "Write BWF ('bext') chunk" in the Render to File window.

Upvotes: 1

Carlos Leal de Castro
Carlos Leal de Castro

Reputation: 51

The easiest solution to this problem is to convert the wav file into other wav file using SoX.

$ sox wavfile.wav wavfile2.wav

Works for me!

Upvotes: 5

daisukelab
daisukelab

Reputation: 91

I had the same error and could successfully convert to what it can read.

My original file was from Logic Pro. Then I used audacity to read the file.

Upvotes: 2

user2348114
user2348114

Reputation: 167

I also got this error because of (presumably) metadata introduced by Audacity. I exported my wav file from another DAW (Ableton Live), and scipy.io.wavfile loaded it without error.

Upvotes: 1

rolinger
rolinger

Reputation: 763

The files is no longer available (not surprising after 9 months!), but for future reference the most likely cause is that it had extra metadata which scipy can't parse.

In my case, it was default metadata (copyright, track name etc) which was added by Audacity- you can open the file in Audacity and use File ... Open Metadata Editor to see it. Then use the 'Clear' button to strip it, and try again.

The current version of scipy supports the following RIFF chunks - 'fmt', 'fact', 'data' and 'LIST'. The Wikipedia page on RIFF has a bit more detail on how a WAV file is structured, for example yours might have included an unsupported-but-popular INFO chunk

Upvotes: 30

necaris
necaris

Reputation: 247

I don't know anything about the WAV file format, but digging into the scipy code it looks like scipy isn't familiar with the chunk that's present towards the end of the file (chunk ID is bext, 2753632 bytes in, if that helps). That chunk is declared as 603 bytes long so it reads past it expecting another chunk ID 603 bytes later -- it doesn't find it (runs out of file) and falls over.

Have you tried it on other WAV files successfully? How was this one generated?

Upvotes: 10

Related Questions