Skip to content

Instantly share code, notes, and snippets.

@adamf
Created January 15, 2015 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamf/e30ece52f2c065fd90f6 to your computer and use it in GitHub Desktop.
Save adamf/e30ece52f2c065fd90f6 to your computer and use it in GitHub Desktop.
<html>
<body>
<script>
// use the HTML5 audio API to make a beep.
var context = new webkitAudioContext();
var volume = context.createGain();
volume.gain.value = 0.5;
volume.connect(context.destination);
var synth = context.createOscillator();
synth.connect(volume);
// I think 0 is the default type? Let’s see what we get.
synth.type = 0;
// Play an ‘A’ at 440Hz, the typical tone used to tune an instrument.
synth.frequency_value = 440;
// Actually play a note.
synth.noteOn(0);
// In 2 seconds, stop playing the note.
setTimeout(synth.noteOff, 2000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment