var context = new (window.AudioContext || window.webkitAudioContext)(); var osc = context.createOscillator(); var vol = context.createGain(); osc.type = 'sawtooth'; // sine,square, sawtooth, triangle osc.frequency.value = 140; // Hz osc.connect(vol); vol.gain.value = 0.4; // from 0 to 1, 1 full volume, 0 is muted vol.connect(context.destination); osc.start(context.currentTime); osc.stop(context.currentTime + .9); // stop x seconds after the current time