The AudioContext
interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode
. An audio context controls both the creation of the nodes it contains and the execution of the audio processing, or decoding. You need to create an AudioContext before you do anything else, as everything happens inside a context.
An AudioContext
can be a target of events, therefore it implements the EventTarget
interface.
AudioContext()
AudioContext
object.AudioContext.currentTime
Read only
0
.AudioContext.destination
Read only
AudioDestinationNode
representing the final destination of all audio in the context. It can be thought of as the audio-rendering device.AudioContext.listener
Read only
AudioListener
object, used for 3D spatialization.AudioContext.sampleRate
Read only
AudioContext
cannot be changed.AudioContext.state
Read only
AudioContext
.AudioContext.mozAudioChannelType
Read only
AudioContext
will play in, on a Firefox OS device.AudioContext.onstatechange
statechange
has fired. This occurs when the AudioContext
's state changes, due to the calling of one of the state change methods (AudioContext.suspend
, AudioContext.resume
, or AudioContext.close
).Also implements methods from the interface EventTarget
.
AudioContext.close()
AudioContext.createBuffer()
AudioBuffer
object, which can then be populated by data and played via an AudioBufferSourceNode
.AudioContext.createConstantSource()
ConstantSourceNode
object, which is an audio source that continuously outputs a monaural (one-channel) sound signal whose samples all have the same value.AudioContext.createBufferSource()
AudioBufferSourceNode
, which can be used to play and manipulate audio data contained within an AudioBuffer
object. AudioBuffer
s are created using AudioContext.createBuffer
or returned by AudioContext.decodeAudioData
when it successfully decodes an audio track.AudioContext.createMediaElementSource()
MediaElementAudioSourceNode
associated with an HTMLMediaElement
. This can be used to play and manipulate audio from <video>
or <audio>
elements.AudioContext.createMediaStreamSource()
MediaStreamAudioSourceNode
associated with a MediaStream
representing an audio stream which may come from the local computer microphone or other sources.AudioContext.createMediaStreamDestination()
MediaStreamAudioDestinationNode
associated with a MediaStream
representing an audio stream which may be stored in a local file or sent to another computer.AudioContext.createScriptProcessor()
ScriptProcessorNode
, which can be used for direct audio processing via JavaScript.AudioContext.createStereoPanner()
StereoPannerNode
, which can be used to apply stereo panning to an audio source.AudioContext.createAnalyser()
AnalyserNode
, which can be used to expose audio time and frequency data and for example to create data visualisations.AudioContext.createBiquadFilter()
BiquadFilterNode
, which represents a second order filter configurable as several different common filter types: high-pass, low-pass, band-pass, etc.AudioContext.createChannelMerger()
ChannelMergerNode
, which is used to combine channels from multiple audio streams into a single audio stream.AudioContext.createChannelSplitter()
ChannelSplitterNode
, which is used to access the individual channels of an audio stream and process them separately.AudioContext.createConvolver()
ConvolverNode
, which can be used to apply convolution effects to your audio graph, for example a reverberation effect.AudioContext.createDelay()
DelayNode
, which is used to delay the incoming audio signal by a certain amount. This node is also useful to create feedback loops in a Web Audio API graph.AudioContext.createDynamicsCompressor()
DynamicsCompressorNode
, which can be used to apply acoustic compression to an audio signal.AudioContext.createGain()
GainNode
, which can be used to control the overall volume of the audio graph.AudioContext.createIIRFilter()
IIRFilterNode
, which represents a second order filter configurable as several different common filter types.AudioContext.createOscillator()
OscillatorNode
, a source representing a periodic waveform. It basically generates a tone.AudioContext.createPanner()
PannerNode
, which is used to spatialise an incoming audio stream in 3D space.AudioContext.createPeriodicWave()
PeriodicWave
, used to define a periodic waveform that can be used to determine the output of an OscillatorNode
.AudioContext.createWaveShaper()
WaveShaperNode
, which is used to implement non-linear distortion effects.AudioContext.createAudioWorker()
AudioWorkerNode
, which can interact with a web worker thread to generate, process, or analyse audio directly. This was added to the spec on August 29 2014, and is not implemented in any browser yet.AudioContext.decodeAudioData()
ArrayBuffer
. In this case, the ArrayBuffer is usually loaded from an XMLHttpRequest
's response
attribute after setting the responseType
to arraybuffer
. This method only works on complete files, not fragments of audio files.AudioContext.resume()
AudioContext.suspend()
AudioContext.createJavaScriptNode()
JavaScriptNode
, used for direct audio processing via JavaScript. This method is obsolete, and has been replaced by AudioContext.createScriptProcessor()
.AudioContext.createWaveTable()
WaveTableNode
, used to define a periodic waveform. This method is obsolete, and has been replaced by AudioContext.createPeriodicWave()
.Basic audio context declaration:
var audioCtx = new AudioContext();
Cross browser variant:
var AudioContext = window.AudioContext || window.webkitAudioContext; var audioCtx = new AudioContext(); var oscillatorNode = audioCtx.createOscillator(); var gainNode = audioCtx.createGain(); var finish = audioCtx.destination; // etc.
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'AudioContext' in that specification. | Working Draft |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 10.0webkit 35 | (Yes) | 25.0 (25.0) | No support | 15.0webkit 22 | 6.0webkit |
createStereoPanner() | 42.0 | (Yes) | 37.0 (37.0) | No support | No support | No support |
onstatechange , state , suspend() , resume()
| (Yes) | (Yes) | 40.0 (40.0) | No support | No support | No support |
createConstantSource() | 56.0 | No support | 52 (52) | No support | 43 | No support |
Unprefixed | (Yes) | (Yes) |
Feature | Android Webview | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 37.0 (37.0) | 2.2 | No support | (Yes) | No support | (Yes) |
createStereoPanner() | 42.0 | (Yes) | (Yes) | (Yes) | No support | No support | No support | 42.0 |
onstatechange , state , suspend() , resume()
| (Yes) | (Yes) | (Yes) | (Yes) | No support | No support | No support | (Yes) |
createConstantSource() | 56.0 | No support | 52.0 (52) | No support | No support | No support | No support | 56.0 |
Unprefixed | (Yes) | (Yes) | ? | ? | ? | 43 | ? | (Yes) |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioContext