Skip to main content

AudioTurnDetector

Trait AudioTurnDetector 

Source
pub trait AudioTurnDetector: Send + Sync {
    // Required methods
    fn push_audio(&mut self, frame: &AudioFrame<'_>);
    fn predict(&mut self) -> Result<TurnPrediction, TurnError>;
    fn reset(&mut self);
}
Expand description

Turn detector that operates on raw audio.

Implementations buffer audio internally and run prediction on demand.

Most users should wrap this in TurnController rather than calling these methods directly. The controller tracks prediction state and provides reset_if_finished for correct multi-utterance handling.

§Direct usage (advanced)

If you need full control over reset logic:

  1. Every audio chunkpush_audio
  2. VAD fires “speech stopped”predict
  3. New turn beginsreset

Note: calling reset unconditionally on every VAD speech-start will discard audio context when the user pauses mid-sentence. See TurnController for the recommended approach.

Required Methods§

Source

fn push_audio(&mut self, frame: &AudioFrame<'_>)

Feed audio into the internal buffer.

Call continuously with incoming audio frames (16 kHz mono).

Source

fn predict(&mut self) -> Result<TurnPrediction, TurnError>

Run prediction on buffered audio.

Call when VAD detects end of speech. The buffer is not cleared after prediction — call reset explicitly when starting a new turn.

Source

fn reset(&mut self)

Unconditionally clear the internal buffer.

Use when you are certain a new turn is starting (e.g. after the assistant finishes responding). For VAD speech-start events where the user may be continuing, prefer TurnController::reset_if_finished.

Implementors§