Last active
September 8, 2019 08:42
-
-
Save Korilakkuma/2b4404226abf84e964d1dc6e582ee8c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Safari は, ベンダープレフィックスが必要 | |
window.AudioContext = window.AudioContext || window.webkitAudioContext; | |
const audiocontext = new AudioContext(); | |
// Autoplay Policy 対策 | |
document.addEventListener('click', async () => { | |
if (audiocontext.state !== 'running') { | |
await audiocontext.resume(); | |
} | |
// Create the instance of `AudioNode` | |
const oscillator = audiocontext.createOscillator(); | |
const delay = audiocontext.createDelay(5); | |
// `OscillatorNode` -> `AudioDestinationNode` | |
oscillator.connect(audiocontext.destination); | |
// `OscillatorNode` -> `DelayNode` -> `AudioDestinationNode` | |
oscillator.connect(delay); | |
delay.connect(audiocontext.destination); | |
// `AudioParam` | |
delay.delayTime.value = 5; | |
// Immediate pronounce | |
oscillator.start(0); | |
// Stop after 1 sec | |
oscillator.stop(audiocontext.currentTime + 1); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment