Trying to figure out why setloopback needs to be set to true for microphone activity to be detected.
The problem is the echo feedback when using a macbook with a built in mic.
If anyone has some ideas about this let me know.
Right now I'm experimenting with toggling gain, depending on activity to simulate echo reduction. Not optimal though.
@lessfame
I was looking for a similar solution to this one, then I found you that you can apply a sound transform to a microphone to control the volume of the outputted volume of the microphone input.
So it can be done this easily:
var st:SoundTransform = new SoundTransform(0);
mic.soundTransform = st;
I know you asked this question almost a year ago now, but thought I'd put it up for anybody looking for an answer.
Cheers,
Will
I know this is an old question but just came across the problem.
There is a bug with the SPEEX codec as noted here: Microphone soundTransform and SPEEX codec bug
This bug basically says that using the SPEEX codec ignores the sound transform. As a work around for this I setup a toggle function to switch the settings for the microphone to display activity before the audio is attached to a NetStream and to work around the bug.
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. AS3 Docs
Setup the Mic: (m is an instance variable)
m = Microphone.getMicrophone();
m.setSilenceLevel(0);
m.gain = 75;
m.setUseEchoSuppression(true);
m.rate = 16; //rate only applies to NELLYMOSER Codec - but 16 kHz matches SPEEX default setting
m.setLoopBack(true); //necessary to get activity
m.codec = SoundCodec.NELLYMOSER; //this is default
m.soundTransform = new SoundTransform(0); //mute so you don't get crazy echo!
Toggle for 'offline' and 'online' activity monitoring
protected function audioMeterToggle(switch:String) {
if(switch == "offline") {
m.setLoopBack(true);
m.soundTransform.volume = 0;
m.codec = SoundCodec.NELLYMOSER;
} else {
m.setLoopBack(false);
m.soundTransform.volume = 1;
m.codec = SoundCodec.SPEEX;
}
}
Switching codecs helps reduce bandwidth.
Hope this helps save someone some time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With