Web Audio API Intro Tutorial

With the Web Audio API, you can make sound in the browser.

I’m going to show you how to play a triangle wave.

1. Create the AudioContext

var context;

try {
 window.AudioContext = window.AudioContext||window.webkitAudioContext;
 context = new AudioContext();
catch(e) {
     alert('Web Audio API is not supported in this browser :-(');

2. Create an oscillator

var oscillator = context.createOscillator();
oscillator.type = 'triangle'; //Other types: sine, square, sawtooth
oscillator.frequency.value = 200;
oscillator.start(0);  //start playing sound after 0 seconds

You can stop the sound with oscillator.stop();

My next tutorial will explain how to create a basic step sequencer. Stay tuned.