Skip to content

Basic Playback

Generate a synthesized tone or load an audio file to try waa-play’s basic playback features.

  • Sound generation (sine wave, white noise, click) or file loading
  • Waveform display and seeking
  • Play / Pause / Stop
  • Volume, pan, speed, and loop controls

Sound Source

Generate a synthesized tone or load an audio file to get started.

or

Code Examples

WaaPlayer API

import { WaaPlayer } from "waa-play";
const player = new WaaPlayer();
const buffer = player.createSineBuffer(440, 2);
const gain = player.createGain(0.8);
const panner = player.createPanner(0);
const playback = player.play(buffer, {
through: [gain, panner],
loop: true,
});
playback.on("timeupdate", ({ position, duration }) => {
console.log(`${position.toFixed(1)}s / ${duration.toFixed(1)}s`);
});
playback.pause();
playback.resume();
playback.seek(1.0);
playback.setPlaybackRate(1.5);
playback.stop();
player.dispose();

Function API (BYO AudioContext)

import { WaaPlayer } from "waa-play";
const ctx = new AudioContext({ sampleRate: 48000 });
const player = new WaaPlayer(ctx);
const buffer = await player.load("/drums.mp3");
const gain = player.createGain(0.8);
const comp = player.createCompressor({ ratio: 4 });
const a = player.play(buffer, { through: [gain, comp] });
a.on("ended", () => {
player.play(buffer, { through: [gain, comp] });
});
player.dispose();
ctx.close();