bundles / IPython 9.3.0 / IPython / lib / display / Audio
class
IPython.lib.display:Audio
source: /IPython/lib/display.py :17
Signature
class Audio ( data = None , filename = None , url = None , embed = None , rate = None , autoplay = False , normalize = True , * , element_id = None ) Members
-
__init__ -
_data_and_metadata -
_get_normalization_factor -
_make_wav -
_repr_html_ -
_validate_and_normalize_with_numpy -
_validate_and_normalize_without_numpy -
autoplay_attr -
element_id_attr -
reload -
src_attr
Summary
Create an audio object.
Extended Summary
When this object is returned by an input cell or passed to the display function, it will result in Audio controls being displayed in the frontend (only works in the notebook).
Parameters
data: numpy array, list, unicode, str or bytesCan be one of
Numpy 1d array containing the desired waveform (mono)
Numpy 2d array containing waveforms for each channel. Shape=(NCHAN, NSAMPLES). For the standard channel order, see http://msdn.microsoft.com/en-us/library/windows/hardware/dn653308(v=vs.85).aspx
List of float or integer representing the waveform (mono)
String containing the filename
Bytestring containing raw PCM data or
URL pointing to a file on the web.
If the array option is used, the waveform will be normalized.
If a filename or url is used, the format support will be browser dependent.
url: unicodeA URL to download the data from.
filename: unicodePath to a local file to load the data from.
embed: booleanShould the audio data be embedded using a data URI (True) or should the original source be referenced. Set this to True if you want the audio to playable later with no internet connection in the notebook.
Default is
True, unless the keyword argumenturlis set, then default value isFalse.rate: integerThe sampling rate of the raw data. Only required when data parameter is being used as an array
autoplay: boolSet to True if the audio should immediately start playing. Default is
False.normalize: boolWhether audio should be normalized (rescaled) to the maximum possible range. Default is
True. When set toFalse,datamust be between -1 and 1 (inclusive), otherwise an error is raised. Applies only whendatais a list or array of samples; other types of audio are never normalized.
Examples
import pytest np = pytest.importorskip("numpy")✓
import numpy as np framerate = 44100 t = np.linspace(0,5,framerate*5) data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t) Audio(data, rate=framerate)✓
dataleft = np.sin(2*np.pi*220*t) dataright = np.sin(2*np.pi*224*t) Audio([dataleft, dataright], rate=framerate)✓
See also
- ipywidgets.Audio
Audio widget with more more flexibility and options.
Aliases
-
IPython.display.Audio