Clap detection module for node js
ClapDetector is a hand clap detection module for nodejs (iojs). It detects a clap or a series of claps and allows you to trigger callbacks whenever these events happen. I created this module for my personal assistant project on a Raspberry Pi (raspbian). The clap detection allows me to activate the assistant whenever I need it (and prevents it from continuously listening out for instructions or interpreting random noises as instructions)
This module works on linux based OS (raspbian, Ubuntu, Debian...) using alsa for audio and a working microphone or Mac OS X using coreaudio.
This module requires sox, "the Swiss Army knife of sound processing programs" (http://sox.sourceforge.net/) to be installed
sudo apt-get install sox
Mac OS X
brew install sox
You can simply add this module to your node.js project with
npm install --save clap-detector
First, create an instance of the ClapDetector class:
const clap = new
Then register a callback that will be triggered whenever a series of hand claps is detected. Your callback will be provided with an array of claps and their associated timestamps as arguments.
const disposableOneClapListener = clap.addClapsListener
You can dispose (remove) a clap listener by calling the disposable method returned by addClapsListeners
Finally you can call the dispose() method when you want to stop all clap detection and free associated resources
- Type : Function
- Arguments: (callback [Function], options [Object])
list of options
|number||Number of claps||1|
|delay||Period within the specified number of claps must be heard (ms)||1000|
|force||If true, trigger callback every time even if a listener with a higher number is triggered||false|
Real life example
import ClapDetector from 'clap-detector'const clap = newclap.addClapsListener
import ClapDetector from 'clap-detector'const clap = newconst disposableOneClapListener = clap.addClapsListener
You can pass a configuration object and override the default values when you create an instance of the ClapDetector class. If you don't the following config will be used.
// DEFAULT CONFIGvar CONFIG =const clap = new ClapDetector
If you wish to improve the clap detection you can fiddle with the CLAP_AMPLITUDE_THRESHOLD and CLAP_ENERGY_THRESHOLD values. Depending on your microphone these might need to be modified.
These will be added soon. Please do not hesitate to submit some Ò!
About the Author
clap-detector is dual licensed under the MIT license and GPL. For more information click here.