Audio 3A Processing
Feature Introduction
During real-time audio and video calls or live streaming, 3A processing can be performed on 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 (Echo Cancellation): Filter the collected audio data to reduce echo in the audio.
- AGC (Automatic Gain Control): After enabling this feature, the SDK can automatically adjust the microphone volume to adapt to near and far sound pickup and maintain stable volume.
- ANS (Noise Suppression): Identify background noise in the sound and eliminate it. After enabling this feature, the human voice can be clearer. At the same time, you can enable music scene detection to identify communication and music scenes in real time without consumption, and further improve the fidelity of human voice and music sound quality in music scenes. If users need a more aggressive noise suppression strategy, they can use the Scenario-based AI Noise Suppression feature.
If you need to use music scene detection capabilities, please contact ZEGO technical support for special packaging and configuration.
Sample Source Code Download
Please refer to Download Sample Source Code to get the source code.
For related source code, please check the files in the "/ZegoExpressExample/Examples/AdvancedAudioProcessing/AECANSAGC" directory.
Default Configuration and Recommended Configuration
The default configuration and recommended configuration for audio 3A processing in the SDK are as follows:
| Interface Name | Interface Description | Default Configuration | Recommended Configuration |
|---|---|---|---|
| enableAEC | Turn on/off echo cancellation. | Before calling this function, the SDK internally automatically determines whether AEC needs to be used. Once this function is called, the SDK no longer automatically determines. | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| enableHeadphoneAEC | Whether to enable echo cancellation when using headphones. | 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 it. |
| setAECMode | Set echo cancellation mode. | ZegoAECModeAggressive (Aggressive echo cancellation). | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| enableAGC | Turn on/off automatic gain control. | Before calling this function, the SDK internally automatically determines whether AGC needs to be used. Once this function is called, the SDK no longer automatically determines. |
|
| enableANS | Turn on/off noise suppression. | Before calling this function, the SDK internally automatically determines whether ANS needs to be used. Once this function is called, the SDK no longer automatically determines. | In general usage scenarios, it is recommended not to modify this configuration and keep the default. |
| enableTransientANS | Turn on/off transient noise suppression. | When this function is not called, 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. | ZegoANSModeMedium (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, please ensure:
- You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - Project Information.
- You have integrated ZEGO Express SDK in the project and implemented basic audio and video publishing and playing functions. For details, please refer to Quick Start - Integration and Quick Start - Implementation Flow.
Usage Steps
Set AEC (Echo Cancellation)
enableAEC, enableHeadphoneAEC, and setAECMode all need to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager interfaces to take effect.
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 the collected audio data to reduce echo in the audio.
-
(Optional) Developers can set whether to enable echo cancellation when using headphones by calling the enableHeadphoneAEC interface.
-
After enabling echo cancellation, developers can set the echo cancellation mode by calling the setAECMode interface. The SDK supports the following three echo cancellation modes:
Enumeration Description ZegoAECModeAggressive Aggressive echo cancellation, may significantly affect sound quality, but echo will be eliminated very cleanly. ZegoAECModeMedium Moderate echo cancellation, may slightly affect sound quality a little bit, but residual echo will be less. ZegoAECModeSoft Comfortable echo cancellation, echo cancellation basically will not affect the sound quality of the sound, may sometimes leave a little residual echo, but will not affect normal listening.
Express SDK supports AI echo cancellation, which further improves the fidelity of human voice on the basis of effectively eliminating echo. If you need to use AI echo cancellation feature, please contact ZEGO technical support for special packaging first.
Taking setting moderate echo cancellation as an example:
// Enable AEC
[[ZegoExpressEngine sharedEngine] enableAEC:YES];
// Enable AEC when using headphones
[[ZegoExpressEngine sharedEngine] enableHeadphoneAEC:YES];
// Set AEC mode to ZegoAECModeMedium
[[ZegoExpressEngine sharedEngine] setAECMode:ZegoAECModeMedium];Set AGC (Automatic Gain Control)
enableAGC needs to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager interfaces to take effect.
Call the enableAGC interface to enable automatic gain control. After enabling this feature, the SDK can automatically adjust the microphone volume to adapt to near and far sound pickup and maintain stable volume.
// Enable AGC
[[ZegoExpressEngine sharedEngine] enableAGC:YES];Set ANS (Noise Suppression)
enableANS, enableTransientANS, and setANSMode all need to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager interfaces to take effect.
Developers can complete noise suppression related settings according to the following steps:
-
Call the enableANS interface to enable noise suppression. After enabling this feature, the human voice can be clearer.
-
(Optional) Developers can set whether to enable transient noise suppression by calling the enableTransientANS interface. Transient noise suppression is used to suppress transient noises such as typing on keyboards and tapping tables.
-
After enabling noise suppression, developers can set the noise suppression mode by calling the setANSMode interface. The default value is "ZegoANSModeMedium".
The SDK supports the following noise suppression modes:
Enumeration Description ZegoANSModeAggressive Aggressive noise suppression, may significantly damage sound quality, but has very good noise suppression effect. ZegoANSModeMedium Moderate noise suppression, may damage some sound quality, but has good noise suppression effect. ZegoANSModeSoft Light noise suppression, basically will not damage sound quality, but will leave some noise. WarningExpress SDK supports AI mode noise suppression, and provides three modes: lightweight mode, balanced mode, and low-latency mode. It effectively eliminates transient noises such as keyboards, coughing, wind, car horns, etc. on the basis of eliminating steady-state noise. For details, please refer to Scenario-based AI Noise Suppression.
-
(Optional) Enable music detection. Please contact ZEGO technical support to configure and enable the music detection feature.
Taking setting moderate noise suppression as an example:
// Enable ANS
[[ZegoExpressEngine sharedEngine] enableANS:YES];
// Enable transient noise suppression
[[ZegoExpressEngine sharedEngine] enableTransientANS:YES];
// Set ANS mode to ZegoANSModeMedium
[[ZegoExpressEngine sharedEngine] setANSMode:ZegoANSModeMedium];