Instead of using setLoopBack()
, you just need to listen for SampleDataEvent
's from the Microphone
. Note the section titled "Detecting Microphone Activity" in this Adobe article, and in particular this note that talks about ways you can listen for microphone activity:
Note: A Microphone object only dispatches Activity events when your application is monitoring the microphone. Thus, if you do not call setLoopBack( true ), add a listener for sample data events, or attach the microphone to a NetStream object, then no activity events are 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 be a more optimal solution, as the SampleDataEvent
's are only dispatched when the microphone detects sound, as opposed to your current approach that works on every frame.