AudioBits

Introduction and quick start

Choose a starting point, install the AudioBits runtime, and play your first procedural sound.

AudioBits API · 0.7.0 · Available on npm.

AudioBits generates procedural browser audio from recipes. Use the catalog to hear and adjust sounds and interactive experiences, then use these guides to bring them into your application.

The audiobits npm package is the audio runtime: it interprets recipe data and creates browser audio. The shadcn registry installs editable recipes and sound controllers into your project. Demo renderers stay in the showcase. Each item declares audiobits as an npm dependency, so installed source uses the same runtime as an original sound you write yourself.

Choose a starting point

Browse the live catalog for sounds to adapt, or see the runtime reference for public APIs. The agent guide also links to optional MCP tooling for complex workflows.

Install the runtime

For an original sound, install AudioBits directly with your project's package manager. This installs the runtime, not catalog source or the agent Skill.

npm install audiobits

Play a tone

Start audio from a user gesture

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);
let request = 0;

export async function play() {
  const token = ++request;
  await audio.start();
  if (token !== request) return;
  sound.play();
}
export function stop() {
  request++;
  audio.stopAll({ tails: "cut" });
}
export async function dispose() {
  stop();
  await audio.dispose();
}

Own the host lifecycle

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

Browser verification target: current Chromium. Other browsers and operating systems are unverified and deliberately deferred.

On this page