To promote audio quality and user experience, ZEGOCLOUD provides the ability to process audio with 3A technologies, including AEC, AGC, and ANS.
ZEGOCLOUD also supports headphone monitoring and stereo features, which can be configured as needed.
Before you begin, make sure you complete the following steps:
To enable the AEC feature (enableAEC
), to enable the AEC when using headphones (enableHeadphoneAEC
), or to set up the AEC mode (setAECMode
), you will need to call those methods before calling the following methods:
startPublishingStream
, startPlayingStream
, startPreview
, createMediaPlayer
, and createAudioEffectPlayer
.
To implement the AEC feature, do the following:
To enable the AEC feature, call the enableAEC
method.
Optional: To enable the AEC feature for the headphones scenario, call the enableHeadphoneAEC
method.
To set the AEC mode, call the setAECMode
mode.
The following sample code is used for setting the AEC to the medium mode (ZegoAECModeMedium
):
// Enable the AEC feature.
[[ZegoExpressEngine sharedEngine] enableAEC:YES];
// Enable the AEC when using headphones.
[[ZegoExpressEngine sharedEngine] enableHeadphoneAEC:YES];
// Set the AEC to medium mode (ZegoAECModeMedium).
[[ZegoExpressEngine sharedEngine] setAECMode:ZegoAECModeMedium];
To enable the AGC feature , you will need to
call the enableAGC
method before calling the following methods:
startPublishingStream
, startPlayingStream
, startPreview
, createMediaPlayer
, and createAudioEffectPlayer
.
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.
[[ZegoExpressEngine sharedEngine] enableAGC:YES];
To implement the ANS feature, do the following:
To enable the ANS feature, call the enableANS
method.
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.
To set or adjust the ANS mode, call the setANSMode
method. The SDK uses medium mode (ZegoANSModeMedium
) by default.
The following sample code is used for setting the ANS to the medium mode (ZegoANSModeMedium
):
// Enable the ANS feature.
[[ZegoExpressEngine sharedEngine] enableANS:YES];
// Enable the transient ANS feature to control the transient noise.
[[ZegoExpressEngine sharedEngine] enableTransientANS:YES];
// Set the ANS to medium mode (ZegoANSModeMedium).
[[ZegoExpressEngine sharedEngine] setANSMode:ZegoANSModeMedium];
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. | Yes, but disabled on talkingmode. | We recommend you use the default settings for general scenarios. |
enableHeadphoneAEC |
Enable the AEC for the headphone scenario. | Yes | We recommend you enable this for chatting or playing games in groups. |
setAECMode |
Set the AEC mode. | ZegoAECModeAggressive (Aggressive mode) | We recommend you use the default settings for general scenarios. |
enableAGC |
Enable/Disable the AGC feature. | Yes |
|
enableANS |
Enable/Disable the ANS feature. | Yes | We recommend you use the default settings for general scenarios. |
setANSMode |
Set the ANS mode. | ZegoANSModeMedium (Medium mode)) | We recommend you use the default settings for general scenarios. |
After starting the local video preview or after starting publishing a stream, call the enableHeadphoneMonitor
method to enable headphone monitoring, and then you will start to hear yourself through the headphones.
For headphone monitoring to work correctly, you must connect the monitoring headphones to the device you are using.
[[ZegoExpressEngine sharedEngine] enableHeadphoneMonitor:YES];
Call the setHeadphoneMonitorVolume
method to adjust the volume for headphone monitoring as needed.
The volume
parameter is the volume of the captured audio for headphone monitoring, whose value is in the range 0-200 with a default of 100.
[[ZegoExpressEngine sharedEngine] setHeadphoneMonitorVolume:100];
To make the setAudioConfig
and setAudioCaptureStereoMode
methods take effect correctly, you must call them before calling the startPublishingStream
, startPlayingStream
, startPreview
, createMediaPlayer
, and createAudioEffectPlayer
methods.
To set the stereo coding before stream publishing, call the audio quality setAudioConfig
method, and set channel
property to stereo coding.
ZegoAudioConfig *audioConfig = [ZegoAudioConfig configWithPreset:ZegoAudioConfigPresetHighQualityStereo];
[[ZegoExpressEngine sharedEngine] setAudioConfig:audioConfig];
To always enable the stereo mode for audio capturing or enable the stereo mode only for stream publishing, call the setAudioCaptureStereoMode
and set the Mode
property based on the actual situation (stereo mode is disabled by default).
[[ZegoExpressEngine sharedEngine] setAudioCaptureStereoMode:ZegoAudioCaptureStereoModeAlways];
Capture stereo audio requires the stream publishing side to use a device that supports stereo capturing as the audio input source, for example, the microphone of a mobile phone does not support capture stereo audio.