ar
audio-rms
npm i audio-rms
ar

audio-rms

〰️ Connect a Web Audio API AudioNode and stream out the realtime RMS audio level.

by Matt McKegg

2.0.2 (see all)License:ISCTypeScript:Not Found
npm i audio-rms
Readme

audio-rms

Connect a Web Audio API AudioNode and stream out the realtime RMS audio level.

Install

$ npm install audio-rms

Example

Stereo level meter using html5's meter element.

<meter id='L' min='-20' class='.left' high='0' value='-20' max='6' />
<meter id='R' min='-20' class='.right' high='0' value='-20' max='6' />
var AudioRMS = require('audio-rms')

var leftMeter = document.getElementById('L')
var rightMeter = document.getElementById('R')

var audioContext = new AudioContext()
var output = audioContext.createGain()
output.gain.value = 0.4
output.connect(audioContext.destination)

var oscillator = audioContext.createOscillator()
oscillator.connect(output)
oscillator.start()

// modulate audio level
var lfo = audioContext.createOscillator()
var amp = audioContext.createGain()
lfo.frequency.value = 1
amp.gain.value = 0.4
lfo.connect(amp)
amp.connect(output.gain)
lfo.start()

var rms = AudioRMS(audioContext)
output.connect(rms.input)

rms.on('data', function(data){
  leftMeter.value = Math.max(-40, getDecibels(data[0]))
  rightMeter.value = Math.max(-40, getDecibels(data[1]))
})

function getDecibels(value) {
  if (value == null) return 0
  return Math.round(Math.round(20 * (0.43429 * Math.log(value)) * 100) / 100 * 100) / 100
}

Downloads/wk

12

GitHub Stars

26

LAST COMMIT

6yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

1

OPEN PRs

0
VersionTagPublished
2.0.2
latest
6yrs ago
No alternatives found
No tutorials found
Add a tutorial