Skip to content

GanymedeNil/go-webrtcvad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A quick n' dirty Go port of py-webrtcvad Voice Activity Detector (VAD).

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.

This project is an upgraded version of maxhawkins/go-webrtcvad

Usage

Go-get the package. You don't need to have webrtc installed.

go get github.com/GanymedeNil/go-webrtcvad

Feed raw audio samples into the VAD:

reader, err := wav.NewReader("test.wav")
if err != nil {
    log.Fatal(err)
}

vad, err := webrtcvad.New()
if err != nil {
    log.Fatal(err)
}

if err := vad.SetMode(2); err != nil {
    log.Fatal(err)
}

rate := 32000 // kHz
frame := make([]byte, 320*2)

if ok := vad.ValidRateAndFrameLength(rate, len(frame)); !ok {
    log.Fatal("invalid rate or frame length")
}
for {
    _, err := io.ReadFull(reader, frame)
    if err == io.EOF || err == io.ErrUnexpectedEOF {
        break
    }
    if err != nil {
        log.Fatal(err)
    }

    active, err := vad.Process(rate, frame)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(active)
}

About

cgo interface to WebRTC Voice Activity Dectection

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published