mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +00:00
#5024: whichhdr now returns the frame count for WAV files.
Patch by Ned Jackson Lovely based on a suggestion by Robert Pyle.
This commit is contained in:
parent
052ddb01b3
commit
1a48b9dd7d
4 changed files with 13 additions and 6 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue