[PYTHON] Embed wav files in Jupyter

problem

You can embed videos in Jupyter, as you can see in the blogs below. http://jakevdp.github.io/blog/2013/05/12/embedding-matplotlib-animations/

I want to embed a sound file in the same way and play it from Jupyter.

Solution

Embed it in the same way as the above blog using HTML5 Audio elements.

Define a function like this

from IPython.display import HTML
def embedAudio(filename):
    tmpl = """
    <audio controls>
    <source src="data:audio/x-m4v;base64,{0}" type="audio/wav">
    """
    
    return HTML(tmpl.format(open(filename, "rb").read().encode("base64")))

If you execute it like this, you can embed it.

embedAudio("myaudio.wav")

However, only one per Cell.

Recommended Posts

Embed wav files in Jupyter
Embed your favorite HTML in Jupyter
Bash in Jupyter
Smartly embed atomic properties in SDF files
View Selenium screenshots in Jupyter without saving files
Jupyter in Cloud9 IDE
Automatically save .py and .html files in Jupyter notebook.
Embed audio data with Jupyter
Embed matplotlib graphs in Tkinter
Multiprocessing error in Jupyter Notebook
Settings often used in Jupyter
Search for strings in files
Upload multiple files in Flask
Transpose CSV files in Python Part 1
Set opset to embed in ONNX
Manipulate files and folders in Python
Generate Jupyter notebook ".ipynb" in Python
Handling of JSON files in Python
Download Google Drive files in Python
Sort large text files in Python
View graphs inline in Jupyter Notebook
Read files in parallel with Python
Bring files in Windows to WSL
Export and output files in Python
Extract strings from files in Python