diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-03-18 21:42:42 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-03-18 21:42:42 (GMT) |
commit | 1a48b9dd7dacbb298da2632a5196190de01587bb (patch) | |
tree | 39f5345d03ffa9ef3346283b94a7f7e3527689b0 /Lib/sndhdr.py | |
parent | 052ddb01b37287c43ef595f6c8381a5eeb1dcb79 (diff) | |
download | cpython-1a48b9dd7dacbb298da2632a5196190de01587bb.zip cpython-1a48b9dd7dacbb298da2632a5196190de01587bb.tar.gz cpython-1a48b9dd7dacbb298da2632a5196190de01587bb.tar.bz2 |
#5024: whichhdr now returns the frame count for WAV files.
Patch by Ned Jackson Lovely based on a suggestion by Robert Pyle.
Diffstat (limited to 'Lib/sndhdr.py')
-rw-r--r-- | Lib/sndhdr.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/sndhdr.py b/Lib/sndhdr.py index 0a2fa8d..240e507 100644 --- a/Lib/sndhdr.py +++ b/Lib/sndhdr.py @@ -137,14 +137,17 @@ tests.append(test_voc) def test_wav(h, f): + import wave # 'RIFF' <len> 'WAVE' 'fmt ' <len> if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ': return None - 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 + 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()) tests.append(test_wav) |