@adrianhurt/mic-volume-meter

0.1.1 • Public • Published

@adrianhurt/mic-volume-meter

MicVolumeMeter allows you to retrieve the microphone's volume with a given interval.

First of all, thank to Chris Wilson's repository that serves as the core for this one.

Install

$ npm install @adrianhurt/mic-volume-meter

or

$ yarn add @adrianhurt/mic-volume-meter

Usage

import MicVolumeMeter from '@adrianhurt/mic-volume-meter'

const volumeMeter = new MicVolumeMeter()

function onNewMeasure ({ volume, time }) {
    console.log(volume, time) // volume from 0 to 1 and time in millisecs from the start time
}

function stop () {
    volumeMeter.stop() // stop the MicVolumeMeter whenever you want
}
function switchOff () {
    volumeMeter.switchOff() // switch off the MicVolumeMeter whenever you want
}

volumeMeter.switchOn() // switches on the MicVolumeMeter
    .then(() => {
        // starts the MicVolumeMeter that will call onNewMicVolumeMeasure each 100 milliseconds
        volumeMeter.start({ onNewMeasure: this.onNewMicVolumeMeasure, interval: 100 })
    })
    .catch(() => alert('Permission denied!'))

MicVolumeMeter

Methods

  • switchOn({ clipLevel, averaging, clipLag }): returns a promise after requesting mic permissions and switching on the MicVolumeMeter. It is rejected if the user denies the mic permissions. Please, check Chris Wilson's repository to know how to use the clipLevel, averaging and clipLag options.
  • start({ onNewMeasure, interval }): starts the MicVolumeMeter and call onNewMeasure callback periodically (with the given interval in milliseconds). onNewMeasure callback will be called with an object as argument with this structure: { volume, time } (volume will be a number from 0 to 1 and time in millisecs from the start time).
  • stop(): stops the MicVolumeMeter.
  • switchOff(): stops (if it was active) and switchs off the MicVolumeMeter.
  • checkClipping(): please, check Chris Wilson's repository to know more about clipping

Properties

  • isActive (readonly): Boolean to know if MicVolumeRecorder is active or not (it's actived when you switch it on and deactivated when you switch it off).
  • volume (readonly): Number from 0 to 1 with the current mic's volume.
  • startAt (readonly): Number in milliseconds elapsed since January 1, 1970 00:00:00 UTC (with Date.now()).
  • meter (readonly): the inner meter object gotten with Chris Wilson's repository.

Package Sidebar

Install

npm i @adrianhurt/mic-volume-meter

Weekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

11.5 kB

Total Files

6

Last publish

Collaborators

  • adrianhurt