How to use ZEGOCLOUD SDK to implement Acoustic Echo Cancellation、Automatic Gain Control、Active Noise Control in android
Tags: android, sdk, ae, tutorial
Published: 2022-05-20 02:39:17

![](https://resource.zegocloud.com/content_resource/2022/05/18/16510311268680.jpg)

## Introduction

To promote audio quality and user experience, ZEGOCLOUD provides the ability to process audio with 3A technologies, including AEC, AGC, and ANS. 

- AEC (Acoustic Echo Cancellation): A method of removing the echo from the audio signal captured by the microphone. After this feature is enabled, the SDK will filter the collected audio data to remove the echo.
- AGC (Automatic Gain Control): A feature that automatically adjusts the receiver's audio gain (volume). After this feature is enabled, the sound will be amplified, but the sound quality will be affected to some extent.
- ANS (Active Noise Control): A set of audio technologies that actively cancel the ambient noise. Enabling this feature will make your voice clearer.

## Prerequisites

Before you begin, make sure you complete the following steps:

- Create a project in [ZEGOCLOUD Admin Console](https://console.zegocloud.com?_source=medium&article=4), and get the AppID of your project.
- The ZEGO Express SDK has been integrated into the project. For details, see [Integration](https://docs.zegocloud.com/article/195?_source=medium&article=4) and [Implementation](https://docs.zegocloud.com/article/10836?_source=medium&article=4).

## Set up audio 3A processing

### Set up the AEC (Acoustic Echo Cancellation)

To implement the AEC feature, do the following: 

1. To enable the AEC feature, call the `enableAEC` method. 

2. Optional: To enable the AEC feature for the headphones scenario, call the `enableHeadphoneAEC` method.

3. To set the AEC mode, call the `setAECMode` mode. 

The following sample code is used for setting the AEC to the medium mode (`ZegoAECMode.MEDIUM`): 

```java
// Enable the AEC feature.
engine.enableAEC(true);
// Enable the AEC when using headphones.
engine.enableHeadphoneAEC(true);
// Set the AEC to medium mode (ZegoAECMode.MEDIUM).
engine.setAECMode(ZegoAECMode.MEDIUM);
```

### Set up the AGC (Automatic Gain Control)
To enable the AGC, call the `enableAGC` method. After this function is turned on, the SDK can automatically adjust the Microphone Volume to adapt to near and far sound pickups and keep the Volume stable.

```java
// Enable the AGC feature.
engine.enableAGC(true);
```


### Set up the ANS (Active Noise Control)
To implement the ANS feature, do the following: 

1. To enable the ANS feature, call the `enableANS` method. 

2. Optional: To control or cancel the transient noise, call the `enableTransientANS` method. This feature can be used to suppress the noise of typing keyboard, table, etc. 

3. To set or adjust the ANS mode, call the `setANSMode` method. The SDK uses medium mode (`ZegoANSMode.MEDIUM`) by default. 


The following sample code is used for setting the ANS to the soft mode (`ZegoANSMode.SOFT`): 

```java
// Enable the ANS feature.
engine.enableANS(true);
// Enable the transient ANS feature to control the transient noise.
engine.enableTransientANS(true);
// Set the ANS to soft mode (ZegoANSMode.SOFT).
engine.setANSMode(ZegoANSMode.SOFT);
```

### Recommended configurations for 3A 
The default and recommended configurations for audio 3A processing in the SDK are as follows:

|Method|Description|Default config|Recommended config|
|-|-|-|-|
|`enableAEC`|Enable/Disable the AEC feature. |True| We recommend you use the default settings for general scenarios.|
|`enableHeadphoneAEC`| Enable the AEC for the headphone scenario. |False| We recommend you enable this for chatting or playing games in groups.|
|`setAECMode`| Set the AEC mode.|ZegoAECMode.AGGRESSIVE (Aggressive mode)| We recommend you use the default settings for general scenarios. |
|`enableAGC`| Enable/Disable the AGC feature. |True|<ul><li> In the chatting scenario, use the default settings.</li><li><font size=5>In the music radio scenario, disable the AGC feature to keep original sound.</font></li><li> In the educational scenarios, such as large classes, small classes, and 1v1 classes, enable the AGC feature.</li></ul>|
|`enableANS`|Enable/Disable the ANS feature. |True| We recommend you use the default settings for general scenarios. |
|`setANSMode`| Set the ANS mode. |ZegoANSMode.MEDIUM (Medium mode)|We recommend you use the default settings for general scenarios.|