Ear Monitor and Channel Settings
Introduction
ZEGO Express SDK provides ear monitor and dual channel functions. Developers can set them as needed.
- Ear monitor refers to headphone capture monitoring. After inserting headphones (ordinary headphones or Bluetooth headphones) into the device, you can hear the sound captured by the device's microphone from the local headphone side.
- Dual channel refers to two audio channels. When hearing sound, you can judge the specific position of the sound source based on the phase difference of the sound between the left and right ears. ZEGO Express SDK defaults to single-channel audio capture. When developers have high sound quality requirements, they can enable dual-channel capture functionality. Through dedicated dual-channel capture devices, dual-channel audio data can be captured and published.
Download Sample Source Code
Please refer to Download Sample Source Code to obtain the source code.
For related source code, please check the files in the "/ZegoExpressExample/Examples/AdvancedAudioProcessing/EarReturnAndChannelSettings" directory.
Prerequisites
Before setting ear monitor and channel, ensure that:
- A project has been created in the ZEGOCLOUD Console, and valid AppID and AppSign have been obtained. For details, please refer to Console - Project Information.
- ZEGO Express SDK has been integrated into the project, and basic audio and video streaming functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.
Usage Steps
Set Ear Monitor
Enable Ear Monitor
After starting preview or starting publishing stream, call the enableHeadphoneMonitor interface to enable ear monitor (that is, enable capture monitoring). After connecting headphones, when the user makes a sound, they can hear their own voice.
After enabling the ear monitor function, it will only take effect after headphones are connected.
engine->enableHeadphoneMonitor(true);Set Ear Monitor Volume
After starting preview or starting publishing stream, call the setHeadphoneMonitorVolume interface to adjust the ear monitor volume.
The parameter "volume" is the capture ear monitor volume, with a value range of [0, 200] and a default of 60.
engine->setHeadphoneMonitorVolume(60);Set Channel
setAudioConfig and setAudioCaptureStereoMode must be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, and createAudioEffectPlayer to take effect.
Set Audio Dual Channel Encoding
Before publishing stream, call the setAudioConfig method to set audio quality related configurations. The audio encoding channel parameter "channel" needs to be set to dual channel encoding (the default is single channel encoding), and other parameters can use default values.
ZegoAudioConfig audioConfig = ZegoAudioConfig(ZEGO_AUDIO_CONFIG_PRESET_HIGH_QUALITY_STEREO);
ZegoExpressSDK::getEngine()->setAudioConfig(audioConfig);Set Audio Capture Dual Channel Mode
Audio capture dual channel mode requires the publishing stream end to use a device that supports dual channel capture as the audio input source. Generally, mobile phone microphones do not support dual channel capture.
Call the setAudioCaptureStereoMode method and set the "Mode" parameter (default is not enabling dual channel, that is, single channel capture) to "Always enable dual channel capture" according to the actual scenario to enable audio dual channel capture.
ZegoExpressSDK::getEngine()->setAudioCaptureStereoMode(ZEGO_AUDIO_CAPTURE_STEREO_MODE_ALWAYS);Publish Stream
Please refer to "Publish Stream" in Quick Start - Implementation Process. At this time, the published stream audio is dual channel. The playing stream end does not need additional configuration and can directly play stream to play dual channel audio.
