pub struct TurnController<T: AudioTurnDetector> { /* private fields */ }Expand description
Orchestration wrapper around any AudioTurnDetector.
Tracks prediction state across calls and provides convenience methods
like reset_if_finished for
correct VAD integration without manual state bookkeeping.
§Usage
let detector = PipecatSmartTurn::new()?;
let mut ctrl = TurnController::new(detector);
// Audio arrives continuously
ctrl.push_audio(&frame);
// VAD speech start — soft reset (keeps buffer if turn was unfinished)
ctrl.reset_if_finished();
// VAD speech end — predict
let result = ctrl.predict()?;See reset_if_finished for details
on when to use soft vs hard reset.
Implementations§
Source§impl<T: AudioTurnDetector> TurnController<T>
impl<T: AudioTurnDetector> TurnController<T>
Sourcepub fn push_audio(&mut self, frame: &AudioFrame<'_>)
pub fn push_audio(&mut self, frame: &AudioFrame<'_>)
Feed audio into the detector.
Sourcepub fn predict(&mut self) -> Result<TurnPrediction, TurnError>
pub fn predict(&mut self) -> Result<TurnPrediction, TurnError>
Run prediction on buffered audio.
Tracks the result state internally for reset_if_finished.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Hard reset — always clears the buffer.
Use when you know a new turn is starting (e.g. after the assistant finishes responding).
Sourcepub fn reset_if_finished(&mut self) -> bool
pub fn reset_if_finished(&mut self) -> bool
Soft reset — clears the buffer only if the last prediction was
Finished or no prediction has been made
since the last reset.
Returns true if a reset occurred, false if skipped.
Call this on VAD speech-start when you don’t know whether the user
is continuing the same turn or starting a new one. If the previous
prediction was Unfinished, the buffer is
preserved so the next predict runs on the full
accumulated audio.
Sourcepub fn last_state(&self) -> Option<TurnState>
pub fn last_state(&self) -> Option<TurnState>
Returns the state from the last predict call,
or None if no prediction has been made since the last reset.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap the controller, returning the inner detector.