class

Whisper::Vad

Inherits Reference < Object

Voice Activity Detection (VAD) subsystem.

Loads a standalone VAD model and detects speech segments in audio data independently of the main Whisper transcription pipeline.

vad = Whisper::Vad.new("/path/to/silero-vad.onnx")
segments = vad.detect(samples)
segments.each { |seg| puts "Speech: #{seg.start_seconds}s - #{seg.end_seconds}s" }
vad.close

Constructors

new(model_path : String, n_threads : Int32 = 4, use_gpu : Bool = false)

Loads a VAD model from disk.

model_path should point to a Silero VAD model file. n_threads sets the number of CPU threads for processing. Set use_gpu to true to enable GPU acceleration.

Source

Instance methods

close

Frees the underlying VAD context. Safe to call multiple times.

Source
closed?
Source
detect(samples : Array(Float32), threshold : Float32 = 0.5_f32, min_speech_duration_ms : Int32 = 250, min_silence_duration_ms : Int32 = 100, max_speech_duration_s : Float32 = Float32::MAX, speech_pad_ms : Int32 = 30, samples_overlap : Float32 = 0.0_f32) : Array(SpeechSegment)

Runs speech detection on audio samples and returns speech segments.

samples must be 32-bit float PCM audio normalized to [-1.0, 1.0], mono, at 16kHz. VAD parameters can be customized via optional keyword arguments.

Source
detect_speech(samples : Array(Float32)) : Bool

Runs speech probability computation on audio samples.

Returns true if speech was detected, and makes probabilities accessible via #n_probs and #probs.

Source
finalize
Source
n_probs

Returns the number of probability values from the last detect_speech call.

Source
probs

Returns a Slice of speech probabilities from the last detect_speech call.

Source
segments_from_probs(threshold : Float32 = 0.5_f32, min_speech_duration_ms : Int32 = 250, min_silence_duration_ms : Int32 = 100, max_speech_duration_s : Float32 = Float32::MAX, speech_pad_ms : Int32 = 30, samples_overlap : Float32 = 0.0_f32) : Array(SpeechSegment)

Computes speech segments from previously computed probabilities.

Requires detect_speech to have been called first.

Source

Nested types