Skip to content

Instantly share code, notes, and snippets.

@tassoevan
Created January 3, 2017 12:54
Show Gist options
  • Save tassoevan/f5a11e42595f5609f57d1132bf49a0cf to your computer and use it in GitHub Desktop.
Save tassoevan/f5a11e42595f5609f57d1132bf49a0cf to your computer and use it in GitHub Desktop.
Sinusoidal beep in JavaScript ES5
var audioCtx = new(window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
gainNode.gain.value = 1;
oscillator.frequency.value = 440;
oscillator.type = 'sine';
oscillator.start();
setTimeout(function() { oscillator.stop(); }, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment