Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created December 19, 2019 12:05
Show Gist options
  • Save gkucmierz/97a36a8ccdb37557cac6af847745e3be to your computer and use it in GitHub Desktop.
Save gkucmierz/97a36a8ccdb37557cac6af847745e3be to your computer and use it in GitHub Desktop.
play sine wave in browser
// play sine wave in browser
const sound = (() => {
return {
play: (duration = 1e3) => {
const context = new AudioContext();
const o = context.createOscillator();
o.type = 'sine';
o.connect(context.destination);
o.start();
setTimeout(() => o.stop(), duration);
}
};
})();
setInterval(sound.play, 2e3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment