I would like to be able to play a sound file in a ipython notebook. My aim is to be able to listen to the results of different treatments applied to a sound directly from within the notebook. Is this possible? If yes, what is the best solution to do so?
Playing a real sound Of course, we can also play back real recorded sounds in the same way. Your browser does not support the audio element.
python-sounddevice In order to play WAV files, numpy and soundfile need to be installed, to open WAV files as NumPy arrays. The line containing sf. read() extracts the raw audio data, as well as the sampling rate of the file as stored in its RIFF header, and sounddevice.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With