actionscript 3 - getMicrophone() in as3 only works when using setLoopBack() -
i want monitor microphone audio input flash ( as3 ).
this tiny part of code, problem in there.
var mic:microphone = microphone.getmicrophone(); mic.setloopback(true); addeventlistener( event.enter_frame, loop ); function loop( event:event ):void { trace( mic.activitylevel ); }
if use code is, can trace activitylevel
, can see values.. ( think volume ? )
well, problem is, audio outputed speakers, don't want... ( mic.setloopback(true);
)
but when try mic.setloopback(false);
, flash doesn't ask microphone premissions anymore , traced activitylevel
stays "-1
".....
so can disable audio loopback or monitor audio data mic. ?
( when "audio data", mean data necessary later bpm detection... think it's byte array of audio, isn't ? )
instead of using setloopback()
, need listen sampledataevent
's microphone
. note section titled "detecting microphone activity" in this adobe article, , in particular note talks ways can listen microphone activity:
note: microphone object dispatches activity events when application monitoring microphone. thus, if not call setloopback( true ), add listener sample data events, or attach microphone netstream object, no activity events dispatched.
var mic:microhpone = microphone.getmicrophone; mic.addeventlistener(sampledataevent.sample_data, onsampledata); function onsampledata(event:sampledataevent):void { trace("activity from: " + mic.name + " level: " + mic.activitylevel); }
this should more optimal solution, sampledataevent
's dispatched when microphone detects sound, opposed current approach works on every frame.
Comments
Post a Comment