Documentation
¶
Overview ¶
Package turn provides end-of-turn detection: it decides when a user has actually finished speaking, as opposed to merely pausing. The Analyzer interface is the contract; the package ships SmartTurnV3, an ONNX model that predicts turn completion from the audio of the user's turn, as the default.
Unlike a voice activity detector, which reacts to silence, a turn analyzer listens to the shape of speech — intonation, trailing words — to tell a mid-sentence pause from a finished thought. The turntaking package feeds it the user's audio and asks it, when speech stops, whether the turn is over.
Index ¶
- type Analyzer
- type EndOfTurnState
- type Params
- type SmartTurnV3
- func (b SmartTurnV3) AnalyzeEndOfTurn() (EndOfTurnState, float64, error)
- func (b SmartTurnV3) AppendAudio(buffer []byte, isSpeech bool) EndOfTurnState
- func (b SmartTurnV3) Clear()
- func (s *SmartTurnV3) Close() error
- func (b SmartTurnV3) SetSampleRate(sampleRate int)
- func (b SmartTurnV3) UpdateVADStartSecs(secs float64)
- type TurnOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer interface {
// SetSampleRate sets the input sample rate in Hz. It is called once before
// analysis begins.
SetSampleRate(sampleRate int)
// AppendAudio adds a chunk of the user's audio along with whether voice
// activity considers it speech. It returns Complete when a non-model
// condition (the silence safety net) ends the turn, otherwise Incomplete.
AppendAudio(buffer []byte, isSpeech bool) EndOfTurnState
// AnalyzeEndOfTurn runs the model over the buffered turn audio and returns
// the predicted state and the model's completion probability in [0,1].
AnalyzeEndOfTurn() (EndOfTurnState, float64, error)
// UpdateVADStartSecs informs the analyzer of the VAD start delay so it can
// align its pre-speech buffering.
UpdateVADStartSecs(secs float64)
// Clear resets the analyzer to its initial state.
Clear()
// Close releases any resources (for example a model session).
Close() error
}
Analyzer decides when a user's turn has ended.
type EndOfTurnState ¶
type EndOfTurnState int
EndOfTurnState is the result of end-of-turn analysis.
const ( // Incomplete means the user is likely still speaking or about to continue. Incomplete EndOfTurnState = iota // Complete means the user has finished their turn. Complete )
func (EndOfTurnState) String ¶
func (s EndOfTurnState) String() string
String returns the lowercase state name.
type Params ¶
type Params struct {
// StopSecs is the silence duration that forces a turn complete even if the
// model has not fired, as a safety net.
StopSecs float64
// PreSpeechMs is how much audio before speech onset to include in the
// analyzed segment.
PreSpeechMs float64
// MaxDurationSecs caps the analyzed segment length; only the most recent
// audio is kept.
MaxDurationSecs float64
}
Params configures end-of-turn analysis.
func DefaultParams ¶
func DefaultParams() Params
DefaultParams returns the default analysis parameters.
type SmartTurnV3 ¶
type SmartTurnV3 struct {
// contains filtered or unexported fields
}
SmartTurnV3 is an end-of-turn Analyzer backed by the smart-turn-v3 ONNX model.
func NewSmartTurnV3 ¶
func NewSmartTurnV3(opts ...TurnOption) (*SmartTurnV3, error)
NewSmartTurnV3 loads the embedded smart-turn-v3 model and returns an analyzer. It requires the ONNX runtime to be locatable (see the onnxrt package).
func (SmartTurnV3) AnalyzeEndOfTurn ¶
func (b SmartTurnV3) AnalyzeEndOfTurn() (EndOfTurnState, float64, error)
AnalyzeEndOfTurn runs the model over the buffered turn and returns the predicted state and completion probability. On Complete it clears the buffer.
func (SmartTurnV3) AppendAudio ¶
func (b SmartTurnV3) AppendAudio(buffer []byte, isSpeech bool) EndOfTurnState
AppendAudio buffers a chunk of turn audio and tracks silence. It returns Complete only when accumulated silence crosses the stop-seconds safety net; the model decision happens in AnalyzeEndOfTurn.
func (SmartTurnV3) Clear ¶
func (b SmartTurnV3) Clear()
Clear resets the analyzer to its initial state.
func (SmartTurnV3) SetSampleRate ¶
func (b SmartTurnV3) SetSampleRate(sampleRate int)
SetSampleRate sets the input sample rate.
func (SmartTurnV3) UpdateVADStartSecs ¶
func (b SmartTurnV3) UpdateVADStartSecs(secs float64)
UpdateVADStartSecs stores the VAD start delay used to widen the pre-speech window.