Skip to main content

Overview

TrackVADEmitter connects a JitsiLocalTrack to a VAD (Voice Activity Detection) processor using the Web Audio API’s ScriptProcessorNode. It processes raw PCM audio data and emits VAD scores via events, enabling real-time voice activity detection for features like noise suppression, active speaker detection, and audio visualization.

Constructor

number
required
Sample rate of the ScriptProcessorNode. Valid values: 256, 512, 1024, 2048, 4096, 8192, 16384. Other values will default to the closest neighbor.
IVadProcessor
required
VAD processor implementing the IVadProcessor interface for calculating voice activity scores
JitsiLocalTrack
required
The JitsiLocalTrack (audio) to analyze
Use the TrackVADEmitter.create() factory method instead of calling the constructor directly.

Factory Method

create

Factory method that sets up all necessary components and creates a TrackVADEmitter instance.
string
required
Target microphone device ID to capture audio from
number
required
Sample rate for the ScriptProcessorNode (256, 512, 1024, 2048, 4096, 8192, or 16384)
IVadProcessor
required
VAD processor that implements:
  • getSampleLength() - Returns required PCM sample size
  • getRequiredPCMFrequency() - Returns required PCM frequency
  • calculateAudioFrameVAD(pcmSample) - Calculates VAD score for a PCM sample
Returns: Promise resolving to a new TrackVADEmitter instance Example:

Methods

start

Starts the VAD emitter by connecting the audio graph. Audio data begins flowing through the ScriptProcessorNode.
Example:

stop

Stops the VAD emitter by disconnecting the audio graph and clearing internal buffers.
Example:

destroy

Performs complete cleanup: disconnects audio graph, stops the underlying track, and releases all resources.
Always call destroy() when done to prevent memory leaks. After calling destroy(), the emitter cannot be reused.
Example:

Events

VAD_SCORE_PUBLISHED

Emitted whenever a VAD score is calculated for an audio frame. This event is fired at a rate determined by the processor sample size and node sample rate. Event Data:
string
The microphone device ID being analyzed
number
Voice activity detection score (typically 0-1, where higher = more likely voice)
Float32Array
The raw PCM audio sample that was analyzed
number
Timestamp when the sample was processed (Date.now())
Example:

Complete Examples

Basic VAD Detection with RNNoise

Advanced: VAD with Audio Visualization

VAD Processor Interface

Implement the IVadProcessor interface for custom VAD algorithms:

Performance Considerations

ScriptProcessorNode is deprecated in favor of AudioWorklet. However, at the time of implementation, AudioWorklet had limited browser support. Consider migrating to AudioWorklet when browser support improves.
The procNodeSampleRate affects how often calculateAudioFrameVAD is called. Lower values (256, 512) provide more frequent updates but higher CPU usage. Higher values (8192, 16384) reduce CPU usage but lower update frequency.

Buffer Handling

The emitter handles sample size mismatches automatically:
  • If procNodeSampleRate doesn’t divide evenly by vadProcessor.getSampleLength(), residual PCM data is buffered
  • The residue is prepended to the next batch to ensure no audio data is lost
  • This allows flexible combinations of processor sample sizes and node buffer sizes

Browser Support

  • Chrome/Edge 14+
  • Firefox 25+
  • Safari 6+
  • Opera 15+
Requires Web Audio API support. The AudioContext is automatically created with the frequency required by your VAD processor.

Common Use Cases

  1. Active speaker detection - Identify who is speaking in a conference
  2. Noise suppression - Apply processing only when voice is detected
  3. Audio gating - Mute audio below a voice activity threshold
  4. Transcription optimization - Send audio to speech-to-text only when voice is present
  5. Audio visualization - Display real-time voice activity indicators