defineSequence

Schedules a series of sounds over time. Returns a controller with play() and stop() methods. Uses a lookahead scheduler for sample-accurate timing, even in background tabs.

import { defineSequence } from "@web-kits/audio";

const seq = defineSequence([
  { sound: clickDef, at: 0 },
  { sound: popDef, at: 0.2 },
  { sound: chimeDef, at: 0.5 },
], { loop: false });

seq.play();
seq.stop();

Signature

function defineSequence(
  steps: SequenceStep[],
  options?: SequenceOptions
): { play: () => void; stop: () => void };

SequenceStep

PropertyTypeDescription
soundSoundDefinition | PlayFunctionSound to play, or a pre-built play fn
atnumberAbsolute time offset (seconds)
waitnumberDelay after previous step (seconds)
volumenumberPer-step volume override

Use at for absolute positioning or wait for relative timing. If both are provided, at takes priority.

SequenceOptions

PropertyTypeDefaultDescription
loopbooleanfalseRepeat after last step
durationnumber-Total sequence length (s)