Stack Exchange
WebAudio Analyser not returning any data
I want to use webAudio to make a simple VU Meter to indicate the volume of a <video> element, which contains a live stream from a Webcam (streaming using Janus).  I have created the following function from other examples. It is called after the stream is initialised, but the array produced by the analyser.getByteFrequencyData(array); method is all zeroes.
function meterInit(){

    audioCtx = new (window.AudioContext || window.webkitAudioContext)();
    videoElement = document.getElementById('remotevideo');
    source = audioCtx.createMediaElementSource(videoElement);

    analyser = audioCtx.createAnalyser();
    analyser.smoothingTimeConstant = 0.2;
    analyser.fftSize = 512;
    analyser.minDecibels = -200;

    source.connect(analyser);
    analyser.connect(audioCtx.destination);

    javascriptNode = audioCtx.createScriptProcessor(2048, 1, 1);
    javascriptNode.connect(audioCtx.destination);

    analyser.connect(javascriptNode);

    javascriptNode.onaudioprocess = function() {

        var array =  new Uint8Array(analyser.frequencyBinCount);
        analyser.getByteFrequencyData(array);
        var average = getAverageVolume(array)
        document.getElementById('vuMeter').value = average;


    }
}


function getAverageVolume(array) {
    var values = 0;
    var average;

    var length = array.length;

    // get all the frequency amplitudes
    for (var i = 0; i < length; i++) {
        values += array[i];
    }

    average = values / length;
    return average;
}


Sounds strange to use a ScriptNode only to make an animation loop, but that should work. You don't have an error in your console? Which browser do you use? From janus, you get a MediaStream? How do you set it?

To begin with to get values for a VU meter you want to use getByteTimeDomainData, not frequency. 
The reason your analyser is not giving readings is because the audio is not being routed anywhere. A script processor node has an input and an output array, you have to copy the input array to the output array to keep the signal going. 
These are properties on the event object of onaudioprocess. 
I would recommend removing the script processor node as it will introduce a large amount of audio latency, at least 2048 samples in your example + script execution time. 
You can move the code inside onaudioprocess into a request animation frame loop, this will cause no audio latency. The only downside is that you are not processing every single sample so you could miss a clip, you should be able to get 60 fps though. 
If detecting clips is important to your application you could look for them in the audio data (all values > 1 or < -1 of the decoded audio data)
Basically all the analyzer node is giving you is a tiny portion of the full audio data and converting it from float to byte format.
Using bytetime domain data actually takes longer than float because internally its float and it has to convert it.
Something you may want to consider is that VU meters use mainly either peak or Rms values, not average. 

see below, thanks for your help.  See below for a response.

@DavidSherman and @Kaiido - thanks for your help. @David, I've marked yours as the correct answer - even though my script isn't actually working yet - as there is some really useful info in here.  To answer your points in turn:

Getting frequency domain data would actually work, as I'd just be getting the average of the peaks across the whole frequency domain.  I know that this isn't as good a representation as RMS in Time Domain, it's good enough for my application. 
Thanks for the tip on request animation frame - I'm now using that.
It seems that my issue is with the <video> element, as the JS Fiddle linked in the comment above works.  I need to go back and look at how I'm generating the <video> element.  It's strange because this works:

var vid = document.getElementById('remotevideo');
vid.muted = !vid.muted;
