Documentation
ExpressVideoSDK Video Call
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • Video Call
  • Develop your app
  • Enhance basic feature
  • Set up common audio config

Set up common audio config

Last updated:2023-10-30 10:51

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.

ZEGOCLOUD also supports headphone monitoring and stereo features, which can be configured as needed.

  • Headphone monitoring is the process of feeding the audio captured by the current device's microphone to the headphones (or wireless Bluetooth earbuds) connecting to the same device in real time.
  • Stereo refers to the use of two independent audio channels to create the impression of sound heard from various directions, as in natural hearing. The ZEGO Express SDK uses the mono channel for sound capturing by default, you can enable the stereo for audio capturing and stream publishing when higher sound quality is needed.

Prerequisites

Before you begin, make sure you complete the following steps:

  • A project has been created in ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - How to view project information .
  • ZEGO Express SDK has been integrated into the project to implement basic real-time audio and video functions. For details, please refer to Integrate the SDK and Implement a basic video call.

Set up audio 3A processing

Set up the AEC (Acoustic Echo Cancellation)

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:

  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 (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];

Set up the AGC (Automatic Gain Control)

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];

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 (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];

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. 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
  • 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. 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.

Set up headphone monitoring

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];

Set up stereo

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.

Page Directory
  • Free trial
  • 提交工单
    咨询集成、功能及报价等问题
    电话咨询
    400 1006 604
    Get Consulting
    Scan Wechat QR code