AudioWorklet
The AudioWorklet interface of the Web Audio API is used to supply custom audio processing scripts that execute in a separate thread to provide very low latency audio processing.
The worklet's code is run in the AudioWorkletGlobalScope global execution context, using a separate Web Audio thread which is shared by the worklet and other audio nodes.
Access the audio context's instance of AudioWorklet through the BaseAudioContext.audioWorklet property.
Worklet AudioWorklet
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 66 | 79 | 76 | 14.1 | 66 | 14.5 | |
| The AudioWorkletGlobalScope interface of the Web Audio API represents a global execution context for user-supplied code, which defines custom AudioWorkletProcessor-derived classes. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The read-only currentFrame property of the AudioWorkletGlobalScope interface returns an integer that represents the ever-increasing current sample-frame of the audio block being processed. It is incremented by 128 (the size of a render quantum) after the processing of each audio block. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The read-only currentTime property of the AudioWorkletGlobalScope interface returns a double that represents the ever-increasing context time of the audio block being processed. It is equal to the BaseAudioContext.currentTime property of the BaseAudioContext the worklet belongs to. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
port Experimental The port read-only property of the AudioWorkletGlobalScope interface returns a MessagePort object that can be used to send and receive messages between the main thread and the associated AudioWorklet. | | | 138 | | | |
| The registerProcessor method of the AudioWorkletGlobalScope interface registers a class constructor derived from AudioWorkletProcessor interface under a specified name. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The read-only sampleRate property of the AudioWorkletGlobalScope interface returns a float that represents the sample rate of the associated BaseAudioContext the worklet belongs to. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| 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. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The AudioWorkletNode() constructor creates a new AudioWorkletNode object, which represents an AudioNode that uses a JavaScript function to perform custom audio processing. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The read-only parameters property of the AudioWorkletNode interface returns the associated AudioParamMap — that is, a Map-like collection of AudioParam objects. They are instantiated during creation of the underlying AudioWorkletProcessor according to its AudioWorkletProcessor.parameterDescriptors static getter. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The read-only port property of the AudioWorkletNode interface returns the associated MessagePort. It can be used to communicate between the node and its associated AudioWorkletProcessor. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The processorerror event fires when the underlying AudioWorkletProcessor behind the node throws an exception in its constructor, the AudioWorkletProcessor.process method, or any user-defined class method. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The AudioWorkletProcessor interface of the Web Audio API represents an audio processing code behind a custom AudioWorkletNode. It lives in the AudioWorkletGlobalScope and runs on the Web Audio rendering thread. In turn, an AudioWorkletNode based on it runs on the main thread. | 64 | 79 | 76 | 14.1 | 64 | 14.5 |
| The AudioWorkletProcessor() constructor creates a new AudioWorkletProcessor object, which represents an underlying audio processing mechanism of an AudioWorkletNode. | 64 | 79 | 76 | 14.1 | 64 | 14.5 |
| The read-only port property of the AudioWorkletProcessor interface returns the associated MessagePort. It can be used to communicate between the processor and the AudioWorkletNode to which it belongs. | 64 | 79 | 76 | 14.1 | 64 | 14.5 |
| The audioWorklet read-only property of the BaseAudioContext interface returns an instance of AudioWorklet that can be used for adding AudioWorkletProcessor-derived classes which implement custom audio processing. | 66 | 79 | 76 | 14.1 | 66 | 14.5 |
| The Worklet interface is a lightweight version of Web Workers and gives developers access to low-level parts of the rendering pipeline. | 65 | 79 | 76 | 14.1 | 65 | 14.5 |
| The addModule() method of the Worklet interface loads the module in the given JavaScript file and adds it to the current Worklet. | 65 | 79 | 76 | 14.1 | 65 | 14.5 |
| The WorkletGlobalScope interface is an abstract class that specific worklet scope classes inherit from. Each WorkletGlobalScope defines a new global environment. | 65 | 79 | 76 | 14.1 | 65 | 14.5 |
Use cases
-
Using AudioWorklet
The AudioWorklet interface of the Web Audio API is used to supply custom audio processing scripts that execute in a separate thread to provide very low latency audio processing.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.