Although the interface is available outside secure contexts, the BaseAudioContext.audioWorklet
property is not, thus custom AudioWorkletProcessor
s cannot be defined outside them.
The AudioWorkletNode
interface of the Web Audio API represents a base class for a user-defined AudioNode
, which can be connected to an audio routing graph along with other nodes. It has an associated AudioWorkletProcessor
, which does the actual audio processing in a Web Audio rendering thread.
Constructor
AudioWorkletNode()
- Creates a new instance of an
AudioWorkletNode
object.
Properties
Also Inherits properties from its parent, AudioNode
.
AudioWorkletNode.port
Read only- Returns a
MessagePort
used for bidirectional communication between the node and its associatedAudioWorkletProcessor
. The other end is available under theport
property of the processor. AudioWorkletNode.parameters
Read only- Returns an
AudioParamMap
— a collection ofAudioParam
objects. They are instantiated during the creation of the underlyingAudioWorkletProcessor
. If theAudioWorkletProcessor
has a staticparameterDescriptors
getter, theAudioParamDescriptor
array returned from it is used to createAudioParam
objects on theAudioWorkletNode
. With this mechanism it is possible to make your ownAudioParam
objects accessible from yourAudioWorkletNode
. You can then use their values in the associatedAudioWorkletProcessor
.
Event handlers
AudioWorkletNode.onprocessorerror
- Fired when an error is thrown in associated
AudioWorkletProcessor
. Once fired, the processor and consequently the node will output silence throughout its lifetime.
Methods
Also inherits methods from its parent, AudioNode
.
The AudioWorkletNode
interface does not define any methods of its own.
Examples
In this example we create a custom AudioWorkletNode
that outputs white noise.
First, we need to define a custom AudioWorkletProcessor
, which will output white noise, and register it. Note that this should be done in a separate file.
// white-noise-processor.js
class WhiteNoiseProcessor extends AudioWorkletProcessor {
process (inputs, outputs, parameters) {
const output = outputs[0]
output.forEach(channel => {
for (let i = 0; i < channel.length; i++) {
channel[i] = Math.random() * 2 - 1
}
})
return true
}
}
registerProcessor('white-noise-processor', WhiteNoiseProcessor)
Next, in our main script file we'll load the processor, create an instance of AudioWorkletNode
passing it the name of the processor, and connect the node to an audio graph.
const audioContext = new AudioContext()
await audioContext.audioWorklet.addModule('white-noise-processor.js')
const whiteNoiseNode = new AudioWorkletNode(audioContext, 'white-noise-processor')
whiteNoiseNode.connect(audioContext.destination)
Specifications
Specification | Status | Comment |
Web Audio APIThe definition of 'AudioWorkletNode' in that specification. | Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioWorkletNode
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
Full support Yes |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
Full support 79 |
Opera Android
Full support Yes |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
AudioWorkletNode() constructor
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
? |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
Full support 79 |
Opera Android
? |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
onprocessorerror
|
Chrome
Full support 67 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
? |
Safari
No support No |
WebView Android
Full support 67 |
Chrome Android
Full support 67 |
Firefox Android
Full support 79 |
Opera Android
? |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
parameters
|
Chrome
Full support 67 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
Full support Yes |
Safari
No support No |
WebView Android
Full support 67 |
Chrome Android
Full support 67 |
Firefox Android
Full support 79 |
Opera Android
Full support Yes |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
port
|
Chrome
Full support 67 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
Full support Yes |
Safari
No support No |
WebView Android
Full support 67 |
Chrome Android
Full support 67 |
Firefox Android
Full support 79 |
Opera Android
Full support Yes |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
processorerror event
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
? |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
Full support 79 |
Opera Android
? |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
See also
AudioWorkletNode by Mozilla Contributors is licensed under CC-BY-SA 2.5.