Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def readfile(file_name):
- music_file = wave.open(file_name, 'rb')
- type_channel = music_file.getnchannels()
- sample_rate = music_file.getframerate()
- sample_width = music_file.getsampwidth()
- num_frames = music_file.getnframes()
- raw_data = music_file.readframes(num_frames ) # Returns byte data
- music_file.close()
- ## Formating raw_data into Integer data
- num_samples = num_frames * type_channel
- if sample_width == 1:
- fmt = "%iB" % num_samples # read unsigned chars
- elif sample_width == 2:
- fmt = "%ih" % num_samples # read signed 2 byte shorts
- else:
- raise ValueError("Only supports 8 and 16 bit audio formats.")
- formated_data = list(struct.unpack(fmt,raw_data))
- return formated_data
Advertisement
Add Comment
Please, Sign In to add comment