How to Configure VAD Thresholds and Minimum Speech Duration in Hugging Face Speech-to-Speech
Set VAD thresholds and speech duration limits by instantiating VADHandlerArguments with custom values for threshold, min_speech_ms, and related parameters, then pass the instance to S2SPipeline as vad_handler_kwargs.
The huggingface/speech-to-speech library exposes Voice Activity Detection (VAD) settings through a dedicated dataclass that feeds directly into the real-time audio pipeline. Understanding these parameters lets you tune speech segmentation for your specific acoustic environment—whether you need low-latency responsiveness or robust filtering of false triggers.
VAD Configuration Parameters Explained
All VAD settings live in src/speech_to_speech/arguments_classes/vad_arguments.py within the VADHandlerArguments dataclass. Here are the key fields that control detection behavior:
| Parameter | Type | Default | Purpose |
|---|---|---|---|
threshold |
float |
0.5 |
Probability cutoff for Silero VAD—chunks scoring above this are marked as speech |
smart_turn_threshold |
float |
0.5 |
Confidence barrier for Smart Turn finalization; higher values delay turn completion |
min_speech_ms |
int |
384 |
Minimum contiguous speech duration (milliseconds) to emit as a valid turn |
min_speech_continuation_ms |
int |
192 |
Hysteresis window for "reopenable" turns; merges continued speech within this span |
The min_speech_continuation_ms parameter is internally clamped to [100, min_speech_ms] as implemented in src/speech_to_speech/VAD/vad_handler.py. Setting it to 0 disables the soft-ending logic entirely.
How Parameters Interact in the Pipeline
The VADHandler class in src/speech_to_speech/VAD/vad_handler.py orchestrates three processing layers:
-
Raw VAD Scoring: The underlying
VADIterator(src/speech_to_speech/VAD/vad_iterator.py, lines 147-153) applies yourthresholdwith a built-in hysteresis ofthreshold - 0.15to smooth speech/silence transitions. -
Duration Filtering: Consecutive speech fragments are stitched; only segments meeting
min_speech_mssurvive. Fragments separated by gaps undermin_speech_continuation_msare merged into single turns. -
Smart Turn Arbitration: The
SmartTurnmodule (src/speech_to_speech/VAD/smart_turn.py) usessmart_turn_thresholdto probabilistically decide when a pause truly signals turn completion versus temporary hesitation.
The handler updates the VADIterator threshold at runtime (lines 199-201 of vad_handler.py), ensuring your configuration takes immediate effect without pipeline restart.
Configuration Code Examples
Default Settings
from speech_to_speech.arguments_classes.vad_arguments import VADHandlerArguments
from speech_to_speech.s2s_pipeline import S2SPipeline
vad_args = VADHandlerArguments() # threshold=0.5, min_speech_ms=384, etc.
pipeline = S2SPipeline(
vad_handler_kwargs=vad_args,
# additional module arguments...
)
pipeline.run()
Aggressive Detection (Noisy Environments, Low Latency)
vad_args = VADHandlerArguments(
threshold=0.35, # Accept lower-confidence speech
min_speech_ms=200, # Capture very short utterances
min_speech_continuation_ms=100, # Tight merging window
smart_turn_threshold=0.3, # Fast turn finalization
)
pipeline = S2SPipeline(vad_handler_kwargs=vad_args, ...)
pipeline.run()
Conservative Detection (Quiet, Controlled Environments)
vad_args = VADHandlerArguments(
threshold=0.7, # Require high confidence
min_speech_ms=500, # Ignore brief noises
min_speech_continuation_ms=300, # Longer tolerance for pauses
smart_turn_threshold=0.6, # Wait longer on silences
)
pipeline = S2SPipeline(vad_handler_kwargs=vad_args, ...)
pipeline.run()
Source File Reference Map
| File | Responsibility |
|---|---|
src/speech_to_speech/arguments_classes/vad_arguments.py |
Dataclass definition for all VAD CLI and constructor arguments |
src/speech_to_speech/VAD/vad_iterator.py |
Silero VAD wrapper; raw threshold application and per-chunk scoring |
src/speech_to_speech/VAD/vad_handler.py |
Fragment stitching, min_speech_ms enforcement, runtime threshold updates |
src/speech_to_speech/VAD/smart_turn.py |
Probabilistic turn completion using smart_turn_threshold |
src/speech_to_speech/s2s_pipeline.py |
Orchestrates components; wires VADHandlerArguments into VADHandler |
Summary
VADHandlerArgumentsinvad_arguments.pycentralizes all VAD configurationthresholdcontrols raw detection sensitivity;min_speech_msfilters brief noisesmin_speech_continuation_msenables "soft-ended" turns with configurable hysteresissmart_turn_thresholdgoverns high-level turn finalization decisions- Pass configured arguments to
S2SPipelineviavad_handler_kwargsto activate changes
Frequently Asked Questions
What happens if I set min_speech_continuation_ms higher than min_speech_ms?
The value is automatically clamped to the valid range [100, min_speech_ms] by the VADHandler initialization logic. Attempting to exceed this boundary silently adjusts your setting downward to maintain internal consistency.
How do I completely disable the soft-ending behavior for VAD turns?
Set min_speech_continuation_ms=0. This forces the handler to use min_speech_ms as the sole duration criterion without reopening closed turns, creating hard boundaries between speech segments.
Why does lowering threshold sometimes increase false triggers rather than sensitivity?
The Silero model's probability scores correlate with signal-to-noise ratio. In very noisy environments, lowering threshold admits more low-confidence predictions that may include non-speech audio. Balance this by simultaneously increasing min_speech_ms to filter transient noise spikes.
Where is the threshold value actually applied to VAD scores?
The VADHandler sets the iterator's threshold at runtime in src/speech_to_speech/VAD/vad_handler.py lines 199-201. The underlying VADIterator then compares each audio chunk's probability against this threshold in its iteration loop (vad_iterator.py lines 147-153).
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →