Giter VIP home page Giter VIP logo

vad-audio-worklet's Introduction

NPM Version

VAD AudioWorklet

AudioWorklet implementation of the vad algorithm from Moattar, Mohammad & Homayoonpoor, Mahdi .

Example Mic/File
Full Example with Debug Data

Reference

Moattar, Mohammad & Homayoonpoor, Mahdi. (2010). A simple but efficient real-time voice activity detection algorithm. European Signal Processing Conference.

https://www.researchgate.net/publication/255667085_A_simple_but_efficient_real-time_voice_activity_detection_algorithm

Install

Copy the files from /src to your public folder.

src/vad-audio-worklet.js
src/fft.js

When using npm install you need to copy the files from node_modules into your project directory. ES6 module import wouldn't work.

npm install vad-audio-worklet

Usage

Copy the files in /src to your project. Create a new AudioContext, load the vad module and connect the vad worklet node to some audio source.

More on how to use the Web Audio API see https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

// create AudioContext
const audioContext = new AudioContext();

// load AudioWorklet module
await audioContext.audioWorklet.addModule("/src/vad-audio-worklet.js");

// create new vad audio node
const vad = new AudioWorkletNode(audioContext, "vad", {
  outputChannelCount: [1],
  processorOptions: {
    sampleRate: audioContext.sampleRate, // sample rate of the audio input
    fftSize: 128, // optional change fft size, default: 128
  },
});

// connect worklet to some audio source
yourAudioSource.connect(vad);

// listen for messages
vad.port.onmessage = (event) => {
  const cmd = event.data["cmd"];

  if (cmd === "speech") {
    // speech detected
  }

  if (cmd === "silence") {
    // silence , cpt. obvious
  }
};

Example File

example/alert.ogg Radio Universidad Nacional de La Plata, CC BY-SA 3.0, via Wikimedia Commons

Credits

fft.js
https://github.com/indutny/fft.js/

Moattar, Mohammad & Homayoonpoor, Mahdi. (2010). A simple but efficient real-time voice activity detection algorithm. European Signal Processing Conference.
https://www.researchgate.net/publication/255667085_A_simple_but_efficient_real-time_voice_activity_detection_algorithm

MDN Docs: Web Audio API
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
https://openwebdocs.org/

vad-audio-worklet's People

Contributors

thurti avatar

Stargazers

Gideon Stele avatar Felipe  avatar Xiyang Chen avatar wervice avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.