Registry / ai-ml / pyvad
library0.2.0pypypiunverified

Pyvad is a Python wrapper for the `py-webrtcvad` library, designed for trimming speech clips from audio. It provides a simplified interface for Voice Activity Detection (VAD) functionality, allowing users to identify and extract voiced segments from audio data. The current version is 0.2.0, released in July 2022, with an infrequent release cadence.

pip install pyvad
INSTALL
IMPORT
SIG · PYVAD
P
pyvad
ai-mlpythonv0.2.0
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
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.10–3.920 runs
build_error
glibc
py 3.10–3.920 runs
build_error
Code
Verified usage

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

pyvad
✓ import pyvad
✗ import pyvad

This quickstart demonstrates how to use `pyvad` to perform Voice Activity Detection and trim silence from a simulated audio clip. It generates a sample audio array with speech and silence segments, then applies the `vad` and `trim` functions. The `vad` function returns an array indicating voiced/unvoiced segments, and `trim` returns the audio with leading/trailing silence removed, along with the start and end indices of the speech.

import numpy as np from pyvad import vad, trim # Simulate audio data (e.g., 1 second of speech, 1 second of silence) fs = 16000 # Sample rate in Hz (WebRTC VAD supported rate) duration_speech = 1.0 # seconds duration_silence = 1.0 # seconds # Generate a simple sine wave for 'speech' t = np.linspace(0, duration_speech, int(fs * duration_speech), endpoint=False) speech_data = 0.5 * np.sin(2 * np.pi * 440 * t) # 440 Hz sine wave # Generate silence silence_data = np.zeros(int(fs * duration_silence)) # Combine speech and silence audio_data = np.concatenate((silence_data, speech_data, silence_data)).astype(np.float32) print(f"Audio data shape: {audio_data.shape}, Sample rate: {fs} Hz") # Perform Voice Activity Detection vact = vad(audio_data, fs) print(f"Voice activity array shape: {vact.shape}") # vact will contain 1s for voiced segments, 0s for unvoiced # Trim silence from the audio trimmed_audio, (start_idx, end_idx) = trim(audio_data, fs) print(f"Trimmed audio shape: {trimmed_audio.shape}") print(f"Original audio length: {len(audio_data) / fs:.2f}s") print(f"Trimmed audio from {start_idx/fs:.2f}s to {end_idx/fs:.2f}s, total {len(trimmed_audio)/fs:.2f}s")
Debug
Known issues
breakingPyvad v0.2.0 introduced significant breaking changes, specifically restricting Python version compatibility to 3.8 and 3.9 only. Earlier versions might support Python 3.6+ or even Python 2.x (for pre-0.1.0 versions). Additionally, the `hoplength` argument was renamed to `hop_length`, and the `trim` function's `return_sec` argument was removed, with `trim` now returning `(start_index, end_index)` directly.
fix
Ensure your Python environment is 3.8 or 3.9. Update your code to use `hop_length` instead of `hoplength` and adjust calls to `trim` to expect `(start_index, end_index)` as the second return value instead of relying on `return_sec`. Review the `example.ipynb` on GitHub for the latest API usage.
affects: >=0.2.0
gotchaThe underlying `webrtcvad` library, and by extension `pyvad`, has strict requirements for audio input parameters. The `fs_vad` (internal sampling frequency for VAD) must be 8000, 16000, 32000, or 48000 Hz, and `hop_length` (frame duration) must be 10, 20, or 30 milliseconds. Input `data` must be mono and scaled correctly: if `int`, between -32768 and 32767; if `float`, between -1.0 and 1.0. Failure to meet these requirements will result in `ValueError` exceptions.
fix
Always ensure your input audio data (`data` and `fs`) and specified VAD parameters (`fs_vad`, `hop_length`, `vad_mode`) adhere to these constraints. Resample your audio to one of the supported `fs_vad` rates if necessary, and normalize `float` data to the -1.0 to 1.0 range or ensure `int` data fits the 16-bit PCM range. Use `librosa.resample` for resampling.
affects: All
gotchaThe `vad_mode` parameter, controlling aggressiveness, must be an integer between 0 and 3. A higher value (e.g., 3) makes the VAD more aggressive in filtering out non-speech, while a lower value (e.g., 0) is less aggressive. Using a value outside this range will raise a `ValueError`.
fix
When calling `vad` or `trim`, set `vad_mode` to 0, 1, 2, or 3 based on your desired aggressiveness. Default is 0.
affects: All
Upgrade
Version history
0.2.0latest on PyPI · released Jul 3, 2022
Audit
Dependencies
numpyrequiredRequired for numerical operations on audio data.
librosarequiredUsed for audio processing, including resampling, within pyvad.
py-webrtcvadrequiredThe core Voice Activity Detector that pyvad wraps.
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
pyvad — pip install pyvad · libregistry