Web/API/AudioContext/AudioContext

From Get docs


The AudioContext() constructor creates a new AudioContext object which represents an audio-processing graph, built from audio modules linked together, each represented by an AudioNode.

Syntax

var audioCtx = new AudioContext();
var audioCtx = new AudioContext(options);

Parameters

options Optional
An object based on the AudioContextOptions dictionary that contains zero or more optional properties to configure the new context. Available properties are as follows:
latencyHint Optional
The type of playback that the context will be used for, as a value from the AudioContextLatencyCategory enum or a double-precision floating-point value indicating the preferred maximum latency of the context in seconds. The user agent may or may not choose to meet this request; check the value of AudioContext.baseLatency to determine the true latency after creating the context.
sampleRate Optional
The sampleRate to be used by the AudioContext, specified in samples per second. The value may be any value supported by AudioBuffer. If not specified, the preferred sample rate for the context's output device is used by default.

Return value

The newly constructed AudioContext instance.

Exceptions

NotSupportedError
The specified sampleRate isn't supported by the context.

Usage notes

The specification doesn't go into a lot of detail about things like how many audio contexts a user agent should support, or minimum or maximum latency requirements (if any), so these details can vary from browser to browser. Be sure to check the values if they matter to you.

In particular, the specification doesn't indicate a maximum or minimum number of audio contexts that must be able to be open at the same time, so this is left up to the browser implementations to decide.

Google Chrome

Per-tab audio context limitation in Chrome

Prior to version 66 Google Chrome only supported up to six audio contexts per tab at a time.

Non-standard exceptions in Chrome

If the value of the latencyHint  property isn't valid, Chrome throws a TypeError exception with the message "The provided value '...' is not a valid enum value of type AudioContextLatencyCategory".

Example

This example creates a new AudioContext for interactive audio (optimizing for latency) and a sample rate of 44.1kHz.

var AudioContext = window.AudioContext || window.webkitAudioContext;

var audioCtx = new AudioContext({
  latencyHint: 'interactive',
  sampleRate: 44100,
});

Specifications

Specification Status Comment
Web Audio APIThe definition of 'AudioContext()' in that specification. Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
AudioContext() constructor

Chrome Full support 35

Notes'

Full support 35

Notes'

Notes' Prior to Chrome 66, each tab is limited to 6 audio contexts in Chrome; attempting to create more will throw a DOMException. For details see Per-tab audio context limitation in Chrome. Notes' If latencyHint isn't valid, Chrome throws a TypeError exception. See Non-standard exceptions in Chrome for details. No support 14 — 57

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Edge

Full support 12

Firefox

Full support 25

IE

No support No

Opera Full support 22

Notes'

Full support 22

Notes'

Notes' Prior to Opera 53, each tab is limited to 6 audio contexts in Opera; attempting to create more will throw a DOMException. For details see Per-tab audio context limitation in Chrome. Notes' If latencyHint isn't valid, Opera throws a TypeError exception. See Non-standard exceptions in Chrome for details. No support 15 — 44

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Safari Full support 6.1

Prefixed'

Full support 6.1

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

WebView Android Full support 37

Notes'

Full support 37

Notes'

Notes' Prior to WebView 66, each tab is limited to 6 audio contexts in WebView; attempting to create more will throw a DOMException. For details see Per-tab audio context limitation in Chrome. Notes' If latencyHint isn't valid, WebView throws a TypeError exception. See Non-standard exceptions in Chrome for details. No support ≤37 — 44

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Chrome Android Full support 35

Notes'

Full support 35

Notes'

Notes' Prior to Chrome 66, each tab is limited to 6 audio contexts in Chrome; attempting to create more will throw a DOMException. For details see Per-tab audio context limitation in Chrome. Notes' If latencyHint isn't valid, Chrome throws a TypeError exception. See Non-standard exceptions in Chrome for details. No support 18 — 57

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Firefox Android

Full support 26

Opera Android Full support 22

Notes'

Full support 22

Notes'

Notes' Prior to Opera Android 47, each tab is limited to 6 audio contexts in Opera; attempting to create more will throw a DOMException. For details see Per-tab audio context limitation in Chrome. Notes' If latencyHint isn't valid, Opera throws a TypeError exception. See Non-standard exceptions in Chrome for details. No support 14 — 43

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Safari iOS Full support 6.1

Prefixed'

Full support 6.1

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Samsung Internet Android Full support 3.0

Notes'

Full support 3.0

Notes'

Notes' Prior to Samsung Internet 9.0, each tab is limited to 6 audio contexts in Samsung Internet; attempting to create more will throw a DOMException. For details see Per-tab audio context limitation in Chrome. Notes' If latencyHint isn't valid, Samsung Internet throws a TypeError exception. See Non-standard exceptions in Chrome for details. No support 1.0 — 7.0

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

latencyHint option

Experimental'

Chrome

Full support 60

Edge

Full support 79

Firefox

No support No

IE

No support No

Opera

Full support 47

Safari

?

WebView Android

Full support 60

Chrome Android

Full support 60

Firefox Android

No support No

Opera Android

Full support 44

Safari iOS

?

Samsung Internet Android

Full support 8.0

sampleRate option

Experimental'

Chrome

Full support 74

Edge

Full support 79

Firefox

No support No

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 74

Chrome Android

Full support 74

Firefox Android

?

Opera Android

?

Safari iOS

Full support Yes

Samsung Internet Android

Full support 11.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.
See implementation notes.'
See implementation notes.
Requires a vendor prefix or different name for use.'
Requires a vendor prefix or different name for use.


See also