Skip to content

Instantly share code, notes, and snippets.

@thales17
Created September 4, 2019 18:55
Show Gist options
  • Save thales17/7759bffb9874fb4b7f1222cbd1474921 to your computer and use it in GitHub Desktop.
Save thales17/7759bffb9874fb4b7f1222cbd1474921 to your computer and use it in GitHub Desktop.
WebAudio Oscillator Example
<html>
<head>
</head>
<body>
<script type="text/javascript">
console.log("Hello, world");
// create web audio api context
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// create Oscillator node
var oscillator = audioCtx.createOscillator();
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(288, audioCtx.currentTime); // value in hertz
oscillator.connect(audioCtx.destination);
oscillator.start();
setTimeout(()=> {
oscillator.stop()
}, 5000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment