[issue5024] sndhdr.whathdr returns -1 for WAV file frame count
Robert Pyle
report at bugs.python.org
Fri Jul 9 17:27:43 CEST 2010
Robert Pyle <rpyle at post.harvard.edu> added the comment:
On Jul 8, 2010, at 6:52 PM, Mark Lawrence wrote:
>
> Mark Lawrence <breamoreboy at yahoo.co.uk> added the comment:
>
> Robert, could you provide a patch for this?
>
> ----------
> nosy: +BreamoreBoy
> stage: -> needs patch
> versions: +Python 3.2
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <http://bugs.python.org/issue5024>
> _______________________________________
Okay, I'm not sure exactly how I'm supposed to go about this. Here's
the output from diff <new file> <original file> for sndhdr.py
131d130
< import wave
135,141c134,138
< f.seek(0)
< try:
< w = wave.openfp(f, 'r')
< except (EOFError, wave.Error):
< return None
< return ('wav', w.getframerate(), w.getnchannels(), \
< w.getnframes(), 8*w.getsampwidth())
---
> style = get_short_le(h[20:22])
> nchannels = get_short_le(h[22:24])
> rate = get_long_le(h[24:28])
> sample_bits = get_short_le(h[34:36])
> return 'wav', rate, nchannels, -1, sample_bits
$
All I did was use test_aifc() as inspiration, so the patched sndhdr.py
calls wave.py to get the file parameters.
Here's the new test_wav() in its entirety:
--------------------------------
def test_wav(h, f):
import wave
# 'RIFF' <len> 'WAVE' 'fmt ' <len>
if h[:4] != 'RIFF' or h[8:12] != 'WAVE' or h[12:16] != 'fmt ':
return None
f.seek(0)
try:
w = wave.openfp(f, 'r')
except (EOFError, wave.Error):
return None
return ('wav', w.getframerate(), w.getnchannels(), \
w.getnframes(), 8*w.getsampwidth())
--------------------------------
If you want anything else, please ask.
Bob Pyle
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5024>
_______________________________________
More information about the Python-bugs-list
mailing list