Registry / ai-ml / webrtcvad

webrtcvad

JSON →
library2.0.10pypypiunverified

webrtcvad is a Python interface to the Google WebRTC Voice Activity Detector (VAD). It classifies short segments of audio as being voiced or unvoiced, useful for telephony and speech recognition. The current version is 2.0.10, with releases historically following an infrequent, as-needed cadence to incorporate upstream WebRTC VAD changes or bug fixes.

ai-mlcommunication
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

import webrtcvad

Initializes the VAD, sets its aggressiveness mode, and demonstrates classifying silence and a mock speech segment. It highlights the strict audio format requirements: 16-bit mono PCM at 8000, 16000, 32000, or 48000 Hz, with frame durations of 10, 20, or 30 ms.

import webrtcvad import struct # WebRTC VAD requires 16-bit mono PCM audio at specific sample rates # and frame durations (10, 20, or 30 ms). sample_rate = 16000 # Hz frame_duration_ms = 30 # ms bytes_per_sample = 2 # 16-bit audio # Calculate frame size in bytes frame_size_bytes = int(sample_rate * (frame_duration_ms / 1000.0) * bytes_per_sample) # Create a VAD instance with an aggressiveness mode (0-3) # 0: least aggressive, 3: most aggressive vad = webrtcvad.Vad(3) # Create a silent audio frame (16-bit mono PCM) silence_frame = b'\x00\x00' * int(frame_size_bytes / bytes_per_sample) # Create a mock speech-like frame (simple sine wave for demonstration) # In a real application, this would come from an audio input. speech_frame = b'' for i in range(int(frame_size_bytes / bytes_per_sample)): # Simple sine wave approximation for a speech-like signal amplitude = 10000 # Max 32767 for 16-bit value = int(amplitude * (i % 30 < 15) - amplitude * (i % 30 >= 15)) # Square wave approximation speech_frame += struct.pack('<h', value) print(f"Processing frame of {frame_duration_ms} ms at {sample_rate} Hz") # Test with silence is_speech_silence = vad.is_speech(silence_frame, sample_rate) print(f"Silence frame contains speech: {is_speech_silence}") # Test with speech-like audio is_speech_mock = vad.is_speech(speech_frame, sample_rate) print(f"Mock speech frame contains speech: {is_speech_mock}") # You can also set the mode after initialization vad.set_mode(1) print(f"VAD aggressiveness set to 1.")
Debug
Known footguns
gotchaThe WebRTC VAD has strict audio input requirements: 16-bit, mono PCM audio, sampled at 8000, 16000, 32000, or 48000 Hz. Frames must be exactly 10, 20, or 30 ms in duration.
gotchaThe `webrtcvad` package (wiseman/py-webrtcvad) can be difficult to install on some platforms due to its C/C++ dependencies and lack of pre-built wheels for all Python versions/OS combinations.
gotchaVersion 2.0.10 fixed a memory leak in the `is_speech()` method. While 2.0.10 should contain this fix, later versions of the `webrtcvad-wheels` fork (e.g., 2.0.13) address further memory leak issues.
gotchaThe WebRTC VAD is a simple, real-time oriented model and may produce false positives for non-speech sounds (e.g., music, birdsong) or false negatives in very noisy environments, even at high aggressiveness settings.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
143 hits · last 30 days
chatgpt-user
5
dotbot
4
mj12bot
3
ahrefsbot
3
googlebot
3
oai-searchbot
2
script
1
perplexity-user
1
Resources