Quick start
Install AudioBits from npm and play a procedural sound from a user gesture.
AudioBits API · 0.2.0 · Available on npm.
Install AudioBits from npm:
npm install audiobitsPlay a tone
Create the engine and definition without allocating browser audio. Call play()
directly from your button's click handler and report rejected promises to the user.
Retry a failed start with a fresh Play gesture.
import { createAudio, defineSound } from "audiobits";
const recipe = defineSound({
schemaVersion: 1,
kind: "one-shot",
duration: 0.15,
layers: [
{
id: "tone",
source: { type: "oscillator", waveform: "sine", frequency: 660 },
gainDb: -18,
envelope: { attack: 0.004, decay: 0.08, sustain: 0.1, release: 0.04 },
},
],
});
const audio = createAudio();
const sound = audio.sound(recipe);
export async function play() {
await audio.start();
sound.play();
}
export function stop() {
audio.stopAll({ tails: "cut" });
}
export async function dispose() {
await audio.dispose();
}Bind play() to your button click and surface failures with
void play().catch(showError). For hiding, SPA navigation, suspension and disposal,
bind stop() to Stop and await dispose() when removing the host.
See Production lifecycle. The catalog never plays on load.
Next
- Listen and adjust the eight catalog sounds.
- Recipes: validated JSON and supported fields.
- Playback and lifecycle: sound versus voice, Stop, and teardown.
- Parameters: controls, smoothing, and seeded replay.
- Buses and routing: named routes, gain, and mute.
- Native interop: caller-owned analyser taps.
- API reference: public exports and limits.
Browser verification target: current Chromium. Other browsers and operating systems are unverified and deliberately deferred. The maintainer reported manual sound-quality acceptance for the current eight sounds on 2026-10-07; automated signals do not establish audible quality. Output devices and detailed listening coverage were not specified.