thescoop
thescoop

Reputation: 514

import of Audio module not possible on iPython Notebook

I am struggling to get the following Audio example to work on In[7] of the following iPython notebook:

http://nbviewer.ipython.org/url/github.com/ipython/ipython/raw/master/examples/notebooks/Part%205%20-%20Rich%20Display%20System.ipynb

Running this code on my laptop:

from IPython.display import Audio
Audio(url="http://www.nch.com.au/acm/8k16bitpcm.wav")

I get this error message:

ImportError: cannot import name Audio

I have tried looking for the Audio module in the API (http://ipython.org/ipython-doc/stable/api/index.html ), but can’t find one.

I am running iPython notebook from a laptop which uses the Enthought Canopy package to make the default python and and iPython environment. From Canopy, I see that I am using ipython1.1.0-2 , but I see no reference to an ipython notebook version and I'm therefore assuming that this also refers to my notebook version?!

If anyone can help it would be most appreciated.

Regards, Scoop.

Upvotes: 1

Views: 2132

Answers (1)

Kyle Kelley
Kyle Kelley

Reputation: 14144

With the current version of IPython that you're using, IPython.display.Audio is unavailable.

For just that call, here's a monkey patch that will work on most browsers:

import IPython
from IPython import display

def audio(url):
  return display.HTML("<audio controls><source src='{}'></audio>".format(url))
IPython.display.Audio = audio

Results:

IPython audio

However, this isn't as fully featured as the Audio object slated for the next release. It will be able to take raw data and numpy arrays as well.

Upvotes: 3

Related Questions