Code examples that accompany the MDN Web Audio documentation https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
The "audio-analyser" directory contains a very simple example showing a graph visualization of audio drawn with data taken from an AnalyserNode. Run the demo live.
The "audio-basics" directory contains a fun example showing a retro-style "boombox" that allows audio to be played, stereo panned, and volume adjusted. Run the demo live.
The "audio-buffer" directory contains a very simple example showing how to use an audio buffer in Web Audio API. Run the demo live.
The "audio-param" directory contains some simple examples showing how to use the methods of the Web Audio API AudioParam interface. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/AudioParam. Run example live.
The "audiocontext-states" directory contains a simple demo of the new Web Audio API AudioContext states, including the states property and the close()
, resume()
and suspend()
methods. See https://developer.mozilla.org/en-US/docs/Web/API/AudioContext for more details. Run the demo live.
The "compressor-example" directory contains a simple demo to show usage of the Web Audio API createDynamicsCompressor() method and DynamicCompressorNode. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createDynamicsCompressor. Run the example live.
The "create-media-stream-destination" directory contains a simple example showing how Web Audio API AudioContext.createMediaStreamDestination which can be used to output a stream, in this case to a MediaRecorder instance, to output a sinewave to an opus file. Run the demo live.
The "decode-audio-data" directory contains a simple example demonstrating usage of the Web Audio API decodeAudioData() method. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/decodeAudioData. View example live.
The "iirfilter-node" directory contains an example showing usage of an IIRFilterNode. Run the demo live.
The "media-source-buffer" directory contains a simple example demonstrating usage of the Web Audio API AudioContext.createMediaElementSource() method. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaElementSource or view the demo live.
The "offline-audio-context" directory contains a simple example to show how a Web Audio API OfflineAudioContext object can be used to rapidly process/render audio in the background to create a buffer, which can then be used in any way you please. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext. Run example live.
The "offline-audio-context-promise" directory contains a simple example to show how a Web Audio API OfflineAudioContext object can be used to rapidly process/render audio in the background to create a buffer, which can then be used in any way you please. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext/startRendering(promise). Run the example live.
The "panner-node" directory contains a demo to show basic usage of a Web Audio API PannerNode to control audio spatialisation. See https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPanner for more details. Run the example live.
The "script-processor-node" directory contains a simple demo showing how to use the Web Audio API's ScriptProcessorNode to process a loaded audio track, adding a little bit of white noise to each audio sample. For more information see ScriptProcessorNode documentation and the live demo.
The "step-sequencer" directory contains a simple step-sequencer that loops and manipulates sounds based on a dial-up modem. For more information see Advanced techniques: creating sound, sequencing, timing, scheduling. See the live demo also.
The "stereo-panner-node" directory contains a simple example to show how the Web Audio API StereoPannerNode can be used to pan an audio stream. See https://developer.mozilla.org/en-US/docs/Web/API/StereoPannerNode for more details. Run the example live.
The "stream-source-buffer" directory contains a simple example demonstrating usage of the Web Audio API AudioContext.createMediaElementSource() method. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamSource. View example live.