During real-time audio and video calls or live streaming, audio can be processed using the 3A approach, which mainly includes Acoustic Echo Cancelling (AEC), Automatic Gain Control (AGC), and Active Noise Control (ANS), in order to improve the quality of the calls or live streams and enhance the user experience.
To use the music scene detection capability, please contact ZEGOCLOUD technical support for special packaging and configuration.
Please refer to Sample codes to get the source code.
The relevant source code can be found in the “/ZegoExpressExample/AdvancedAudioProcessing/src/main/java/im/zego/advancedaudioprocessing/audio3a” directory.
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 | Enable/disable acoustic echo cancellation. | Before calling this function, the SDK will automatically determine whether to use AEC. Once this function is called, the SDK will no longer automatically determine. | In general use cases, it is recommended not to modify this configuration and keep it as the default. |
enableHeadphoneAEC | Enable/disable acoustic echo cancellation when using headphones. | Disabled. | It is recommended to enable this feature for normal voice chat or game voice chat, and it is generally not necessary to enable it in other scenarios. |
setAECMode | Set the acoustic echo cancellation mode. | ZegoAECMode.AGGRESSIVE (aggressive echo cancellation). | In general use cases, it is recommended not to modify this configuration and keep it as the default. |
enableAGC | Enable/disable automatic gain control. | Before calling this function, the SDK will automatically determine whether to use AGC. Once this function is called, the SDK will no longer automatically determine. |
|
enableANS | Enable/disable noise suppression. | Before calling this function, the SDK will automatically determine whether to use ANS. Once this function is called, the SDK will no longer automatically determine. | In general use cases, it is recommended not to modify this configuration and keep it as the default. |
enableTransientANS | Enable/disable transient noise suppression. | By default, transient noise suppression is disabled when this function is not called. | In general use cases, it is recommended not to modify this configuration and keep it as the default. |
setANSMode | Set the audio noise suppression mode. | ZegoANSMode.Medium (moderate noise suppression). | In general use cases, it is recommended not to modify this configuration and keep it as the default. |
Before using audio 3A processing, please make sure:
enableAEC, enableHeadphoneAEC, and setAECMode need to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager interfaces in order to take effect.
Developers can follow the steps below to configure echo cancellation:
Call the enableAEC interface to enable echo cancellation. After enabling this feature, the SDK will filter the captured audio data to reduce echo.
(Optional) Developers can call the enableHeadphoneAEC interface 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:
Enumeration | Description |
---|---|
ZegoAECMode.AGGRESSIVE | Aggressive echo cancellation, which may have a noticeable impact on audio quality, but effectively eliminates echo. |
ZegoAECMode.MEDIUM | Moderate echo cancellation, which may slightly affect audio quality, but reduces residual echo. |
ZegoAECMode.SOFT | Comfortable echo cancellation, which has minimal impact on audio quality and may leave a small amount of echo, but does not affect normal listening. |
The Express SDK supports AI echo cancellation and provides a lightweight mode to further enhance the fidelity of human voice while effectively eliminating echo. If you need to use the AI echo cancellation feature, please contact ZEGOCLOUND technical support for special packaging.
For example, to set the echo cancellation mode to "Medium":
// Enable AEC
engine.enableAEC(true);
// Enable AEC when using headphones
engine.enableHeadphoneAEC(true);
// Set AEC mode to ZegoAECMode.MEDIUM
engine.setAECMode(ZegoAECMode.MEDIUM);
To configure AGC:
enableAGC needs to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager interfaces in order to take effect.
Call the enableAGC interface to enable Automatic Gain Control (AGC). After enabling this feature, the SDK will automatically adjust the microphone volume to adapt to different distances, ensuring a stable volume.
// Enable AGC
engine.enableAGC(true);
To configure ANS:
enableANS, enableTransientANS, and setANSMode need to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, createAudioEffectPlayer, and createRealTimeSequentialDataManager interfaces in order to take effect.
Developers can follow the steps below to configure noise suppression:
Call the enableANS interface to enable noise suppression. This feature can make the human voice clearer.
(Optional) Developers can call the enableTransientANS interface to enable transient noise suppression, which 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 three noise suppression modes:
Enumeration | Description |
---|---|
ZegoANSMode.AGGRESSIVE | Aggressive noise suppression, which may significantly affect audio quality but has good noise reduction effects. |
ZegoANSMode.MEDIUM | (Default) Moderate noise suppression, which may slightly affect audio quality but has good noise reduction effects. |
ZegoANSMode.SOFT | Mild noise suppression, which has minimal impact on audio quality but may leave some residual noise. |
Note: The Express SDK supports AI-based noise suppression and provides two modes: ZegoANSModeAI
and ZegoANSModeAI_BALANCED
. These modes effectively eliminate transient noises such as keyboard typing, coughing, wind noise, and car horns, in addition to eliminating steady-state noise. For more details, please refer to AI-based noise reduction in real-world scenarios.
(Optional) Enable music detection. Please contact ZEGOCLOUD technical support to configure and enable music detection. Taking setting mild noise suppression as an example:
// Enable ANS
engine.enableANS(true);
// Enable transient noise suppression
engine.enableTransientANS(true);
// Set ANS mode to ZegoANSMode.SOFT
engine.setANSMode(ZegoANSMode.SOFT);