I've been trying to short beep for a notification on website but google autoplay policy change does not allow me to do so what should I do. I've seen so many sites still doing this like facebook chat etc.
I've tried this with no success (also tried with element):
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(vol, freq, duration);
The problem is that autoplay sound will be blocked under some circumstance according to the autoplay policy of Chrome.
Autoplay with sound is allowed if:
See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio for more details.