Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. AudioWorkletNode

AudioWorkletNode

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 insecure contexts (HTTPS), in some or allsupporting browsers.

Note:Although the interface is available outsidesecure contexts, theBaseAudioContext.audioWorklet property is not, thus customAudioWorkletProcessors cannot be defined outside them.

TheAudioWorkletNode interface of theWeb Audio API represents a base class for a user-definedAudioNode, which can be connected to an audio routing graph along with other nodes. It has an associatedAudioWorkletProcessor, which does the actual audio processing in a Web Audio rendering thread.

EventTarget AudioNode AudioWorkletNode

Constructor

AudioWorkletNode()

Creates a new instance of anAudioWorkletNode object.

Instance properties

Also Inherits properties from its parent,AudioNode.

AudioWorkletNode.portRead only

Returns aMessagePort used for bidirectional communication between the node and its associatedAudioWorkletProcessor. The other end is available under theport property of the processor.

AudioWorkletNode.parametersRead only

Returns anAudioParamMap — 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.

Events

processorerror

Fired when an error is thrown in associatedAudioWorkletProcessor. Once fired, the processor and consequently the node will output silence throughout its lifetime.

Instance methods

Also inherits methods from its parent,AudioNode.

TheAudioWorkletNode interface does not define any methods of its own.

Examples

In this example we create a customAudioWorkletNode that outputs random noise.

First, we need to define a customAudioWorkletProcessor, which will output random noise, and register it. Note that this should be done in a separate file.

js
// random-noise-processor.jsclass RandomNoiseProcessor 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("random-noise-processor", RandomNoiseProcessor);

Next, in our main script file we'll load the processor, create an instance ofAudioWorkletNode passing it the name of the processor, and connect the node to an audio graph.

js
const audioContext = new AudioContext();await audioContext.audioWorklet.addModule("random-noise-processor.js");const randomNoiseNode = new AudioWorkletNode(  audioContext,  "random-noise-processor",);randomNoiseNode.connect(audioContext.destination);

Specifications

Specification
Web Audio API
# AudioWorkletNode

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp