Tutorial by Examples

In this example we show how to generate a simple sine wave, and output it on the user's speakers/headphones. let audioContext = new (window.AudioContext || window.webkitAudioContext)(); let sourceNode = audioContext.createOscillator(); sourceNode.type = 'sine'; sourceNode.frequency.value = 261...
Effects can be applied to audio by chaining nodes between the source and the destination node. In this example we use a gain node to mute the source, and only let sound through at specific times. This allows us to create morse code. function morse(gainNode, pattern) { let silenceTimeout = 300; ...
In order to record audio from a user's microphone, we must first gain permission from the user to access the device: navigator.mediaDevices.getUserMedia({ audio: true }) .then(successCallback) .catch(failureCallback); On success, our successCallback will be called with a MediaStream ob...
To play audio using the Web Audio API, we need to get an ArrayBuffer of audio data and pass it to a BufferSource for playback. To get an audio buffer of the sound to play, you need to use the AudioContext.decodeAudioData method like so: const audioCtx = new (window.AudioContext || window.webkitAud...
This example shows how to use two audio sources, and alter one of them based on the other. In this case we create an audio Ducker, that will lower the volume of the primary track if the secondary track produces sound. The ScriptProcessorNode will send regular events to its audioprocess handler. In ...
We start off by creating an audio context and then create an oscillator which is the easiest way to check that your setup works. (Example fiddle) // We can either use the standard AudioContext or the webkitAudioContext (Safari) var audioContext = (window.AudioContext || window.webkitAudioContext);...

Page 1 of 1