Skip to content

Web Audio API

In one line

The Web Audio API is a graph-based system for generating, processing, and playing audio entirely in the browser.

In simple words

The Web Audio API lets you synthesize, process, and play audio in JavaScript. You build a routing graph of AudioNodes: a source (oscillator, audio file, microphone) connects through effect nodes (gain, filter, delay, reverb) to a destination (the speakers). The browser processes the audio in real time on a separate thread.

This enables synthesizers, audio visualizers, games with dynamic sound, music apps, and voice changers — all without audio files. You create an AudioContext, build nodes, connect them with connect(), and start sources. Parameters can be automated over time with setValueAtTime and linearRampToValueAtTime for smooth transitions.

For simple playback, the HTML <audio> element is easier. Reach for the Web Audio API when you need real-time processing, synthesis, effects, precise scheduling, or visualization (an AnalyserNode gives frequency and time-domain data).

Example

javascript
const ctx = new AudioContext();

// Build a graph: oscillator → gain → speakers
const osc = ctx.createOscillator();
osc.type = "sine";
osc.frequency.value = 440; // A4 note

const gain = ctx.createGain();
gain.gain.value = 0.2;

osc.connect(gain).connect(ctx.destination);
osc.start();
// Plays a 440Hz sine tone at 20% volume

An oscillator generates a sine wave at 440Hz. A gain node scales the volume. The chain connects to the speakers (destination).

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary