2 var audioCtx
= new window
.AudioContext
;
3 function beep(duration
, frequency
, volume
, type
, callback
) {
4 var oscillator
= audioCtx
.createOscillator();
5 var gainNode
= audioCtx
.createGain();
7 oscillator
.connect(gainNode
);
8 gainNode
.connect(audioCtx
.destination
);
10 if (volume
){gainNode
.gain
.value
= volume
;}
11 if (frequency
){oscillator
.frequency
.value
= frequency
;}
12 if (type
){oscillator
.type
= type
;}
13 if (callback
){oscillator
.onended
= callback
;}
15 oscillator
.start(audioCtx
.currentTime
);
16 oscillator
.stop(audioCtx
.currentTime
+ ((duration
|| 500) / 1000));