Skip to content
Python interface to the WebRTC Voice Activity Detector
Branch: master
Clone or download
wiseman Merge pull request #18 from rahimnathwani/rahimnathwani-patch-1
Update example.py to accept 48kHz files
Latest commit e86f2fd Nov 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cbits updated webrtc Nov 24, 2018
.gitignore Ignore emacs backup files. Apr 23, 2016
.travis.yml
LICENSE
MANIFEST.in Preparing for deployment to pypi. Apr 24, 2016
README.rst
example.py
leak-test.wav
setup.py Added c++11 for linux build & mark python 3.6 and 3.7 as supported Nov 24, 2018
test-audio.raw It works. Apr 23, 2016
test_webrtcvad.py
webrtcvad.py

README.rst

https://travis-ci.org/wiseman/py-webrtcvad.svg?branch=master

py-webrtcvad

This is a python interface to the WebRTC Voice Activity Detector (VAD). It is compatible with Python 2 and Python 3.

A VAD classifies a piece of audio data as being voiced or unvoiced. It can be useful for telephony and speech recognition.

The VAD that Google developed for the WebRTC project is reportedly one of the best available, being fast, modern and free.

How to use it

  1. Install the webrtcvad module:

    pip install webrtcvad
    
  2. Create a Vad object:

    import webrtcvad
    vad = webrtcvad.Vad()
    
  3. Optionally, set its aggressiveness mode, which is an integer between 0 and 3. 0 is the least aggressive about filtering out non-speech, 3 is the most aggressive. (You can also set the mode when you create the VAD, e.g. vad = webrtcvad.Vad(3)):

    vad.set_mode(1)
    
  4. Give it a short segment ("frame") of audio. The WebRTC VAD only accepts 16-bit mono PCM audio, sampled at 8000, 16000, 32000 or 48000 Hz. A frame must be either 10, 20, or 30 ms in duration:

    # Run the VAD on 10 ms of silence. The result should be False.
    sample_rate = 16000
    frame_duration = 10  # ms
    frame = b'\x00\x00' * (sample_rate * frame_duration / 1000)
    print 'Contains speech: %s' % (vad.is_speech(frame, sample_rate)
    

See example.py for a more detailed example that will process a .wav file, find the voiced segments, and write each one as a separate .wav.

How to run unit tests

To run unit tests:

pip install -e ".[dev]"
python setup.py test

History

2.0.10

Fixed memory leak. Thank you, bond005!

2.0.9

Improved example code. Added WebRTC license.

2.0.8

Fixed Windows compilation errors. Thank you, xiongyihui!
You can’t perform that action at this time.