Skip to content

Instantly share code, notes, and snippets.

@hkitago
Last active August 1, 2018 05:18
Show Gist options
  • Save hkitago/7c2eb11f22922b2f57d2657b32940f35 to your computer and use it in GitHub Desktop.
Save hkitago/7c2eb11f22922b2f57d2657b32940f35 to your computer and use it in GitHub Desktop.
making beep sound.
const audioCtx = new(window.AudioContext || window.webkitAudioContext)();
const beep = function(){
if(settings.beep === 1) {
return false;
}
const volume = 0.1
, duration = 200
, type = 'square'
, frequency = 2000 /*1000*/;
const oscillator = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
gainNode.gain.value = volume;
oscillator.frequency.value = frequency;
oscillator.type = type;
oscillator.start();
setTimeout(function() {
oscillator.stop();
}, duration);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment