From 76498e363c0cb0c207efaf28162b5f5489e13670 Mon Sep 17 00:00:00 2001 From: Eason WaveKat Date: Tue, 31 Mar 2026 15:44:13 +1300 Subject: [PATCH 1/2] feat: expose audio_duration_ms in TurnPrediction Add audio_duration_ms field to TurnPrediction, reporting how much audio was in the detector's buffer at prediction time. For Pipecat this reflects the ring buffer fill level (capped at 8s). Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/wavekat-turn/src/audio/pipecat.rs | 4 ++++ crates/wavekat-turn/src/lib.rs | 6 ++++++ crates/wavekat-turn/tests/controller.rs | 2 ++ 3 files changed, 12 insertions(+) diff --git a/crates/wavekat-turn/src/audio/pipecat.rs b/crates/wavekat-turn/src/audio/pipecat.rs index 7b87c1a..cfaf32c 100644 --- a/crates/wavekat-turn/src/audio/pipecat.rs +++ b/crates/wavekat-turn/src/audio/pipecat.rs @@ -522,11 +522,15 @@ impl AudioTurnDetector for PipecatSmartTurn { (TurnState::Unfinished, 1.0 - probability) }; + let audio_duration_ms = + (self.ring_buffer.len() as u64 * 1000) / SAMPLE_RATE as u64; + Ok(TurnPrediction { state, confidence, latency_ms, stage_times, + audio_duration_ms, }) } diff --git a/crates/wavekat-turn/src/lib.rs b/crates/wavekat-turn/src/lib.rs index 4c6f020..fa68fa2 100644 --- a/crates/wavekat-turn/src/lib.rs +++ b/crates/wavekat-turn/src/lib.rs @@ -64,6 +64,12 @@ pub struct TurnPrediction { pub latency_ms: u64, /// Per-stage timing breakdown in pipeline order. pub stage_times: Vec, + /// Duration of audio in the detector's buffer at prediction time (ms). + /// + /// For PipecatSmartTurn this reflects how much of the 8 s ring buffer + /// was filled. With soft reset the buffer may span multiple speech + /// segments, so this can exceed the current segment duration. + pub audio_duration_ms: u64, } /// A single turn in the conversation, for context-aware text detectors. diff --git a/crates/wavekat-turn/tests/controller.rs b/crates/wavekat-turn/tests/controller.rs index e8edf88..90f5071 100644 --- a/crates/wavekat-turn/tests/controller.rs +++ b/crates/wavekat-turn/tests/controller.rs @@ -42,11 +42,13 @@ impl AudioTurnDetector for MockDetector { TurnState::Unfinished => 0.80, TurnState::Wait => 0.70, }; + let audio_duration_ms = (self.buffer_len as u64 * 1000) / 16000; Ok(TurnPrediction { state, confidence, latency_ms: 0, stage_times: vec![], + audio_duration_ms, }) } From 0b494b4f9a2863d86d5f72eaff497a3869c6d28f Mon Sep 17 00:00:00 2001 From: Eason WaveKat Date: Tue, 31 Mar 2026 15:54:56 +1300 Subject: [PATCH 2/2] style: fix rustfmt formatting Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/wavekat-turn/src/audio/pipecat.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/wavekat-turn/src/audio/pipecat.rs b/crates/wavekat-turn/src/audio/pipecat.rs index cfaf32c..eefe115 100644 --- a/crates/wavekat-turn/src/audio/pipecat.rs +++ b/crates/wavekat-turn/src/audio/pipecat.rs @@ -522,8 +522,7 @@ impl AudioTurnDetector for PipecatSmartTurn { (TurnState::Unfinished, 1.0 - probability) }; - let audio_duration_ms = - (self.ring_buffer.len() as u64 * 1000) / SAMPLE_RATE as u64; + let audio_duration_ms = (self.ring_buffer.len() as u64 * 1000) / SAMPLE_RATE as u64; Ok(TurnPrediction { state,