on-clap
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

on-clap GitHub issues

Do something when you hear a clap (or any loud noise)

Alt Text

Install:

with npm:

npm i on-clap

with yarn:

yarn install on-clap

Usage

Basic Usage

in its most basic usage you pass a callback function to be called after a clap is heard:

import {onClap} from 'on-clap';
onClap(() => console.log("there was a clap!"))              

Note this will ask the user for access to thier microphone as it uses MediaDevices.getUserMedia() under the hood.

Options

An options object can also be passed to onClap:

import {onClap} from 'on-clap';
const options = {
    sens: 1.5, // how loud a clap we need to hear to trigger the call back. Bigger is more sensitive. Default = 1
    repeat: false, //If you want on clap to trigger multiple times or only once. Default = false.
    additionalConditions: () => 2 == 2, //A function which returns true if some additional conditions are met. Default = () => true.
    inputDeviceId: "1235a1", //The input device idea we listen to the clap on. Default = "default"
    ctx: someAudioContext, // a pre-existing audio context if we want to use it. Default = new AudioContext().
};

onClap(() => console.log("there was a clap"), options);

Listening for claps on an existing AudioNode

if you have a pre-existing AudioNode you would like to listen for claps you can use the onClapAudioNode function:

import {onClapAudioNode} from 'on-clap';
onClapAudioNode(someExistingAudioNode, () => console.log("there was a clap"))

the options from above can also be passed on:

onClapAudioNode(someExistingAudioNode, () => console.log("there was a clap"), options)

Readme

Keywords

Package Sidebar

Install

npm i on-clap

Weekly Downloads

0

Version

0.1.4

License

none

Unpacked Size

8.46 kB

Total Files

6

Last publish

Collaborators

  • jackmckayfletcher