viser-audio
Audio for viser scenes: play clips from Python, spatialize them from a scene node, and stream samples to the browser while they play.
viser-audio installs alongside viser -- it is not a fork. It injects a small Web Audio runtime into viser's stock client, so nothing else about your setup changes.
Install
pip install viser-audio
Usage
import numpy as np
import viser
import viser_audio
server = viser.ViserServer()
audio = viser_audio.AudioApi(server)
sample_rate = 44100
t = np.arange(sample_rate) / sample_rate
clip = audio.add(
"/speaker",
0.3 * np.sin(2 * np.pi * 220 * t),
sample_rate,
loop=True,
positional=True,
)
clip.play()
clip.position = (1.0, 0.0, 0.0) # The sound follows the scene node.
clip.volume = 0.5
server.sleep_forever()
API
AudioApi(server)-- installs the browser runtime; idempotent per server.AudioApi.add(name, samples, sample_rate=44100, *, volume, loop, positional, wxyz, position) -> AudioHandle-- adds a clip on the scene nodename. Samples are(N,)mono or(N, C); floats in [-1, 1], integers normalized.AudioHandle.play(offset=None)/.pause()--offsetseeks;Noneresumes (a finished clip restarts from the beginning).AudioHandle.append(chunk)-- extends the clip without interrupting playback, for streaming.AudioHandle.samples/.duration/.volume/.loop/.positional/.position/.wxyz-- read and write; assigningsamplesreplaces the clip, togglingpositionalpreserves the playhead.AudioHandle.remove()-- removes the clip and its scene node.
Audio state is replayed to clients that join later, so a clip left playing also starts for new browser tabs.
Autoplay
Browsers refuse to start audio before the page sees a user gesture. If a clip is asked to play first, the client shows an "Audio is waiting" notification and playback starts on the first click or keypress.
Development
uv sync --group dev
uv run ruff check . && uv run ruff format --check . && uv run pyright
uv run pytest tests --ignore=tests/e2e
# End-to-end tests drive a real browser.
uv run playwright install chromium
uv run pytest tests/e2e
The browser runtime is TypeScript in src/viser_audio/client, bundled by
esbuild into the checked-in src/viser_audio/runtime.js:
cd src/viser_audio/client
npm ci
npm run typecheck
npm run build # rewrites ../runtime.js; commit it
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file viser_audio-0.0.2.tar.gz.
File metadata
- Download URL: viser_audio-0.0.2.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d515c191df5d699671b2e12fad4583eb80d7f3131f193bc0f9bee75016efde9
|
|
| MD5 |
a2b671b0a605154bfc02bd51c44539ab
|
|
| BLAKE2b-256 |
28fe33a4d33f371eb3728666e9d0728c4e75b702ecd7df4c30b0d434437ad211
|
File details
Details for the file viser_audio-0.0.2-py3-none-any.whl.
File metadata
- Download URL: viser_audio-0.0.2-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75da22d351e7b21c825786571965755924d65fa7de94c7c1256d8da329eebe70
|
|
| MD5 |
71c110c36ef7a21072737f07755e5399
|
|
| BLAKE2b-256 |
3aa831f1d535aca366bca7fe2efb613110e8c20d6f9dbacd99438b449b6a3135
|