From 3c9682cfc5af58802eacb0e56aee01186b259a19 Mon Sep 17 00:00:00 2001 From: Eason WaveKat Date: Thu, 26 Mar 2026 10:28:41 +1300 Subject: [PATCH] feat: upgrade silero backend to v6.2.1 Pin the Silero VAD model download to the v6.2.1 release tag instead of tracking the master branch. Add a version marker file in OUT_DIR so cached v5 models are automatically re-downloaded on upgrade. Document the pinned version and SILERO_MODEL_URL override in README and lib.rs. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 10 +++++++++- crates/wavekat-vad/build.rs | 13 +++++++++---- crates/wavekat-vad/src/backends/silero.rs | 8 ++++---- crates/wavekat-vad/src/lib.rs | 13 +++++++++++-- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 122e6aa..8a7e8e2 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,9 @@ let cleaned = preprocessor.process(&raw_audio); ### ONNX Model Downloads -Silero, TEN-VAD, and FireRedVAD models are downloaded automatically at build time. For offline or CI builds, point to a local model file: +Silero, TEN-VAD, and FireRedVAD models are downloaded automatically at build time. The Silero backend is pinned to **v6.2.1** by default. + +For offline or CI builds, point to a local model file: ```sh SILERO_MODEL_PATH=/path/to/silero_vad.onnx cargo build --features silero @@ -206,6 +208,12 @@ TEN_VAD_MODEL_PATH=/path/to/ten-vad.onnx cargo build --features ten-vad FIRERED_MODEL_PATH=/path/to/fireredvad.onnx FIRERED_CMVN_PATH=/path/to/cmvn.ark cargo build --features firered ``` +To use a different Silero model version, override the download URL: + +```sh +SILERO_MODEL_URL=https://github.com/snakers4/silero-vad/raw/v6.0/src/silero_vad/data/silero_vad.onnx cargo build --features silero +``` + ## Error Handling All backends return `Result`. The error type covers: diff --git a/crates/wavekat-vad/build.rs b/crates/wavekat-vad/build.rs index c5c1ac2..63222da 100644 --- a/crates/wavekat-vad/build.rs +++ b/crates/wavekat-vad/build.rs @@ -63,8 +63,10 @@ fn main() { #[cfg(feature = "silero")] fn setup_silero_model() { const DEFAULT_MODEL_URL: &str = - "https://github.com/snakers4/silero-vad/raw/master/src/silero_vad/data/silero_vad.onnx"; + "https://github.com/snakers4/silero-vad/raw/v6.2.1/src/silero_vad/data/silero_vad.onnx"; const SILERO_MODEL_NAME: &str = "silero_vad.onnx"; + // Bump this when updating the default model URL to invalidate cached downloads. + const SILERO_MODEL_VERSION: &str = "v6.2.1"; // Re-run if these env vars change println!("cargo:rerun-if-env-changed=SILERO_MODEL_PATH"); @@ -72,6 +74,7 @@ fn setup_silero_model() { let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); let model_path = Path::new(&out_dir).join(SILERO_MODEL_NAME); + let version_path = Path::new(&out_dir).join("silero_vad.version"); // Option 1: Use local file if SILERO_MODEL_PATH is set if let Ok(local_path) = env::var("SILERO_MODEL_PATH") { @@ -91,8 +94,9 @@ fn setup_silero_model() { return; } - // Skip download if already exists - if model_path.exists() { + // Skip download if model exists and version matches + let cached_version = fs::read_to_string(&version_path).unwrap_or_default(); + if model_path.exists() && cached_version.trim() == SILERO_MODEL_VERSION { return; } @@ -111,9 +115,10 @@ fn setup_silero_model() { .expect("failed to read model bytes"); fs::write(&model_path, &bytes).expect("failed to write model file"); + fs::write(&version_path, SILERO_MODEL_VERSION).expect("failed to write version marker"); println!( - "cargo:warning=Silero VAD model downloaded to {}", + "cargo:warning=Silero VAD model ({SILERO_MODEL_VERSION}) downloaded to {}", model_path.display() ); } diff --git a/crates/wavekat-vad/src/backends/silero.rs b/crates/wavekat-vad/src/backends/silero.rs index b69e28d..e7b555a 100644 --- a/crates/wavekat-vad/src/backends/silero.rs +++ b/crates/wavekat-vad/src/backends/silero.rs @@ -1,7 +1,7 @@ //! Silero VAD backend using ONNX Runtime. //! //! This backend wraps the [Silero VAD](https://github.com/snakers4/silero-vad) -//! v5 model, a pre-trained LSTM neural network for voice activity detection. +//! v6 model, a pre-trained LSTM neural network for voice activity detection. //! It runs inference via ONNX Runtime (through the [`ort`](https://crates.io/crates/ort) //! crate) and returns continuous speech probability scores between 0.0 and 1.0. //! @@ -24,7 +24,7 @@ //! //! # Model Loading //! -//! The default ONNX model (Silero VAD v5) is embedded in the binary at +//! The default ONNX model (Silero VAD v6) is embedded in the binary at //! compile time — no external files are needed at runtime. For custom //! models, use [`SileroVad::from_file`] or [`SileroVad::from_memory`]. //! @@ -47,7 +47,7 @@ use ndarray::{Array1, Array2, Array3}; use ort::{inputs, session::Session, value::Tensor}; use std::time::{Duration, Instant}; -/// Embedded Silero VAD ONNX model (v5). +/// Embedded Silero VAD ONNX model (v6). /// Downloaded automatically at build time by build.rs. const MODEL_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/silero_vad.onnx")); @@ -57,7 +57,7 @@ const CONTEXT_SIZE: usize = 64; /// LSTM hidden state shape: [2, 1, 128] (h and c states). const STATE_DIM: usize = 128; -/// Voice activity detector backed by the Silero VAD v5 ONNX model. +/// Voice activity detector backed by the Silero VAD v6 ONNX model. /// /// Uses an LSTM neural network to produce continuous speech probability /// scores (0.0–1.0). Internal hidden state and a context buffer persist diff --git a/crates/wavekat-vad/src/lib.rs b/crates/wavekat-vad/src/lib.rs index 489090c..0b2a173 100644 --- a/crates/wavekat-vad/src/lib.rs +++ b/crates/wavekat-vad/src/lib.rs @@ -110,8 +110,11 @@ //! ## ONNX model downloads //! //! The Silero, TEN-VAD, and FireRedVAD backends download their ONNX models -//! automatically at build time. For offline or CI builds, set environment -//! variables to point to local model files: +//! automatically at build time. The Silero backend is pinned to **v6.2.1** by +//! default. +//! +//! For offline or CI builds, set environment variables to point to local model +//! files: //! //! ```sh //! SILERO_MODEL_PATH=/path/to/silero_vad.onnx cargo build --features silero @@ -119,6 +122,12 @@ //! FIRERED_MODEL_PATH=/path/to/model.onnx FIRERED_CMVN_PATH=/path/to/cmvn.ark cargo build --features firered //! ``` //! +//! To use a different Silero model version, override the download URL: +//! +//! ```sh +//! SILERO_MODEL_URL=https://github.com/snakers4/silero-vad/raw/v6.0/src/silero_vad/data/silero_vad.onnx cargo build --features silero +//! ``` +//! //! # Error handling //! //! All backends return [`Result`]. Check a backend's