Audio 3A Processing
Feature Overview
During real-time audio/video calls or live streaming, you can apply 3A processing to audio, mainly including AEC (Acoustic Echo Cancelling), AGC (Automatic Gain Control), and ANS (Active Noise Control), to improve call or live streaming quality and user experience.
- AEC (Acoustic Echo Cancellation): Filters captured audio data to reduce echoes in the audio.
- AGC (Automatic Gain Control): When enabled, the SDK can automatically adjust microphone volume to accommodate near and far sound pickup, maintaining stable volume levels.
- ANS (Noise Suppression): Identifies and eliminates background noise in audio. When enabled, it makes voice clearer. If users need more aggressive noise suppression strategies, they can use the Scenario-based AI Noise Reduction feature.
If you need to use music scenario detection capabilities, please contact ZEGOCLOUD technical support for special packaging and configuration.
Example Source Code Download
Please refer to Download Example Source Code to get the source code.
For related source code, please view files in the "lib/topics/AudioAdvanced/audio_3a" directory.
Default Configuration and Recommended Configuration
The default and recommended configurations for audio 3A processing in the SDK are as follows:
| Interface Name | Interface Description | Default Configuration | Recommended Configuration |
|---|---|---|---|
| enableAEC | Enable/Disable acoustic echo cancellation. | Before calling this function, the SDK internally automatically determines whether to use AEC. Once this function is called, the SDK no longer makes automatic judgments. | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| enableHeadphoneAEC | Whether to enable acoustic echo cancellation when using headphones. | Not enabled. | In normal voice chat or gaming sessions, it is recommended to enable this feature. In other cases, it is generally not necessary to enable. |
| setAECMode | Set the acoustic echo cancellation mode. | ZegoAECMode.Aggressive (Aggressive echo cancellation). | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| enableAGC | Enable/Disable automatic gain control. | Before calling this function, the SDK internally automatically determines whether to use AGC. Once this function is called, it no longer makes automatic judgments. |
|
| enableANS | Enable/Disable noise suppression. | Before calling this function, the SDK internally automatically determines whether to use ANS. Once this function is called, it no longer makes automatic judgments. | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| enableTransientANS | Enable/Disable transient noise suppression. | Before calling this function, transient noise suppression is not enabled by default. | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| setANSMode | Set audio noise suppression mode. | ZegoANSMode.Medium (Moderate noise suppression). | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
Prerequisites
Before using audio 3A processing, ensure that:
- You have integrated ZEGO Express SDK into your project and implemented basic real-time audio/video functionality. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
- You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to ZEGOCLOUD Console - Project Information.
Usage Steps
Set Up AEC (Acoustic Echo Cancellation)
enableAEC, enableHeadphoneAEC, and setAECMode must all be called before the following interfaces: startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager to be effective.
Developers can complete echo cancellation related settings according to the following steps:
-
Call the enableAEC interface to enable echo cancellation. After enabling this feature, the SDK will filter captured audio data to reduce echoes in the audio.
-
(Optional) Developers can call the enableHeadphoneAEC interface to set whether to enable echo cancellation when using headphones.
-
After enabling echo cancellation, developers can call the setAECMode interface to set the echo cancellation mode. The SDK supports the following three echo cancellation modes:
Enum Value Description ZegoAECMode.Aggressive Aggressive echo cancellation, which may significantly affect audio quality, but eliminates echoes thoroughly. ZegoAECMode.Medium Moderate echo cancellation, which may slightly affect audio quality, but results in less residual echo. ZegoAECMode.Soft Comfortable echo cancellation, which basically doesn't affect audio quality, though may occasionally leave slight residual echo, but won't affect normal listening.
Express SDK supports AI echo cancellation, which further improves voice fidelity on top of effective echo elimination. If you need to use AI echo cancellation, please contact ZEGOCLOUD technical support for special packaging.
Taking setting moderate echo cancellation as an example:
// Enable AEC
ZegoExpressEngine.instance.enableAEC(true);
// Enable AEC when using headphones
ZegoExpressEngine.instance.enableHeadphoneAEC(true);
// Set AEC mode to ZegoAECMode.MEDIUM
ZegoExpressEngine.instance.setAECMode(ZegoAECMode.Medium);Set Up AGC (Automatic Gain Control)
enableAGC must be called before the following interfaces: startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager to be effective.
Call the enableAGC interface to enable automatic gain control. After enabling this feature, the SDK can automatically adjust microphone volume to accommodate near and far sound pickup, maintaining stable volume levels.
// Enable AGC
ZegoExpressEngine.instance.enableAGC(true);Set Up ANS (Noise Suppression)
enableANS, enableTransientANS, and setANSMode must all be called before the following interfaces: startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager to be effective.
Developers can complete noise suppression related settings according to the following steps:
-
Call the enableANS interface to enable noise suppression. After enabling this feature, voice becomes clearer.
-
(Optional) Developers can call the enableTransientANS interface to set whether to enable transient noise suppression. Transient noise suppression is used to suppress transient noises such as keyboard typing and table tapping.
-
After enabling noise suppression, developers can call the setANSMode interface to set the noise suppression mode. The default value is "Medium". The SDK supports the following four noise suppression modes:
Enum Value Description ZegoANSMode.Aggressive Aggressive noise suppression, which may significantly damage audio quality but has excellent noise reduction effects. ZegoANSMode.Medium (Default) Moderate noise suppression, which may damage some audio quality but has good noise reduction effects. ZegoANSMode.Soft Light noise suppression, which basically doesn't damage audio quality but may leave some residual noise.
Express SDK supports AI mode noise suppression, providing three modes: lightweight, balanced, and low latency. On top of eliminating steady-state noise, it effectively eliminates transient noises such as keyboards, coughing, wind, car horns, etc. For details, please refer to Scenario-based AI Noise Reduction.
- (Optional) Enable music detection. Please contact ZEGOCLOUD technical support to configure and enable the music detection feature.
Taking setting light noise suppression as an example:
// Enable ANS
ZegoExpressEngine.instance.enableANS(true);
// Enable transient noise suppression
ZegoExpressEngine.instance.enableTransientANS(true);
// Set ANS mode to ZegoANSMode.Soft
ZegoExpressEngine.instance.setANSMode(ZegoANSMode.Soft);