javascript实现蜂鸣器beep效果
a=new AudioContext() // browsers limit the number of concurrent audio contexts, so you better re-use'em
function beep(vol, freq, duration){
v=a.createOscillator()
u=a.createGain()
v.connect(u)
v.frequency.value=freq
v.type="square"
u.connect(a.destination)
u.gain.value=vol*0.01
v.start(a.currentTime)
v.stop(a.currentTime+duration*0.001)
}
调用:
beep(100, 520, 200)高频beep
beep(999, 220, 300)低频boop
beep(999, 210, 800); beep(999, 500, 800);长报警Cool noise
原文