speech_prep/vad/
metrics.rs1use crate::monitoring::VADStats;
4use crate::time::AudioDuration;
5
6pub trait VadMetricsCollector: Send + Sync {
8 fn record_vad_metrics(&self, snapshot: &VadMetricsSnapshot);
10}
11
12#[derive(Debug, Clone)]
14pub struct VadMetricsSnapshot {
15 pub stats: VADStats,
17 pub latency: AudioDuration,
19 pub adaptive: AdaptiveThresholdSnapshot,
21}
22
23#[derive(Debug, Clone, Copy, Default)]
25pub struct AdaptiveThresholdSnapshot {
26 pub energy_baseline: f32,
28 pub flux_baseline: f32,
30 pub dynamic_threshold: f32,
32}
33
34impl VadMetricsSnapshot {
35 #[must_use]
37 pub fn new(
38 stats: VADStats,
39 latency: AudioDuration,
40 adaptive: AdaptiveThresholdSnapshot,
41 ) -> Self {
42 Self {
43 stats,
44 latency,
45 adaptive,
46 }
47 }
48
49 #[must_use]
51 pub fn speech_ratio(&self) -> f64 {
52 self.stats.speech_ratio()
53 }
54}
55
56#[derive(Debug, Default, Clone, Copy)]
58pub struct NoopVadMetricsCollector;
59
60impl VadMetricsCollector for NoopVadMetricsCollector {
61 fn record_vad_metrics(&self, _snapshot: &VadMetricsSnapshot) {}
62}