Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
snakers4
GitHub Repository: snakers4/silero-vad
Path: blob/master/examples/rust-example/src/utils.rs
1171 views
1
#[derive(Debug, Clone, Copy)]
2
pub enum SampleRate {
3
EightkHz,
4
SixteenkHz,
5
}
6
7
impl From<SampleRate> for i64 {
8
fn from(value: SampleRate) -> Self {
9
match value {
10
SampleRate::EightkHz => 8000,
11
SampleRate::SixteenkHz => 16000,
12
}
13
}
14
}
15
16
impl From<SampleRate> for usize {
17
fn from(value: SampleRate) -> Self {
18
match value {
19
SampleRate::EightkHz => 8000,
20
SampleRate::SixteenkHz => 16000,
21
}
22
}
23
}
24
25
#[derive(Debug)]
26
pub struct VadParams {
27
pub frame_size: usize,
28
pub threshold: f32,
29
pub min_silence_duration_ms: usize,
30
pub speech_pad_ms: usize,
31
pub min_speech_duration_ms: usize,
32
pub max_speech_duration_s: f32,
33
pub sample_rate: usize,
34
}
35
36
impl Default for VadParams {
37
fn default() -> Self {
38
Self {
39
frame_size: 64,
40
threshold: 0.5,
41
min_silence_duration_ms: 0,
42
speech_pad_ms: 64,
43
min_speech_duration_ms: 64,
44
max_speech_duration_s: f32::INFINITY,
45
sample_rate: 16000,
46
}
47
}
48
}
49
50
#[derive(Debug, Default)]
51
pub struct TimeStamp {
52
pub start: i64,
53
pub end: i64,
54
}
55
56
impl std::fmt::Display for TimeStamp {
57
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58
write!(f, "[start:{:08}, end:{:08}]", self.start, self.end)
59
}
60
}
61
62