1. Learn
  2. /
  3. Courses
  4. /
  5. Spoken Language Processing in Python

Exercise

Bytes to integers

You've seen how to import and read an audio file using Python's wave module and the readframes() method. But doing that results in an array of bytes.

To convert the bytes into something more useful, we'll use NumPy's frombuffer() method.

Passing frombuffer() our sound waves bytes and indicating a dtype of 'int16', we can convert our bytes to integers. Integers are much easier to work with than bytes.

The Python wave library has already been imported along with the good_morning.wav audio file.

Instructions

100 XP
  • Import the numpy package with its common alias np.
  • Open and read the good morning audio file.
  • Convert the signal_gm bytes to int16 integers.
  • View the first 10 sound wave values.