I had problems using the build in function of Scipy to load soundfiles as an scipy.array object. Sometimes it gives an error like “struct.error: unpack requires a string argument of length 4″ when opening some wave files. Yes it only handles wave files!

After trying audiolab, which was not working, and the build-in functions for opening wave files I stumbled upon “Use (Python) Gstreamer to decode audio (to PCM data)”. Because I was already using GStreamer in this project to handle microphone recordings I used the linked library from the post and wrote a little function to convert the raw PCM data to readable scipy arrays. It was a little bit tricky to get the struct.unpack right but now it works like a charm.

So now we have a working implementation that can convert any audiofile, that gstreamer can open, to a scipy.array. Thanks goes to Adrian Sampson for providing the decoding function.

See my changes on http://gist.github.com/592776