Audio demos

In this Notebook, we show a couple of ways of working with audio data. This includes both playing the audio as well as working with the raw audio data as NumPy arrays.

Working with audio data

First, we show how the Audio class can be used to play raw audio data in a NumPy array.

In [2]:
from audiodisplay import Audio
In [3]:
%pylab inline
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

Here we create a simple signal at A (440 Hz):

In [54]:
max_time = 3
f = 440.0
rate = 44100.0
times = np.arange(max_time*rate)/rate
signal = 2.0**16*np.sin(2*pi*f*times)/2.0
signal = signal.astype(np.int16)

The signal looks as you might expect:

In [58]:
[<matplotlib.lines.Line2D at 0x111da2a10>]

We can simply pass the NumPy array and the sampling rate to the Audio object to get an HTML5 audio widget. This widget and audio data will be embedded in the notebook so the audio can be played back later.

In [57]:
Audio(data=signal, rate=rate)

Working with a .wav file

Second, we show how to load audio data from a .wav file. Here we have a 5 second clip from J.S. Bach's Cello Suite #3 in C.

In [4]:
filename = 'data/Bach Cello Suite #3.wav'
In [5]: