This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
* Some parts of this feature may have varying levels of support.
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. It's recommended to create one AudioContext and reuse it instead of initializing a new one each time, and it's OK to use a single AudioContext for several different audio sources and pipeline concurrently.
AudioContext()Creates and returns a new AudioContext object.
Also inherits properties from its parent interface, BaseAudioContext.
AudioContext.baseLatency Read only
Returns the number of seconds of processing latency incurred by the AudioContext passing the audio from the AudioDestinationNode to the audio subsystem.
AudioContext.outputLatency Read only
Returns an estimation of the output latency of the current audio context.
AudioContext.sinkId Read only Experimental Secure context
Returns the sink ID of the current output audio device.
Also inherits methods from its parent interface, BaseAudioContext.
AudioContext.close()Closes the audio context, releasing any system audio resources that it uses.
AudioContext.createMediaElementSource()Creates a MediaElementAudioSourceNode associated with an HTMLMediaElement. This can be used to play and manipulate audio from <video> or <audio> elements.
AudioContext.createMediaStreamSource()Creates a MediaStreamAudioSourceNode associated with a MediaStream representing an audio stream which may come from the local computer microphone or other sources.
AudioContext.createMediaStreamDestination()Creates a MediaStreamAudioDestinationNode associated with a MediaStream representing an audio stream which may be stored in a local file or sent to another computer.
AudioContext.createMediaStreamTrackSource()Creates a MediaStreamTrackAudioSourceNode associated with a MediaStream representing an media stream track.
AudioContext.getOutputTimestamp()Returns a new AudioTimestamp object containing two audio timestamp values relating to the current audio context.
AudioContext.resume()Resumes the progression of time in an audio context that has previously been suspended/paused.
AudioContext.setSinkId() Experimental Secure context
Sets the output audio device for the AudioContext.
AudioContext.suspend()Suspends the progression of time in the audio context, temporarily halting audio hardware access and reducing CPU/battery usage in the process.
sinkchange Experimental
Fired when the output audio device (and therefore, the AudioContext.sinkId) has changed.
Basic audio context declaration:
const audioCtx = new AudioContext(); const oscillatorNode = audioCtx.createOscillator(); const gainNode = audioCtx.createGain(); const finish = audioCtx.destination; // etc.
| Specification |
|---|
| Web Audio API> # AudioContext> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
AudioContext |
35["Before Chrome 66, each tab is limited to 6 audio contexts in Chrome; attempting to create more will throw aDOMException. For details see Per-tab audio context limitation in Chrome.", "If latencyHint isn't valid, Chrome throws a TypeError exception. See Non-standard exceptions in Chrome for details."] |
12 | 25 |
22["Before Opera 53, each tab is limited to 6 audio contexts in Opera; attempting to create more will throw aDOMException. For details see Per-tab audio context limitation in Chrome.", "If latencyHint isn't valid, Opera throws a TypeError exception. See Non-standard exceptions in Chrome for details."] |
14.1New audio contexts are suspended until theresume() method is called via user action, such as the click event. |
35["Before Chrome Android 66, each tab is limited to 6 audio contexts in Chrome Android; attempting to create more will throw aDOMException. For details see Per-tab audio context limitation in Chrome Android.", "If latencyHint isn't valid, Chrome Android throws a TypeError exception. See Non-standard exceptions in Chrome Android for details."] |
25 |
22["Before Opera Android 47, each tab is limited to 6 audio contexts in Opera; attempting to create more will throw aDOMException. For details see Per-tab audio context limitation in Chrome.", "If latencyHint isn't valid, Opera throws a TypeError exception. See Non-standard exceptions in Chrome for details."] |
14.5New audio contexts are suspended until theresume() method is called via user action, such as the click event. |
3.0["Before Samsung Internet 9.0, each tab is limited to 6 audio contexts in Samsung Internet; attempting to create more will throw aDOMException. For details see Per-tab audio context limitation in Chrome.", "If latencyHint isn't valid, Samsung Internet throws a TypeError exception. See Non-standard exceptions in Chrome for details."] |
37["Before WebView Android 66, each tab is limited to 6 audio contexts in WebView Android; attempting to create more will throw aDOMException. For details see Per-tab audio context limitation in WebView Android.", "If latencyHint isn't valid, WebView Android throws a TypeError exception. See Non-standard exceptions in WebView Android for details."] |
14.5New audio contexts are suspended until theresume() method is called via user action, such as the click event. |
AudioContext |
3514–57 | 12 | 25 | 2215–44 | 14.16–14.1 | 3518–57 | 25 | 2214–43 | 14.56–14.5 | 3.01.0–7.0 | 374.4–57 | 14.56–14.5 |
baseLatency |
58 | 79 | 70 | 45 | 14.1 | 58 | 79 | 43 | 14.5 | 7.0 | 58 | 14.5 |
close |
42 | 14 | 40 | 29 | 9 | 42 | 40 | 29 | 9 | 4.0 | 42 | 9 |
createMediaElementSource |
15 | 12 | 25If a sample rate is specified for the audio context, it must match the sample rate of the stream, otherwise this method will fail. |
15 | 6 | 18 | 25If a sample rate is specified for the audio context, it must match the sample rate of the stream, otherwise this method will fail. |
14 | 6 | 1.0 | 4.4 | 6 |
createMediaStreamDestination |
25 | 79 | 25 | 15 | 11 | 25 | 25 | 14 | 11 | 1.5 | 4.4 | 11 |
createMediaStreamSource |
22 | 12 | 25 | 15 | 11 | 25 | 25 | 14 | 11 | 1.5 | 4.4 | 11 |
createMediaStreamTrackSource |
No | No | 68Firefox 68 implements the updated standard's definition of the "first" audio track; now the first track is the one whose ID comes first lexicographically. |
No | No | No | 68Firefox for Android 68 implements the updated standard's definition of the "first" audio track; now the first track is the one whose ID comes first lexicographically. |
No | No | No | No | No |
error_event |
128 | 128 | No | 114 | No | 128 | No | 85 | No | 28.0 | 128 | No |
getOutputTimestamp |
57 | 79 | 70 | 44 | 14.1 | 57 | 79 | 43 | 14.5 | 7.0 | 57 | 14.5 |
outputLatency |
102 | 102 | 70 | 88 | 18.4 | 102 | 79 | 70 | 18.4 | 19.0 | 102 | 18.4 |
resume |
41 | 14 | 40 | 28 | 9 | 41 | 40 | 28 | 9 | 4.0 | 41 | 9 |
setSinkId |
110 | 110 | No | 96 | No | 110 | No | 74 | No | 21.0 | 110 | No |
sinkId |
110 | 110 | No | 96 | No | 110 | No | 74 | No | 21.0 | 110 | No |
sinkchange_event |
110 | 110 | No | 96 | No | 110 | No | 74 | No | 21.0 | 110 | No |
suspend |
41 | 14 | 40 | 28 | 9 | 41 | 40 | 28 | 9 | 4.0 | 41 | 9 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioContext