mirror of
https://github.com/torappinfo/uweb.git
synced 2024-08-14 23:54:59 +00:00
20 lines
633 B
JavaScript
20 lines
633 B
JavaScript
|
//data:charset=utf-8,
|
||
|
var audioCtx = new window.AudioContext;
|
||
|
function beep(duration, frequency, volume, type, callback) {
|
||
|
var oscillator = audioCtx.createOscillator();
|
||
|
var gainNode = audioCtx.createGain();
|
||
|
|
||
|
oscillator.connect(gainNode);
|
||
|
gainNode.connect(audioCtx.destination);
|
||
|
|
||
|
if (volume){gainNode.gain.value = volume;}
|
||
|
if (frequency){oscillator.frequency.value = frequency;}
|
||
|
if (type){oscillator.type = type;}
|
||
|
if (callback){oscillator.onended = callback;}
|
||
|
|
||
|
oscillator.start(audioCtx.currentTime);
|
||
|
oscillator.stop(audioCtx.currentTime + ((duration || 500) / 1000));
|
||
|
};
|
||
|
beep();
|
||
|
self.close();
|