Audio Module

This module contains functions for loading, saving, and playing WAV files (16-bit mono PCM files with variable bitrate). In particular, the following functions are available:

lib6003.audio.wav_file_play(fname)

Play audio from a WAV file on disk using wav_play. REQUIRES PYAUDIO.

Arguments:
  • fname: a string containing a file name of the WAV file to be written.

lib6003.audio.wav_play(samples, fs)

Play WAV data from a Python object and a sampling rate. REQUIRES PYAUDIO.

Arguments:
  • samples: a Python list of numbers in the range [-1, 1], one for each

    sample in the output WAV file. Numbers in the list that are outside this range will be clipped to -1 or 1.

  • fs: an integer representing the sampling rate of the output

    (samples/second).

lib6003.audio.wav_read(fname)

Read a wave file. This will always convert to mono.

Arguments:
  • fname: a string containing a file name of a WAV file.

Returns a tuple with 2 elements:
  • a 1-dimensional NumPy array with floats in the range [-1, 1] representing samples. the length of this array will be the number of samples in the given wave file.

  • an integer containing the sample rate

lib6003.audio.wav_write(samples, fs, fname)

Write a wave file.

Arguments:
  • samples: a Python list of numbers in the range [-1, 1], one for each

    sample in the output WAV file. Numbers in the list that are outside this range will be clipped to -1 or 1.

  • fs: an integer representing the sampling rate of the output

    (samples/second).

  • fname: a string containing a file name of the WAV file to be written.