AudioBits is currently tested in Chromium-based browsers. Other browsers are not yet verified.
Lightsaber
Ignite a living electrical blade. Swing through the field. Strike, spark, retract.
Add to project
npx shadcn@latest add joacod/audiobits/lightsaberAdds editable source and the audiobits runtime dependency. Installation guide
Installs the catalog defaults and sound controller. The website visuals and input system stay in the showcase.
Use this sound
Use in src/integration.ts. Call play() from a user gesture and handle activation errors. Connect updates to application state; stop on cancellation or hiding, and dispose on removal.
import { createAudio } from "audiobits";
import { createLightsaber } from "./sounds/experiences/lightsaber/controller";
const audio = createAudio();
const blade = createLightsaber(audio);
let request = 0;
export async function play() {
const token = ++request;
await audio.start();
if (token !== request) return;
blade.ignite();
}
export function update(value: number, elapsed = 16, direction = 0) {
blade.update(value, elapsed, direction);
}
// Connect your application collision event; force [0, 1], pan [-1, 1].
export function strike(force = 0.8, pan = 0) {
return blade.clash(force, pan);
}
export function retract() {
request++;
blade.retract();
}
export function stop() {
request++;
blade.stop();
}
export async function dispose() {
stop();
blade.dispose();
await audio.dispose();
}
Production lifecycleCustomize or inspect
Connect your application's state and events to the sound controller. The full showcase source includes the browser host, input, and visuals.
View complete public source