# AudioWorklet

> The `AudioWorklet` JS object runs custom audio processing code on a separate high-priority thread.

## What is AudioWorklet used for?

The interface for running custom audio processing code on the audio rendering thread, without blocking the main thread. Used for real-time effects, level meters and converting microphone audio to the format a speech model expects.

- Topic: Media & Audio
- Type: object
- Browser support: Chrome 66+, Chrome Android 66+, Edge 79+, Firefox 76+, Firefox Android 79+, Safari 14.1+, Safari iOS 14.5+

## Example

Wrong:

```js
const node = ctx.createScriptProcessor(1024, 1, 1);
node.onaudioprocess = (e) => processAudio(e);
```

Right:

```js
await ctx.audioWorklet.addModule('processor.js');
const node = new AudioWorkletNode(ctx, 'my-processor');
source.connect(node).connect(ctx.destination);
```

`ScriptProcessorNode` is deprecated and runs on the main thread; an `AudioWorkletNode` runs on the audio thread.

## Common mistakes

- Using the deprecated `ScriptProcessorNode` and getting glitches when the main thread is busy.

## Key points

- Heavy processing happens in the worklet processor, not in a main-thread callback.
- Data is sent between the worklet and the page through `port.postMessage()`.

## Interview questions

### Why does `process()` in my AudioWorklet stop being called?

Returning `false` lets the browser stop the processor once it has no active inputs. Return `true` to keep it running.

### How many samples does `process()` get at a time?

It usually receives blocks of 128 frames per channel, called a render quantum.

### Does AudioWorklet need HTTPS?

Yes. `audioWorklet` is available only in secure contexts, which include `localhost`.

## Related cards

- [AudioContext](https://wonderium.dev/js/audio-context.md)
- [Worker](https://wonderium.dev/js/worker.md)
- [Speech-to-Text](https://wonderium.dev/ai/speech-to-text.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/audio-worklet
- Last updated: 2026-11-25
