Documentation
¶
Overview ¶
Package vad provides voice activity detection: it tells the pipeline when a user is speaking. The Analyzer interface is the contract a detector implements; the package ships Silero, an ONNX-based detector, as the default.
An analyzer is fed raw mono 16-bit PCM and runs a confidence model over fixed-size frames, smoothing the result through a small state machine (quiet → starting → speaking → stopping → quiet) so brief dips or spikes do not flip the speaking decision. The turntaking package drives an analyzer and turns its state transitions into speaking and interruption frames.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer interface {
// SetSampleRate sets the stream sample rate in Hz and resets state. It is
// called once before analysis begins and returns an error if the rate is
// unsupported.
SetSampleRate(sampleRate int) error
// AnalyzeAudio feeds a chunk of mono 16-bit PCM and returns the resulting
// state. Chunks need not align to the analyzer's frame size; audio is
// buffered internally.
AnalyzeAudio(buffer []byte) State
// Params returns the detection parameters.
Params() Params
// Reset clears all internal state.
Reset()
// Close releases any resources (for example a model session).
Close() error
}
Analyzer detects voice activity in a mono 16-bit PCM stream.
type Params ¶
type Params struct {
// Confidence is the minimum model confidence in [0,1] for a frame to count
// as speech.
Confidence float64
// StartSecs is how long speech must persist before the state is confirmed
// as speaking.
StartSecs float64
// StopSecs is how long silence must persist before the state is confirmed
// as quiet.
StopSecs float64
}
Params configures voice activity detection.
func DefaultParams ¶
func DefaultParams() Params
DefaultParams returns the default detection parameters.
type Silero ¶
type Silero struct {
// contains filtered or unexported fields
}
Silero is a voice activity Analyzer backed by the Silero VAD ONNX model. It supports 8 kHz and 16 kHz mono input and manages the model's recurrent state and input context across calls.
func NewSilero ¶
NewSilero loads the embedded Silero VAD model and returns an analyzer. It requires the ONNX runtime to be locatable (see the onnxrt package); the returned error explains how to configure it when it is not.
func (Silero) AnalyzeAudio ¶
AnalyzeAudio buffers the chunk and advances the state machine over every complete frame it now holds, returning the resulting state.
func (*Silero) Reset ¶
func (s *Silero) Reset()
Reset clears the model state, the input context and the detection state machine.
func (*Silero) SetSampleRate ¶
SetSampleRate sets the input sample rate. Silero supports only 8 kHz and 16 kHz.
type State ¶
type State int
State is the voice-activity state of the audio stream.
const ( // StateQuiet means no voice activity is detected. StateQuiet State = iota + 1 // StateStarting means voice activity has begun but is not yet confirmed. StateStarting // StateSpeaking means voice activity is confirmed and ongoing. StateSpeaking // StateStopping means voice activity is ending but not yet confirmed quiet. StateStopping )