Feature · Play

Play a NumPy buffer

play(samples, sample_rate) hands a float32 array to a main-thread AudioContext. No microphone needed — synthesize a buffer and hear it.

This page runs a real in-browser Python kernel (thebe + Pyodide) with the actual browseraudio package — so the cells below are the genuine API, just like JupyterLite / thebe. The cells are editable; the first Run downloads the runtime (~25 MB), so give it a moment. Reload to reset.

ready
01

Synthesize and play a tone

A one-second 440 Hz sine, generated and played through your speakers.

python
import numpy as np
from browseraudio import play

sr = 44100
t = np.linspace(0, 1, sr, endpoint=False)
tone = 0.2 * np.sin(2*np.pi*440*t).astype(np.float32)
play(tone, sr)

Browsers block audio that starts on its own, so if it doesn't play automatically, click the ▶ Play button the widget shows.

02

Stereo works too

play() accepts (n_frames, n_channels). Here the two ears differ by 2 Hz, so you hear a slow binaural beat.

python
left  = np.sin(2*np.pi*440*t)
right = np.sin(2*np.pi*442*t)        # 2 Hz apart
stereo = (0.2*np.stack([left, right], 1)).astype(np.float32)
play(stereo, sr)

Want to play your own voice? Record it first , then pass rec.samples to play().