<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1626" rel="nofollow">http://projects.scipy.org/scipy/ticket/1626</a> on 2012-03-22 by trac user berntl, assigned to unknown.</em></p>
<p dir="auto">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 <em>play</em> it using Windows Media Player, there is no sound!</p>
<p dir="auto">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:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; rate, data = swav.read(path+r&quot;Kalimba.wav&quot;)"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; rate, data = swav.read(path+r"Kalimba.wav")
</code></pre></div>
<p dir="auto">leads to</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="C:\Python27\lib\site-packages\scipy\io\wavfile.py:31: WavFileWarning: Unfamiliar format bytes
  warnings.warn(&quot;Unfamiliar format bytes&quot;, WavFileWarning)
C:\Python27\lib\site-packages\scipy\io\wavfile.py:121: WavFileWarning: chunk not understood
  warnings.warn(&quot;chunk not understood&quot;, WavFileWarning)
rate
6000
data
'\x01\x08\x00\x00'"><pre class="notranslate"><code class="notranslate">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'
</code></pre></div>
<h2 dir="auto">Any clues?</h2>
<p dir="auto">I use the latest version of Enthought Python Distribution as of March 22, 2012.</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1585" rel="nofollow">http://projects.scipy.org/scipy/ticket/1585</a> on 2012-01-14 by trac user richli, assigned to unknown.</em></p>
<p dir="auto">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.</p>
<p dir="auto">The exported wav file plays fine with mplayer et al., but when I load it using scipy.io.wavfile.read, I get this warning:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/usr/lib/python2.7/site-packages/scipy/io/wavfile.py:121: WavFileWarning: chunk not understood
  warnings.warn(&quot;chunk not understood&quot;, WavFileWarning)"><pre class="notranslate"><code class="notranslate">/usr/lib/python2.7/site-packages/scipy/io/wavfile.py:121: WavFileWarning: chunk not understood
  warnings.warn("chunk not understood", WavFileWarning)
</code></pre></div>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Here's a helpful reference I found that talks about the chunks found in wav files: [http://www.sonicspot.com/guide/wavefiles.html#list].</p>
<p dir="auto">I also have a quick patch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[earl@leto io]$ diff wavfile_orig.py  wavfile.py
35a36,44
&gt; def _skip_unknown_chunk(fid):
&gt;     if _big_endian:
&gt;         fmt = '&gt;i'
&gt;     else:
&gt;         fmt = '&lt;i'
&gt;     data = fid.read(4)
&gt;     size = struct.unpack(fmt, data)[0]
&gt;     fid.seek(size, 1)
&gt; 
119a129,131
&gt;         elif chunk_id == asbytes('LIST'):
&gt;             # Someday this could be handled properly but for now skip it
&gt;             _skip_unknown_chunk(fid)
122,128c134
&lt;             data = fid.read(4)
&lt;             if _big_endian:
&lt;                 fmt = '&gt;i'
&lt;             else:
&lt;                 fmt = '&lt;i'
&lt;             size = struct.unpack(fmt, data)[0]
&lt;             fid.seek(size, 1)

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

---
&gt;             _skip_unknown_chunk(fid)
</code></pre></div>
<p dir="auto">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.</p>
<p dir="auto">Finally, for reference I am running:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">And this is scipy v0.10.0 on Arch linux.</p>
<p dir="auto">Thanks,<br>
Rich</p>