Closed bknill closed 5 years ago
@bknill hey! Did you find a way to achieve this?
Yes I did.
Here is the function I ended up using,
I put the recorder steam into a global variable (window.recorder.stream)
function microphoneVolume(callback) {
if(!window.recorder.stream)
return
var audioContext = new AudioContext()
var analyser = audioContext.createAnalyser()
var microphone = audioContext.createMediaStreamSource(window.recorder.stream)
var javascriptNode = audioContext.createScriptProcessor(2048, 1, 1)
analyser.smoothingTimeConstant = 0.8
analyser.fftSize = 1024
microphone.connect(analyser)
analyser.connect(javascriptNode)
javascriptNode.connect(audioContext.destination)
javascriptNode.onaudioprocess = function() {
var array = new Uint8Array(analyser.frequencyBinCount)
analyser.getByteFrequencyData(array)
var values = 0
var length = array.length
for (var i = 0; i < length; i++) {
values += (array[i])
}
var average = values / length
if(callback)
callback(Math.round(average))
}
return audioContext
}
Thz @bknill for sharing your solution, it works out-of-the-box for us.
I noticed, however, that createScriptProcessor()
is deprecated, see https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode and that an AudioWorkletNode
should be used.
Are you planning to adopt the latter? Have you had any problems with createScriptProcessor()
in the wild?
Not that I've noticed. If you fix it please let me see the code.
Hi,
I'm trying to get the microphone levels to show in the UI while this is recording.
navigator.mediaDevices.getUserMedia({ audio: true })
isn't receiving the stream while VMSG is running, I assume because VMSG is using the microphone, is it possible to get the steam levels using this?