Skip to main content

rlx_vad/
lib.rs

1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! Voice activity detection on RLX (Earshot + Silero architectures).
17//!
18//! Enable backends via features: `earshot`, `silero` (both on by default).
19
20pub mod audio;
21pub mod device;
22pub mod ops;
23pub mod segments;
24
25#[cfg(feature = "earshot")]
26pub mod earshot;
27
28#[cfg(feature = "silero")]
29pub mod silero;
30
31pub use audio::{
32    SAMPLE_RATE_16K, SpeechSegment, load_wav_mono_f32, parse_wav_mono_f32, resample_linear,
33};
34pub mod cli;
35
36pub use device::{
37    available_device_labels, available_devices, bench_device_label, ensure_backend_ready,
38    parse_device_list, resolve_device, streaming_execution_device,
39};
40pub use segments::SegmentParams;
41#[cfg(feature = "earshot")]
42pub use segments::speech_segments_earshot;
43#[cfg(feature = "silero")]
44pub use segments::speech_segments_silero;
45
46#[cfg(feature = "earshot")]
47pub use earshot::Detector as EarshotDetector;
48
49#[cfg(feature = "silero")]
50pub use silero::{SileroConfig, SileroSession, SileroWeights};
51
52/// Backends compiled into this crate (from Cargo features).
53pub fn enabled_backends() -> &'static [&'static str] {
54    &[
55        #[cfg(feature = "earshot")]
56        "earshot",
57        #[cfg(feature = "silero")]
58        "silero",
59    ]
60}
61
62/// Default `--backend` for the CLI (first enabled backend).
63pub fn default_backend() -> &'static str {
64    #[cfg(feature = "earshot")]
65    {
66        "earshot"
67    }
68    #[cfg(all(not(feature = "earshot"), feature = "silero"))]
69    {
70        "silero"
71    }
72    #[cfg(not(any(feature = "earshot", feature = "silero")))]
73    {
74        "none"
75    }
76}
77
78/// Supported PCM sample rates for Silero.
79#[cfg(feature = "silero")]
80#[derive(Debug, Clone, Copy, PartialEq, Eq)]
81pub enum SampleRate {
82    Hz8000,
83    Hz16000,
84}
85
86#[cfg(feature = "silero")]
87impl SampleRate {
88    pub const fn as_usize(self) -> usize {
89        match self {
90            Self::Hz8000 => 8_000,
91            Self::Hz16000 => 16_000,
92        }
93    }
94
95    pub fn from_hz(hz: usize) -> anyhow::Result<Self> {
96        match hz {
97            8_000 => Ok(Self::Hz8000),
98            16_000 => Ok(Self::Hz16000),
99            _ => anyhow::bail!("unsupported sample rate {hz} (Silero supports 8000 and 16000)"),
100        }
101    }
102}