Skip to content

JS/SevelteKit

scan 소리내기

Author
siwon
Date
2024-02-16 02:47
Views
477

https://odino.org/emit-a-beeping-sound-with-javascript/

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)


}

<button style="width: 30%; height: 150px; font-size: 2em" onclick="beep(100, 520, 200)">Beep</button>