webrtcvad

package module
v0.0.0-...-a6269e3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2023 License: BSD-3-Clause, MIT Imports: 4 Imported by: 0

README

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.

Usage

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

go get github.com/maxhawkins/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)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type VAD

type VAD struct {
	// contains filtered or unexported fields
}

func New

func New() (*VAD, error)

func (*VAD) Process

func (v *VAD) Process(fs int, audioFrame []byte) (activeVoice bool, err error)

func (*VAD) SetMode

func (v *VAD) SetMode(mode int) error

func (*VAD) ValidRateAndFrameLength

func (v *VAD) ValidRateAndFrameLength(rate int, frameLength int) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL