Skip to content

Audio

marimo.audio

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

Render an audio file as HTML.

PARAMETER DESCRIPTION
src

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]).

TYPE: Union[str, BytesIO, NDArray[Any]]

rate

Sampling rate (required only for NumPy arrays).

DEFAULT: None

normalize

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.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Html

An audio player as an Html object.

Example
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")