Path: blob/main/files/en-us/web/api/audioworkletnode/index.md
6520 views
------{{APIRef("Web Audio API")}}
Note: Although the interface is available outside secure contexts, the {{domxref("BaseAudioContext.audioWorklet")}} property is not, thus custom {{domxref("AudioWorkletProcessor")}}s cannot be defined outside them.
The AudioWorkletNode interface of the Web Audio API represents a base class for a user-defined {{domxref("AudioNode")}}, which can be connected to an audio routing graph along with other nodes. It has an associated {{domxref("AudioWorkletProcessor")}}, which does the actual audio processing in a Web Audio rendering thread.
{{InheritanceDiagram}}
Constructor
{{domxref("AudioWorkletNode.AudioWorkletNode", "AudioWorkletNode()")}}
: Creates a new instance of an
AudioWorkletNodeobject.
Instance properties
Also Inherits properties from its parent, {{domxref("AudioNode")}}.
{{domxref("AudioWorkletNode.port")}} {{ReadOnlyInline}}
: Returns a {{domxref("MessagePort")}} used for bidirectional communication between the node and its associated {{domxref("AudioWorkletProcessor")}}. The other end is available under the {{domxref("AudioWorkletProcessor.port", "port")}} property of the processor.
{{domxref("AudioWorkletNode.parameters")}} {{ReadOnlyInline}}
: Returns an {{domxref("AudioParamMap")}} — a collection of {{domxref("AudioParam")}} objects. They are instantiated during the creation of the underlying
AudioWorkletProcessor. If theAudioWorkletProcessorhas a static {{domxref("AudioWorkletProcessor.parameterDescriptors", "parameterDescriptors")}} getter, the {{domxref("AudioParamDescriptor")}} array returned from it is used to createAudioParamobjects on theAudioWorkletNode. With this mechanism it is possible to make your ownAudioParamobjects accessible from yourAudioWorkletNode. You can then use their values in the associatedAudioWorkletProcessor.
Events
{{domxref("AudioWorkletNode.processorerror_event", "processorerror")}}
: Fired when an error is thrown in associated {{domxref("AudioWorkletProcessor")}}. Once fired, the processor and consequently the node will output silence throughout its lifetime.
Instance methods
Also inherits methods from its parent, {{domxref("AudioNode")}}.
The AudioWorkletNode interface does not define any methods of its own.
Examples
In this example we create a custom AudioWorkletNode that outputs random noise.
First, we need to define a custom {{domxref("AudioWorkletProcessor")}}, which will output random noise, and register it. Note that this should be done in a separate file.
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.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}