Overview
When you need extra audio or video processing between capture and publishing (such as AI noise suppression, beauty filters, or voice changing), the SDK provides a unified processor mechanism. From first principles, a processor is essentially “take oneMediaStreamTrack in, output one processed MediaStreamTrack”. The SDK only needs to provide an attachment point on local tracks, while plugins implement the processing logic; the two are decoupled through the TrackProcessor interface.
Processors are distributed as separate npm packages, such as the RNN noise suppression plugin @seastart/srtc-plugin-rnnoise.
Attaching and detaching
Local audio/video tracks (LocalMicTrack, LocalCameraTrack, custom tracks, etc.) all provide two methods:
replaceTrack without renegotiation, and remote users notice nothing.
Chaining multiple processors
setProcessor accepts an array and chains multiple processors in order (source → P1 → P2 → … → publish). A common combination: noise suppression first, then voice changing.
ProcessorPipeline to combine the processors into one; audio chains share the same AudioContext, reducing the cost of multi-stage processing. You can also use ProcessorPipeline directly:
Writing a custom processor
Implement theTrackProcessor interface to plug in:
ProcessorOptions fields:
When writing an audio processor, reuseoptions.audioContextif it exists (don’tcloseit yourself); only close it indestroyif you created the context yourself.
Declaring browser 3A requirements (audio processors)
When the browser captures the microphone it applies its own 3A (noise suppression, echo cancellation, auto gain control). If your processor already does noise suppression, adding the browser’s on top makes voices sound muffled. An audio processor can implementAudioTrackProcessor (which extends TrackProcessor) and use audioProcessing to declare what the browser should do:
audioProcessing fields (type AudioProcessingConstraints):
Rules:
- When attached to a microphone track (
LocalMicTrack), the SDK recaptures the microphone once with the declared settings, so audio drops out briefly. Detaching the processor, or a processor that fails to initialize, restores the original settings. Browsers can’t switch these settings mid-capture, so a recapture is the only way. - If the declaration matches the current capture settings (for example, your app already turned noise suppression off), no recapture happens.
- When chaining processors (an array or a
ProcessorPipeline), the declarations are merged: a setting is turned off if any processor asks for it to be off. - The options you passed to
startCaptureare left unchanged; the declaration stays in effect after switching devices or callingstartCaptureagain. - The SDK’s RNNoise and DeepFilterNet plugins both declare
{ noiseSuppression: false }. - In Chrome, if the same microphone has another live capture track on the same page (such as a mic test your page runs), those tracks share one set of 3A settings and the declaration may not take effect. Stop other captures on the same device before attaching the processor.
Lifecycle and notes
- You must
startCaptureto have a track before callingsetProcessor; otherwise it throws. setProcessoris idempotent: calling it again detaches the existing processor before attaching the new one.- Automatic reattachment: after switching devices (
changeDeviceId) or callingstartCaptureagain, the SDK automatically rebuilds the processor with the new source track, so you don’t need to callsetProcessoragain. - Processors mostly rely on
AudioContext/WASM, need HTTPS (or localhost), and may need a user gesture before they can run.