Skip to content

Commit 265e95d

Browse files
committed
more vad tests
1 parent cfda4de commit 265e95d

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ hypr-stt = { path = "crates/stt", package = "stt", features = ["realtime", "reco
4343
hypr-template = { path = "crates/template", package = "template" }
4444
hypr-timeline = { path = "crates/timeline", package = "timeline" }
4545
hypr-turso = { path = "crates/turso", package = "turso" }
46+
hypr-vad = { path = "crates/vad", package = "vad" }
4647
hypr-whisper = { path = "crates/whisper", package = "whisper" }
4748
hypr-ws = { path = "crates/ws", package = "ws" }
4849
hypr-ws-utils = { path = "crates/ws-utils", package = "ws-utils" }

crates/chunker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ hound = { workspace = true }
88
hypr-data = { workspace = true }
99

1010
[dependencies]
11+
hypr-vad = { workspace = true }
1112
kalosm-sound = { workspace = true, default-features = false }
1213
rodio = { workspace = true, features = ["wav"] }
1314

crates/vad/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ tracing = { workspace = true }
1010

1111
ndarray = "0.16"
1212
ort = "=2.0.0-rc.9"
13+
14+
[dev-dependencies]
15+
hypr-data = { workspace = true }

crates/vad/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,27 @@ mod tests {
110110
use super::*;
111111

112112
#[test]
113-
fn test_vad() {
113+
fn test_vad_silence() {
114114
let mut vad = Vad::new().unwrap();
115115
let audio_samples = vec![0.0; 16000];
116116
let prob = vad.run(&audio_samples).unwrap();
117117
assert!(prob < 0.1);
118118
}
119+
120+
#[test]
121+
fn test_vad_long() {
122+
let mut vad = Vad::new().unwrap();
123+
let audio_samples = to_f32(hypr_data::english_2::AUDIO);
124+
let prob = vad.run(&audio_samples).unwrap();
125+
assert!(prob > 0.8);
126+
}
127+
128+
fn to_f32(bytes: &[u8]) -> Vec<f32> {
129+
let mut samples = Vec::with_capacity(bytes.len() / 2);
130+
for chunk in bytes.chunks_exact(2) {
131+
let sample = i16::from_le_bytes([chunk[0], chunk[1]]) as f32 / 32768.0;
132+
samples.push(sample);
133+
}
134+
samples
135+
}
119136
}

0 commit comments

Comments
 (0)