AudioWorkletNode: AudioWorkletNode() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The AudioWorkletNode() constructor creates a new AudioWorkletNode object, which represents an AudioNode that uses a JavaScript function to perform custom audio processing.

Syntax

js
new AudioWorkletNode(context, name)
new AudioWorkletNode(context, name, options)

Parameters

context

The BaseAudioContext instance this node will be associated with.

name

A string, which represents the name of the AudioWorkletProcessor this node will be based on. A processor with the provided name must first be registered using the AudioWorkletGlobalScope.registerProcessor() method.

options Optional

An object containing zero or more of the following optional properties to configure the new node:

Note: The result of the structured clone algorithm applied to the object is also internally passed into the associated AudioWorkletProcessor() constructor — this allows custom initialization of an underlying user-defined AudioWorkletProcessor.

numberOfInputs Optional

The value to initialize the numberOfInputs property to. Defaults to 1.

numberOfOutputs Optional

The value to initialize the numberOfOutputs property to. Defaults to 1.

outputChannelCount Optional

An array defining the number of channels for each output. For example, outputChannelCount: [n, m] specifies the number of channels in the first output to be n and the second output to be m. The array length must match numberOfOutputs.

parameterData Optional

An object containing the initial values of custom AudioParam objects on this node (in its parameters property), with key being the name of a custom parameter and value being its initial value.

processorOptions Optional

Any additional data that can be used for custom initialization of the underlying AudioWorkletProcessor.

Exceptions

NotSupportedError DOMException

The specified options.outputChannelCount is 0 or larger than the current implementation supports.

Both options.numberOfInputs and options.numberOfOutputs are 0.

IndexSizeError DOMException

The length of options.outputChannelCount array does not match options.numberOfOutputs.

Usage notes

Different options parameter values can have the following effects.

If the number of inputs and number of outputs are both set to 0, a NotSupportedError will be thrown and the node construction process aborted. If the length of the outputChannelCount array doesn't match numberOfOutputs, an IndexSizeError DOMException will be thrown.

If outputChannelCount isn't specified, and numberOfInputs and numberOfOutputs are both 1, the AudioWorkletNode's initial channel count is set to 1. This has the effect of changing the output channel count to dynamically change to the computed number of channels, based on the input's channel count and the current setting of the AudioNode property channelCountMode.

Otherwise, if outputChannelCount is provided and if the values of numberOfInputs and numberOfOutputs are both 1, the audio worklet node's channel count is set to the value of outputChannelCount. Otherwise, the channel count of each channel in the set of output channels is set to match the corresponding value in the outputChannelCount array.

Examples

For a complete example demonstrating user-defined audio processing, see the AudioWorkletNode page.

Specifications

Specification
Web Audio API
# dom-audioworkletnode-audioworkletnode

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
AudioWorkletNode() constructor
Chrome – Full support
Chrome 66 (Release date: 2018-04-17)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 76 (Release date: 2020-05-05)
footnote Full support
Opera – Full support
Opera 53 (Release date: 2018-05-10)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 66 (Release date: 2018-04-17)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 66 (Release date: 2018-04-17)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also