web api interface
BaseAudioContext
The BaseAudioContext interface of the Web Audio API acts as a base definition for online and offline audio-processing graphs, as represented by AudioContext and OfflineAudioContext respectively. You wouldn’t use BaseAudioContext directly — you’d use its features via one of these two inheriting interfaces.
A BaseAudioContext can be a target of events, therefore it implements the EventTarget interface.
Instance properties
audioWorkletRead only- : Returns the
AudioWorkletobject, which can be used to create and manageAudioNodes in which JavaScript code implementing theAudioWorkletProcessorinterface are run in the background to process audio data.
- : Returns the
currentTimeRead only- : Returns a double representing an ever-increasing hardware time in seconds used for scheduling. It starts at
0.
- : Returns a double representing an ever-increasing hardware time in seconds used for scheduling. It starts at
destinationRead only- : Returns an
AudioDestinationNoderepresenting the final destination of all audio in the context. It can be thought of as the audio-rendering device.
- : Returns an
listenerRead only- : Returns the
AudioListenerobject, used for 3D spatialization.
- : Returns the
sampleRateRead only- : Returns a float representing the sample rate (in samples per second) used by all nodes in this context. The sample-rate of an
AudioContextcannot be changed.
- : Returns a float representing the sample rate (in samples per second) used by all nodes in this context. The sample-rate of an
stateRead only- : Returns the current state of the
AudioContext.
- : Returns the current state of the
Instance methods
Also implements methods from the interface EventTarget.
createAnalyser()- : Creates an
AnalyserNode, which can be used to expose audio time and frequency data and for example to create data visualizations.
- : Creates an
createBiquadFilter()- : Creates a
BiquadFilterNode, which represents a second order filter configurable as several different common filter types: high-pass, low-pass, band-pass, etc
- : Creates a
createBuffer()- : Creates a new, empty
AudioBufferobject, which can then be populated by data and played via anAudioBufferSourceNode.
- : Creates a new, empty
createBufferSource()- : Creates an
AudioBufferSourceNode, which can be used to play and manipulate audio data contained within anAudioBufferobject.AudioBuffers are created usingAudioContext.createBuffer()or returned byAudioContext.decodeAudioData()when it successfully decodes an audio track.
- : Creates an
createConstantSource()- : Creates a
ConstantSourceNodeobject, which is an audio source that continuously outputs a monaural (one-channel) sound signal whose samples all have the same value.
- : Creates a
createChannelMerger()- : Creates a
ChannelMergerNode, which is used to combine channels from multiple audio streams into a single audio stream.
- : Creates a
createChannelSplitter()- : Creates a
ChannelSplitterNode, which is used to access the individual channels of an audio stream and process them separately.
- : Creates a
createConvolver()- : Creates a
ConvolverNode, which can be used to apply convolution effects to your audio graph, for example a reverberation effect.
- : Creates a
createDelay()- : Creates a
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.
- : Creates a
createDynamicsCompressor()- : Creates a
DynamicsCompressorNode, which can be used to apply acoustic compression to an audio signal.
- : Creates a
createGain()- : Creates a
GainNode, which can be used to control the overall volume of the audio graph.
- : Creates a
createIIRFilter()- : Creates an
IIRFilterNode, which represents a second order filter configurable as several different common filter types.
- : Creates an
createOscillator()- : Creates an
OscillatorNode, a source representing a periodic waveform. It basically generates a tone.
- : Creates an
createPanner()- : Creates a
PannerNode, which is used to spatialize an incoming audio stream in 3D space.
- : Creates a
createPeriodicWave()- : Creates a
PeriodicWave, used to define a periodic waveform that can be used to determine the output of anOscillatorNode.
- : Creates a
createScriptProcessor()Deprecated- : Creates a
ScriptProcessorNode, which can be used for direct audio processing via JavaScript.
- : Creates a
createStereoPanner()- : Creates a
StereoPannerNode, which can be used to apply stereo panning to an audio source.
- : Creates a
createWaveShaper()- : Creates a
WaveShaperNode, which is used to implement non-linear distortion effects.
- : Creates a
decodeAudioData()- : Asynchronously decodes audio file data contained in an
ArrayBuffer. In this case, theArrayBufferis usually loaded from anXMLHttpRequest’sresponseattribute after setting theresponseTypetoarraybuffer. This method only works on complete files, not fragments of audio files.
- : Asynchronously decodes audio file data contained in an
Events
Examples
const audioContext = new AudioContext();
const oscillatorNode = audioContext.createOscillator();
const gainNode = audioContext.createGain();
const finish = audioContext.destination;
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.