webkitaudiocontext - Get audio levels from HTML5 Audio Microphone Stream -
on previous stack overflow question, found code:
<script> // store reference input can kill later var livesource; // creates audiocontext , hooks 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 audio input function makeitstop(){ console.log("killing audio!"); livesource.disconnect(); } // run when page loads connectaudiointospeakers(); </script>
which takes audio user's microphone , plays through speakers. want level (amplitude) of input (eg can display red warning if clipping occuring, or tell user need speak up). in above code, how hold of raw data?
for example how can log actual numbers console? i'm guessing it's stored in livesoure?
i don't need clever canvas animations etc, number, tells me how loud input is. relatively simple? , if so, how done?
thanks
here's how did - can see live @ http://labs.dinahmoe.com/dynamicmusicengine/ connect livesource javascriptnode (there context.createscriptprocessor(4096, 1, 1) new syntax, though both supported according http://www.w3.org/2011/audio/wiki/f2f_mar_2013)
var levelchecker = context.createjavascriptnode(4096, 1 ,1); livesource.connect(levelchecker); levelchecker.connect(context.destination); levelchecker.onaudioprocess = function(e) { var buffer = e.inputbuffer.getchanneldata(0); // iterate through buffer check if of values exceeds 1. (var = 0; < buffer.length; i++) { if (1 =< buffer[i]) { console.log("oh noes! got peak.", buffer[i]); } }
Comments
Post a Comment