(Added on 2016/12/21) There was a function to do this in the standard IPython module, so I edited it a lot. Reference URL
In Jupyter, you can embed images by writing % matplotlib inline
.
However, it was not possible to embed an audio file so that it could be played.
To solve this, I wrote an article about embedding audio files with Jupyter in the following article. http://qiita.com/mzmttks/items/f4493efaa8b8c0a58a82 However, there remained a problem that multiple files could not be read and sound data could not be passed directly.
This article shows a standard IPython module that solves this problem and how to use it.
import IPython.display
IPython.display.Audio("sample.wav")
import IPython.display
IPython.display.display(IPython.display.Audio("sample1.wav"))
IPython.display.display(IPython.display.Audio("sample2.wav"))
import numpy
import IPython.display
# 440Hz
duration = 3
sin_1ch = numpy.sin(440 * 2 * numpy.pi * numpy.linspace(0, duration, duration * 16000))
IPython.display.Audio(sin_1ch, rate=16000)
import numpy
import IPython.display
# 440Hz, 220Hz
duration = 3
sin_2ch = [numpy.sin(440 * 2 * numpy.pi * numpy.linspace(0, duration, duration * 16000)),
numpy.sin(220 * 2 * numpy.pi * numpy.linspace(0, duration, duration * 16000))]
IPython.display.Audio(sin_2ch, rate=16000)
Recommended Posts