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
.
var audioCtx = new AudioContext(); var audioCtx = new AudioContext(options);
options
Optional
latencyHint
: A string or double value that identifies type of playback, affecting tradeoffs between audio output latency and power consumption. The default value is interactive
. Although finer control can be achieved by passing a double value (indiciating number of seconds of latency), the preferred values are as follows: balanced
, balances audio output latency and power consumption.interactive
, provides lowest audio output latency as possible without glitching.playback
, prioritizes sustained playback without interruption over audio output latency.sampleRate
: A float with the requested sampling rate for this audio context, between 8,000 and 96,000 Hz. The default value depends on the audio output device but in most cases it is 44,100 Hz.The newly constructed AudioContext
object instance.
DOMException
(The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6)). Other browsers do not have this restriction.AudioContext.close()
. To be sure that the audio context was deleted, you must wait until the Promise
is resolved but in practice this only takes a few milliseconds.TypeError
if latencyHint
has an invalid value (The provided value '...' is not a valid enum value of type AudioContextLatencyCategory).NotSupportedError
will be thrown if sampleRate
is not supported by the hardware, however no browser currently implements this parameter.var AudioContext = window.AudioContext || window.webkitAudioContext; var audioCtx = new AudioContext({ latencyHint: 'interactive', sampleRate: 44100, });
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'AudioContext()' in that specification. | Working Draft | Initial definition. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 55 | Yes | 25 | No | 42 | Yes webkit |
latencyHint option |
60 | No | No | No | 47 | ? |
sampleRate option |
No1 | No | No | No | No | ? |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | 55 | 55 | ? | 25 | No | 42 | ? |
latencyHint option |
60 | 60 | ? | No | No | 47 | ? |
sampleRate option |
? | ? | ? | ? | ? | ? | ? |
1. See issue 432248 for Chrome support.
new OfflineAudioContext()
constructor
© 2005–2018 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/AudioContext