#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VadState {
Silence,
Speech,
SpeechStart,
SpeechEnd,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VadEvent {
Continue,
SpeechStart,
SpeechEnd,
}
#[derive(Debug, Clone)]
pub struct SpeechSegment {
pub start: f32,
pub end: f32,
pub energy: f32,
}
impl SpeechSegment {
#[must_use]
pub fn duration(&self) -> f32 {
self.end - self.start
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_vad_state_enum() {
let state = VadState::Silence;
assert_eq!(state, VadState::Silence);
assert_ne!(state, VadState::Speech);
}
#[test]
fn test_vad_state_clone() {
let state = VadState::Speech;
let cloned = state;
assert_eq!(state, cloned);
}
#[test]
fn test_vad_event_enum() {
let event = VadEvent::SpeechStart;
assert_eq!(event, VadEvent::SpeechStart);
assert_ne!(event, VadEvent::SpeechEnd);
}
#[test]
fn test_speech_segment_duration() {
let segment = SpeechSegment {
start: 1.0,
end: 3.5,
energy: 0.5,
};
assert!((segment.duration() - 2.5).abs() < f32::EPSILON);
}
#[test]
fn test_speech_segment_clone() {
let segment = SpeechSegment {
start: 0.0,
end: 1.0,
energy: 0.1,
};
let cloned = segment.clone();
assert!((segment.start - cloned.start).abs() < f32::EPSILON);
assert!((segment.end - cloned.end).abs() < f32::EPSILON);
}
#[test]
fn test_speech_segment_debug() {
let segment = SpeechSegment {
start: 0.0,
end: 1.0,
energy: 0.5,
};
let debug = format!("{:?}", segment);
assert!(debug.contains("SpeechSegment"));
}
}