npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-vad

v1.1.4

Published

Voice Activity Detection library for Node

Downloads

4,573

Readme

node-vad

This is a stripped down version of this library (https://github.com/voixen/voixen-vad). Thank you very much!

Voice Activity Detection library

Voice Activity Detection based on the method used in the upcoming WebRTC HTML5 standard. Extracted from Chromium for stand-alone use as a library.

Supported sample rates are:

  • 8000Hz
  • 16000Hz*
  • 32000Hz
  • 48000Hz

*recommended sample rate for best performance/accuracy tradeoff

Installation

API

new VAD(mode)

Create a new VAD object using the given mode.

.processAudio(samples, samplerate)

Analyse the given samples (Buffer object containing 16bit signed values) and notify the detected voice event via promise.

.processAudioFloat(samples, samplerate)

Analyse the given samples (Buffer object containing 32bit normalized float values) and notify the detected voice event via promise.

static .createStream(options)

Create an stream for voice activation detection.

Options
{
    mode: VAD.Mode.NORMAL, // VAD mode, see above
    audioFrequency: 16000, // Audiofrequency, see above
    debounceTime: 1000 // Time for debouncing speech active state, default 1 second
}
Stream output example:
{ 
    time: 14520, // Current seek time in audio
    audioData: <Buffer>, // Original audio data
    speech: { 
        state: true, // Current state of speech
        start: false, // True on chunk when speech starts
        end: false, // True on chunk when speech ends
        startTime: 12360, // Time when speech started
        duration: 2160 // Duration of current speech block
    } 
}

Event codes

Event codes are passed to the processAudio promises.

VAD.Event.ERROR

Constant for voice detection errors.

VAD.Event.SILENCE

Constant for voice detection results with no detected voices.

VAD.Event.VOICE

Constant for voice detection results with detected voice.

VAD.Event.NOISE

Constant for voice detection results with detected noise. Not implemented yet

Available VAD Modes

These contants can be used as the mode parameter of the VAD constructor to configure the VAD algorithm.

VAD.Mode.NORMAL

Constant for normal voice detection mode. Suitable for high bitrate, low-noise data. May classify noise as voice, too. The default value if mode is omitted in the constructor.

VAD.Mode.LOW_BITRATE

Detection mode optimised for low-bitrate audio.

VAD.Mode.AGGRESSIVE

Detection mode best suited for somewhat noisy, lower quality audio.

VAD.Mode.VERY_AGGRESSIVE

Detection mode with lowest miss-rate. Works well for most inputs.

Notes

The library is designed to work with input streams in mind, that is, sample buffers fed to processAudio should be rather short (36ms to 144ms - depending on your needs) and the sample rate no higher than 32kHz. Sample rates higher than than 16kHz provide no benefit to the VAD algorithm, as human voice patterns center around 4000 to 6000Hz. Minding the Nyquist-frequency yields sample rates between 8000 and 12000Hz for best results.

Example

See examples folder for a working examples with a sample audio file.

Non-stream example:

const vad = new VAD(VAD.Mode.NORMAL);

const stream = fs.createReadStream("demo_pcm_s16_16000.raw");
stream.on("data", chunk => {
    vad.processAudio(chunk, 16000).then(res => {
        switch (res) {
            case VAD.Event.ERROR:
                console.log("ERROR");
                break;
            case VAD.Event.NOISE:
                console.log("NOISE");
                break;
            case VAD.Event.SILENCE:
                console.log("SILENCE");
                break;
            case VAD.Event.VOICE:
                console.log("VOICE");
                break;
        }
    }).catch(console.error);
});

Stream example:

const inputStream = fs.createReadStream("demo_pcm_s16_16000.raw");
const vadStream = VAD.createStream({
    mode: VAD.Mode.NORMAL,
    audioFrequency: 16000,
    debounceTime: 1000
});

inputStream.pipe(vadStream).on("data", console.log);

License

MIT