vocal_helper.vad module

vocal_helper.vad

Silero-VAD stage. Consumes PcmFrame and emits one VoicedSegment per voiced run.

Algorithm

  • Maintain a rolling buffer.

  • Score every 512-sample (~32 ms @ 16 kHz) Silero window ; threshold at activity_threshold (default 0.5).

  • A speech run starts the first time the score crosses upward, and ends after min_silence_ms of trailing silence below threshold.

  • The emitted PCM is the entire voiced span padded with a small lead/trail margin so the ASR sees the natural envelope (default edge_pad_ms = 200).

  • Runs shorter than min_speech_ms (default 300 ms) are dropped — usually finger taps, lip smacks, room noise.

These thresholds match the canonical pdbms settings ; see pdbms.utils.snr and vad-cadence-study.md §10 for the operating-point justification.

Author

Warith HARCHAOUI — https://linkedin.com/in/warith-harchaoui

class vocal_helper.vad.SileroVADStage(*, activity_threshold=0.5, min_silence_ms=300, min_speech_ms=300, edge_pad_ms=200, sample_rate=16000)[source]

Bases: object

Producer/consumer Silero-VAD stage.

Parameters:
  • activity_threshold (float) – Silero score above which a window is considered voiced. Default 0.5 (canonical).

  • min_silence_ms (int) – Trailing silence required to close a voiced run. Default 300 ms.

  • min_speech_ms (int) – Reject runs shorter than this. Default 300 ms.

  • edge_pad_ms (int) – Lead / trail padding kept around the voiced span so the ASR sees a natural envelope. Default 200 ms.

  • sample_rate (int) – Required to be 16 000 — Silero v5 is trained at 16 kHz.

Notes

The stage owns a single Silero model instance (loaded lazily on first frame). The model is CPU-only ONNX so this is cheap.

async run(inbox, outbox)[source]

Consume PcmFrames from inbox, push VoicedSegments to outbox.

Exits cleanly when a None sentinel is received. Forwards None to outbox so downstream stages can stop too.

Parameters:
  • inbox (Queue)

  • outbox (Queue)

Return type:

None