[PYTHON] Embed audio data with Jupyter

(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
import IPython.display
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

Embed audio data with Jupyter
Create noise-filled audio data with SoX
Allow Jupyter Notebook to embed audio data in HTML tables for playback
Data analysis for improving POG 2 ~ Analysis with jupyter notebook ~
Interactively visualize data with TreasureData, Pandas and Jupyter.
Data analysis with python 2
Multiple selections with Jupyter
Candlestick with plotly + Jupyter
Visualize data with Streamlit
Reading data with TensorFlow
Data visualization with pandas
Data manipulation with Pandas!
Shuffle data with pandas
Data Augmentation with openCV
Normarize data with Scipy
Data analysis with Python
LOAD DATA with PyMysql
Use nim with Jupyter
Sample data created with python
Graph Excel data with matplotlib (1)
Artificial data generation with numpy
Using Graphviz with Jupyter Notebook
Extract Twitter data with CSV
Use pip with Jupyter Notebook
Get Youtube data with python
Clustering ID-POS data with LDA
Learn new data with PaintsChainer
Binarize photo data with OpenCV
Use Cython with Jupyter Notebook
Graph Excel data with matplotlib (2)
Play with Jupyter Notebook (IPython Notebook)
Save tweet data with Django
Try running Python with Try Jupyter
Switch virtual environment with jupyter
Server management with Jupyter (1) import
Data processing tips with Pandas
Interpolate 2D data with scipy.interpolate.griddata
Embed wav files in Jupyter
Read json data with python
Save & load data with joblib, pickle
Allow external connections with jupyter notebook
Formatting with autopep8 on Jupyter notebook
Until you start Jupyter with Docker
Visualize decision trees with jupyter notebook
Make a sound with Jupyter notebook
How to deal with imbalanced data
Try audio signal processing with librosa-Beginner
Easy Jupyter environment construction with Cloud9
How to deal with imbalanced data
[Python] Get economic data with DataReader
Embed your favorite HTML in Jupyter
Versatile data plotting with pandas + matplotlib
Python data structures learned with chemoinformatics
Install the data files with setup.py
Parse pcap data with tshark command
Use markdown with jupyter notebook (with shortcut)
Try running Jupyter with VS Code
How to Data Augmentation with PyTorch
Add more kernels with Jupyter Notebook
Convenient analysis with Pandas + Jupyter notebook
Easy data visualization with Python seaborn.