DecibelMeter
Monitor dB Levels Using HTML5 Audio API
DecibelMeter allows you to monitor the noise level using your device's microphone(s) from within a web page or node-webkit application.
// connect to first audio input device found0 console
Browser Support
I have tested this in Chrome and Firefox for Windows and Android. iOS support is not available yet.
Live Example
You can try the DecibelMeter now: DecibelMeter example
Installation
npm install --save decibel-meter
Usage Examples
Import DecibelMeter
as ES6 module
Or, using a script tag
Create a decibel meter
const meter = 'unique-id';
Get a list of audio sources on the device
// resolves with array of MediaDeviceInfo objects, filtered by type: audioinputmetersources
Connect to an audio source
// first method metersources // second method meter // find audioinput by deviceId, and connect if possiblemeter // find the first audioinput, and connect if possible // handling errors meter
Do something with the decibel data
const level = document meter // display current dB level
Start listening to audio source
meter // "sample" callback set above will now receive data
Stop listening to audio source
meter
Disconnect from the audio source entirely
meter // returns Promise
Connect to a source, add a 'sample' event listener, and start listening to the connected source, in one terse command
meter
Multiple meters on one page
var meter1 = 'meter-1'var meter2 = 'meter-2' DecimelMetermeters // all meters created on this page meter1 === DecimelMeter; // true
Events
DecibelMeter has its own events dispatcher, and supports the following Events
change
connect
disconnect
sample
change
- the meter's listening
state has changed
meter
connect
- the meter successfully connected to an audioinput
meter
disconnect
- the meter was disconnected from a source
sample
- the meter received decibel data from the source