On a previous stack overflow question, I found this code:
<script>
// this is to store a reference to the input so we can kill it later
var liveSource;
// creates an audiocontext and hooks up the audio input
function connectAudioInToSpeakers(){
var context = new webkitAudioContext();
navigator.webkitGetUserMedia({audio: true}, function(stream) {
console.log("Connected live audio input");
liveSource = context.createMediaStreamSource(stream);
liveSource.connect(context.destination);
console.log(liveSource);
});
}
// disconnects the audio input
function makeItStop(){
console.log("killing audio!");
liveSource.disconnect();
}
// run this when the page loads
connectAudioInToSpeakers();
</script>
which takes audio from the user's microphone and plays it back through the speakers. What I want is the level (amplitude) of the input (eg so I can display a red warning if clipping is occuring, or to tell the user they need to speak up). In the above code, how do I actually get hold of the raw data?
For example how can I log actual numbers to the console? I'm guessing it's all stored in liveSoure?
I don't need any clever canvas animations etc, just a number, that tells me how loud the input is. Is this relatively simple? And if so, how is it done?
Thanks