DEV Community 👩‍💻👨‍💻

AndrewDDev
AndrewDDev

Posted on

How to use ZEGOCLOUD SDK to implement Acoustic Echo Cancellation、Automatic Gain Control、Active Noise Control in android

cover image

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:

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):

// 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);
Enter fullscreen mode Exit fullscreen mode

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.

// Enable the AGC feature.
engine.enableAGC(true);
Enter fullscreen mode Exit fullscreen mode

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):

// 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);
Enter fullscreen mode Exit fullscreen mode

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
  • In the chatting scenario, use the default settings.
  • In the music radio scenario, disable the AGC feature to keep original sound.
  • In the educational scenarios, such as large classes, small classes, and 1v1 classes, enable the AGC feature.
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.

Top comments (0)

🌚 Life is too short to browse without dark mode