-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWavFileHelper.py
More file actions
39 lines (27 loc) · 870 Bytes
/
WavFileHelper.py
File metadata and controls
39 lines (27 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
:author: Ryan Nicholas
:description: Wave Reader for sound
"""
import struct
class WavFileHelper():
def __init__(self):
"""
Initialize WavFileHelper
"""
pass
def read_file_properties(self, filename):
"""
Read wave function
:param filename: filename
:return: (num_channels, sample_rate, bit_depth)
"""
wave_file = open(filename, "rb")
riff = wave_file.read(12)
fmt = wave_file.read(36)
num_channels_string = fmt[10:12]
num_channels = struct.unpack('<H', num_channels_string)[0]
sample_rate_string = fmt[12:16]
sample_rate = struct.unpack('<I', sample_rate_string)[0]
bit_depth_string = fmt[22:24]
bit_depth = struct.unpack('<H', bit_depth_string)[0]
return (num_channels, sample_rate, bit_depth)