A simple way to measure the microphone volume meter

Usage no npm install needed!

<script type="module">
  import adrianhurtMicVolumeMeter from 'https://cdn.skypack.dev/@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.


$ npm install @adrianhurt/mic-volume-meter


$ yarn add @adrianhurt/mic-volume-meter


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!'))



  • 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


  • 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.