Voice Activity Detection
Voice Activity Detection (VAD) identifies segments of audio containing speech versus silence. WhisperKit includes VAD capabilities to improve transcription accuracy, reduce computation, and enable intelligent audio chunking.VoiceActivityDetector Base Class
TheVoiceActivityDetector is a base class that provides common functionality for all VAD implementations:
Properties
Int
default:"16000"
Audio sample rate in Hz. WhisperKit uses 16kHz by default.
Int
Length of each analysis frame in samples.
Int
default:"0"
Number of samples overlapping between consecutive frames.
EnergyVAD
WhisperKit includesEnergyVAD, a simple energy-based voice activity detector:
EnergyVAD Initialization
Parameters
Int
default:"16000"
Audio sample rate matching
WhisperKit.sampleRate.Float
default:"0.1"
Frame length in seconds. Default 0.1 = 100ms frames.
Float
default:"0.0"
Overlap in seconds. Helps catch speech at frame boundaries.
Float
default:"0.02"
Minimum energy level to consider as speech. Lower values are more sensitive.
Using VAD for Audio Chunking
VAD enables intelligent audio chunking based on speech activity:ChunkingStrategy Enum
VAD Methods
Calculate Active Chunks
Get start/end indices of speech segments:Find Longest Silence
Identify the longest silent period:Voice Activity Clip Timestamps
Generate clip timestamps for active segments:Index Conversion Utilities
Convert VAD Index to Audio Sample
Convert VAD Index to Seconds
VAD in Configuration
Configure VAD inWhisperKitConfig:
Streaming with VAD
AudioStreamTranscriber uses VAD by default:
How Streaming VAD Works
- Audio buffer accumulates samples
- Relative energy is calculated for recent audio
- VAD checks if energy exceeds
silenceThreshold - If no voice detected, transcription is skipped
- If voice detected, buffer is transcribed
Custom VAD Implementation
Implement your own VAD by subclassingVoiceActivityDetector:
Async VAD
For ML models requiring async operations:VAD Benefits
Reduced Computation
Skip transcription of silent segments, saving CPU/GPU cycles and battery.
Better Accuracy
Avoid hallucinations on background noise by only transcribing speech.
Smart Chunking
Split long audio at natural silence boundaries instead of arbitrary time points.
Real-time Optimization
Streaming transcription skips silent buffers for better responsiveness.
Tuning Energy Threshold
TheenergyThreshold parameter is critical for VAD performance:
Too Low (e.g., 0.001)
- Detects very quiet speech
- May trigger on background noise
- More false positives
Optimal (e.g., 0.02)
- Balances sensitivity and specificity
- Good for typical recording conditions
- Default value works for most cases
Too High (e.g., 0.1)
- Only detects loud speech
- May miss quiet speakers
- More false negatives
Testing Different Thresholds
Complete Example
Next Steps
Streaming
Use VAD in real-time streaming transcription
Configuration
Advanced configuration options