Skip to main content
Render an audio file as HTML.

Usage

mo.audio(
    src="https://upload.wikimedia.org/wikipedia/commons/8/8c/Ivan_Ili%C4%87-Chopin_-_Prelude_no._1_in_C_major.ogg"
)
mo.audio(src="path/to/local/file.wav")

Signature

mo.audio(
    src: Union[str, io.BytesIO, NDArray[Any]],
    rate: Optional[int] = None,
    normalize: bool = True
) -> Html

Parameters

src
Union[str, io.BytesIO, NDArray[Any]]
required
A path or URL to an audio file, bytes, or a file-like object opened in binary mode, 1D numpy array → Mono waveform, 2D numpy array → Multi-channel waveform (Shape: [NCHAN, NSAMPLES]).
rate
Optional[int]
default:"None"
Sampling rate (required only for NumPy arrays).
normalize
bool
default:"True"
Whether to rescale NumPy array audio to its max range (True by default). If False, values must be in [-1, 1], or an error is raised. Does not apply to non-array audio sources.

Returns

Html
An audio player as an Html object.

Supported Input Types

The src parameter accepts:
  • str: Path or URL to an audio file
  • bytes: Audio data as bytes
  • io.BytesIO: File-like object in binary mode
  • io.BufferedReader: Buffered file reader
  • numpy.ndarray: 1D array for mono or 2D array for multi-channel audio
For numpy arrays:
  • 1D array: Mono waveform
  • 2D array: Multi-channel waveform with shape [NCHAN, NSAMPLES]
  • You must specify the rate parameter when using numpy arrays

Build docs developers (and LLMs) love