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)
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.
Synthesize and play a tone
A one-second 440 Hz sine, generated and played through your speakers.
Browsers block audio that starts on its own, so if it doesn't play automatically, click the ▶ Play button the widget shows.
Stereo works too
play() accepts (n_frames, n_channels). Here the two ears differ by 2 Hz, so you hear a slow binaural beat.
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().