run_009

Untitled

Jan 23rd, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. def readfile(file_name):
  2. music_file = wave.open(file_name, 'rb')
  3. type_channel = music_file.getnchannels()
  4. sample_rate = music_file.getframerate()
  5. sample_width = music_file.getsampwidth()
  6. num_frames = music_file.getnframes()
  7.  
  8. raw_data = music_file.readframes(num_frames ) # Returns byte data
  9. music_file.close()
  10.  
  11. ## Formating raw_data into Integer data
  12.  
  13. num_samples = num_frames * type_channel
  14.  
  15. if sample_width == 1:
  16. fmt = "%iB" % num_samples # read unsigned chars
  17. elif sample_width == 2:
  18. fmt = "%ih" % num_samples # read signed 2 byte shorts
  19. else:
  20. raise ValueError("Only supports 8 and 16 bit audio formats.")
  21.  
  22. formated_data = list(struct.unpack(fmt,raw_data))
  23. return formated_data
Advertisement
Add Comment
Please, Sign In to add comment