Issue 1:
Original ticket http://projects.scipy.org/scipy/ticket/1626 on 2012-03-22 by trac user berntl, assigned to unknown.

If I write a wav file to disk using scipy.io.wavfile.write, and then read it again, the file appears to be ok. HOWEVER if I try to play it using Windows Media Player, there is no sound!

I have found a wav-file "sweeplin.wav" on the internet, as well as converted an mp3 file "Kalimba.mp3" to wav using freeware "Switch Sound File Converter". Both sweeplin, and Kalimba (before and after conversion) plays nicely on Windows Media Player. If I try to import e.g. Kalimba.wav using scipy.wavefile.read("Kalimba.wav"), I get an error message:

>>> rate, data = swav.read(path+r"Kalimba.wav")

leads to

C:\Python27\lib\site-packages\scipy\io\wavfile.py:31: WavFileWarning: Unfamiliar format bytes
warnings.warn("Unfamiliar format bytes", WavFileWarning)
C:\Python27\lib\site-packages\scipy\io\wavfile.py:121: WavFileWarning: chunk not understood
warnings.warn("chunk not understood", WavFileWarning)
rate
6000
data
'\x01\x08\x00\x00'

Any clues?

I use the latest version of Enthought Python Distribution as of March 22, 2012.

Issue 2:
Original ticket http://projects.scipy.org/scipy/ticket/1585 on 2012-01-14 by trac user richli, assigned to unknown.

I recorded some sound with Audacity and then exported it using the default options to a 16-bit signed PCM WAV file. Upon export, it fills in some metadata (artist name, track, etc) automatically but allows me to customize or clear out the metadata.

The exported wav file plays fine with mplayer et al., but when I load it using scipy.io.wavfile.read, I get this warning:

/usr/lib/python2.7/site-packages/scipy/io/wavfile.py:121: WavFileWarning: chunk not understood
warnings.warn("chunk not understood", WavFileWarning)

Upon examination of the source code and a hexdump of the offending wav file, I determined that the code only handles "format" and "data" chunks. All other types of wav chunks are skipped. The chunk in question happens to be an "info" chunk that is used for storing metadata. It looks like wavfile.py correctly skips over it, but it's still annoying to see warnings about perfectly legitimate wav files.

To double-check things, I re-exported the wav files from Audacity, this time clearing out metadata. A hex dump confirms that no "list" chunks exist in the wav file and wavfile.py no longer issues the warning.

Here's a helpful reference I found that talks about the chunks found in wav files: [http://www.sonicspot.com/guide/wavefiles.html#list].

I also have a quick patch:

[earl@leto io]$ diff wavfile_orig.py wavfile.py
35a36,44
> def _skip_unknown_chunk(fid):
> if _big_endian:
> fmt = '>i'
> else:
> fmt = '<i'
> data = fid.read(4)
> size = struct.unpack(fmt, data)[0]
> fid.seek(size, 1)
>
119a129,131
> elif chunk_id == asbytes('LIST'):
> # Someday this could be handled properly but for now skip it
> _skip_unknown_chunk(fid)
122,128c134
< data = fid.read(4)
< if _big_endian:
< fmt = '>i'
< else:
< fmt = '<i'
< size = struct.unpack(fmt, data)[0]
< fid.seek(size, 1)

---
> _skip_unknown_chunk(fid)

In this patch I move the else suite to a new private function, _skip_unknown_chunk(). I create an extra elif case for a "list" chunk and note that it could be handled in the future to return the contained metadata, but currently it just treats it as unknown and skips it. It's not important to me currently for it to read the metadata from the wav file, but someday it may be useful.

Finally, for reference I am running:

Linux leto 3.1.8-1-ARCH #1 SMP PREEMPT Sat Jan 7 08:59:43 CET 2012 x86_64 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux

And this is scipy v0.10.0 on Arch linux.

Thanks,

Rich