Playing a sound in a ipython notebook

The previous answer is pretty old. You can use IPython.display.Audio now. Like this:

import IPython
IPython.display.Audio("my_audio_file.mp3")

Note that you can also process any type of audio content, and pass it to this function as a numpy array.

If you want to display multiple audio files, use the following:

IPython.display.display(IPython.display.Audio("my_audio_file.mp3"))
IPython.display.display(IPython.display.Audio("my_audio_file.mp3"))

A small example that might be relevant : http://nbviewer.ipython.org/5507501/the%20sound%20of%20hydrogen.ipynb

it should be possible to avoid gooing through external files by base64 encoding as for PNG/jpg...


The code:

import IPython

IPython.display.Audio("my_audio_file.mp3")

may give an error of "Invalid Source" in IE11, try in other browsers it should work fine.