Implementing Acoustic Echo Cancellation/Suppression in Flash/Flex applications

The new Flash Player 10.3 (yet to be released) has a native Acoustic Echo Cancellation/Suppression algorithm as a feature. Implementation tests within a Flash Audio Video chat system have shown impressive results. In order to implement this though you will need to have the flashplayerglobal for the 10.3 player and update your Flex SDK to 4.5. You will also need to add to the ‘Additional compiler arguments’ input: -swf-version=12. You must have the 10.3 beta player installed - obviously. This is the code I used to test it.

private function getMicrophone() : Microphone {
            var m : Microphone;
            Logger.info('player version:: ' + Capabilities.version);
            if(Capabilities.version.search('10,3') == -1)
            {
                Logger.warn('Enhanced Mic unavailable');
                m = Microphone(Microphone.getMicrophone());
            }else{
                Logger.warn('Enhanced Mic available');
                m = Microphone(Microphone['getEnhancedMicrophone']());
                var options : MicrophoneEnhancedOptions = new MicrophoneEnhancedOptions();
                options.mode = MicrophoneEnhancedMode.FULL_DUPLEX;
                options.autoGain = false;
                options.echoPath = 128;
                options.nonLinearProcessing = true;
                m['enhancedOptions'] = options;
            }
                m.gain = 75;
                // set codec to speex
                m.codec = "Speex";
                m.encodeQuality = 5;
                m.setUseEchoSuppression(true);
                return m;
        }


Enjoy echoless chats :)

20 comments:

Unknown said...

Hi, where did you find the playerglobal.swc for Flash Player 10.3?

mrbinitie said...

http://forums.adobe.com/thread/801429?tstart=0

Look at the link in the first entry of that discussion

kashif said...

dont formet to add these lines

import flash.media.Microphone;
import flash.media.MicrophoneEnhancedOptions;
import flash.media.MicrophoneEnhancedMode;

Unknown said...

Hi

Will this work with webcam chat or only microphone chat ?

Thanks

mrbinitie said...

It will work for both as long as you are passing the microphone

Shawn Shadfar said...

Do you have to convert your project from Flex 3 code to Flex 4 (or 4.5) for this to work? Or could you just compile a flex 3 project in flex 4.5 compiler?

Thank you

mrbinitie said...

compile with the 4.5 SDK, use the 10,3 playerglobal and have the compiler instructions set as in the blog post

Jim Chao said...

why I can still hear echo (from speaker to mic) ... anything missing?

mrbinitie said...

it should work.I' ve had enough proof on apps I've deployed.I'd need more info to help debug this

rahul said...

Can i use AEC, FP10.3 with FlashBuilder 4.0 ? I am able to use it with FlashBuilder 4.5 trial version, but since I have a licensed copy of FB 4.0 I want to implement it in that !! please help aYo ii !!! Thanks

mrbinitie said...

You can use FB4. You do need to get the correct playerglobal.swc and you need to publish to the correct player version.

mrbinitie said...

I used FDT4 with the Flex 4 SDK when I wrote this post.

Unknown said...

hi,
someone know the algorithm used for Acoustic Echo Cancellation in Flash?

Shirish Bhatt said...

Hi,

This is Shirish here. I am still facing the issue of echos after adding your code. Could you please help me out with resolving this issue. I reverted back my code to below -

public function attachAudio():void
{
if(!_sendingAudio)
{
var microphone:Microphone = Microphone.getEnhancedMicrophone();


if(microphone == null)
{
microphone = Microphone.getMicrophone();
}

if (microphone)
{
setMicrophoneDefaults(microphone);
_stream.attachAudio(microphone);
_sendingAudio = true;
}
else
{
trace("No microphone found");
}
}
}


private function setMicrophoneDefaults(microphone:Microphone):void
{
microphone.codec = SoundCodec.NELLYMOSER;
microphone.rate = 11;
microphone.setSilenceLevel(0, 2000);
microphone.gain = 50;
}

Unknown said...

Hello
I am developing a video chat application for android devices. The chat is almost ready but I am facing issue with android device microphone. It is giving bad echo. Can you guide me what best practice to use for mic audio while developing a mobile chat application.
Please revert back ASAP.

Thankss

Unknown said...

Not supported in iOS.

No more development is being done by adobe as they wind down all future flash platform.

kenmckaba said...

Has anyone gotten echo cancellation to work? I'm using RTMP, does it only work on RTMFP? Is there a trick?

Are there other resources for solving this?

mrbinitie said...

AFAIK acoustic echo cancellation can only be implemented using the RTMFP protocol.

I have done little or no AMS development for a while, I'm more involved with Android development now

iWEB TECHNOLOGIES said...

Thankful for a such wonderful blog yours...!
Flash Application Development

mrbinitie said...

@iWEB my apologies for such a late response. I'm truly glad that my small offerings have been of use to you

My Instagram