Algorithmic details
The VAD algorithm works as follows:
- Sample rate conversion is performed on input audio so that the processed audio has a sample rate of 16000.
- The converted samples are batched into "frames" of size
frameSamples
samples. - The Silero vad model is run on each frame and produces a number between 0 and 1 indicating the probability that the sample contains speech.
- If the algorithm has not detected speech lately, then it is in a state of
not speaking
. Once it encounters a frame with speech probability greater thanpositiveSpeechThreshold
, it is changed into a state ofspeaking
. When it encountersredemptionFrames
frames with speech probability less thannegativeSpeechThreshold
without having encountered a frame with speech probability greater thanpositiveSpeechThreshold
, the speech audio segment is considered to have ended and the algorithm returns to a state ofnot speaking
. Frames with speech probability in betweennegativeSpeechThreshold
andpositiveSpeechThreshold
are effectively ignored. - When the algorithm detects the end of a speech audio segment (i.e. goes from the state of
speaking
tonot speaking
), it counts the number of frames with speech probability greater thanpositiveSpeechThreshold
in the audio segment. If the count is less thanminSpeechFrames
, then the audio segment is considered a false positive. Otherwise,preSpeechPadFrames
frames are prepended to the audio segment and the segment is made accessible through the higher-level API.
Configuration
All of the main APIs accept certain common configuration parameters that modify the VAD algorithm.
positiveSpeechThreshold: number
- determines the threshold over which a probability is considered to indicate the presence of speech.negativeSpeechThreshold: number
- determines the threshold under which a probability is considered to indicate the absence of speech.redemptionFrames: number
- number of speech-negative frames to wait before ending a speech segment.frameSamples: number
- the size of a frame in samples - 1536 by default and probably should not be changed.preSpeechPadFrames: number
- number of audio frames to prepend to a speech segment.minSpeechFrames: number
- minimum number of speech-positive frames for a speech segment.