From 3c16509e747d8a085d42c4a31a5eaaced86466d4 2013-10-13 15:41:28 From: David Österberg Date: 2013-10-13 15:41:28 Subject: [PATCH] Add Audio display to the Rich display example notebook --- diff --git a/examples/notebooks/Part 5 - Rich Display System.ipynb b/examples/notebooks/Part 5 - Rich Display System.ipynb index cdea811..633d966 100644 --- a/examples/notebooks/Part 5 - Rich Display System.ipynb +++ b/examples/notebooks/Part 5 - Rich Display System.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "Part 5 - Rich Display System" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -500,6 +500,60 @@ "level": 2, "metadata": {}, "source": [ + "Audio" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "IPython makes it easy to work with sounds interactively. The `Audio` display class allows you to create an audio control that is embedded in the Notebook. The interface is analogous to the interface of the `Image` display class. All audio formats supported by the browser can be used. Note that no single format is presently supported in all browsers." + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from IPython.display import Audio\n", + "Audio(url=\"http://www.nch.com.au/acm/8k16bitpcm.wav\")" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A Numpy array can be auralized automatically. The Audio class normalizes and encodes the data and embed the result in the Notebook.\n", + "\n", + "For instance, when two sine waves with almost the same frequency are superimposed a phenomena known as [beats](https://en.wikipedia.org/wiki/Beat_%28acoustics%29) occur. This can be auralised as follows" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy as np\n", + "max_time = 3\n", + "f1 = 220.0\n", + "f2 = 224.0\n", + "rate = 44100.0\n", + "L = 3\n", + "times = np.linspace(0,L,rate*L)\n", + "signal = np.sin(2*np.pi*f1*times) + np.sin(2*np.pi*f2*times)\n", + "\n", + "Audio(data=signal, rate=rate)" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ "Video" ] }, @@ -1237,4 +1291,4 @@ "metadata": {} } ] -} +} \ No newline at end of file