Friday, April 5, 2013

Error: unknown format: 85

So for the past little bit I've been trying to figure out how to work with wave files in python. It was going well until I ran into this little error:


>>> import wave
>>> f = wave.open("C:\\Users\\Clint\\Test\\elvis_return_x.wav", "rb")

Traceback (most recent call last):
File "", line 1, in
f = wave.open("C:\\Users\\Clint\\Test\\elvis_return_x.wav", "rb")
File "C:\Python27\lib\wave.py", line 498, in open
return Wave_read(f)
File "C:\Python27\lib\wave.py", line 163, in __init__
self.initfp(f)
File "C:\Python27\lib\wave.py", line 143, in initfp
self._read_fmt_chunk(chunk)
File "C:\Python27\lib\wave.py", line 269, in _read_fmt_chunk
raise Error, 'unknown format: %r' % (wFormatTag,)
Error: unknown format: 85


As it turns out this little bug is cause by the fact that the builtin "wave.py" module in python does not support any type of compression aside from "None." (Compression format code "00" for anybody who's interested.)

At the python documentation I found a certain part that actually says this:

http://docs.python.org/2/library/wave.html

"Wave_read.getcomptype()
Returns compression type ('NONE' is the only supported type)."

So how do you change the compression format of a .wav file?

What I did was open the file in Audacity, and the export it as a .wav with a different name (and with the default "None" compression in Audacity), and voila, with the new file, wave.py works.

I did not find much info online about this particular error, so I have decided to post this so that it can be found, and help somebody.

Other useful sites I found about this topic are:

http://www.sonicspot.com/guide/wavefiles.html

http://en.wikipedia.org/wiki/WAV

http://en.wikipedia.org/wiki/Resource_Interchange_File_Format

No comments: