Headphone Monitor and Sound Channel Settings
Feature Overview
ZEGO Express SDK provides headphone monitor and dual channel functions, which developers can set as needed.
- Headphone monitor refers to headphone collection monitoring. After inserting headphones (ordinary headphones or Bluetooth headphones) into the device, you can hear the sound collected by the device's microphone from the local headphone side.
- Dual channel refers to two sound 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 mono audio collection. When developers have high audio quality requirements, they can enable the dual channel collection function. Through dedicated dual channel collection devices, they can collect dual channel audio data and publish streams.
Prerequisites
Before setting headphone monitor and sound channels, 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/video publishing and playing functions. For details, please refer to Quick Start - Integration and Quick Start - Implementation Flow.
Usage Steps
Set Headphone Monitor
Enable Headphone Monitor
After enabling preview or starting publishing stream, call the enableHeadphoneMonitor interface to enable headphone monitor (i.e., enable collection monitoring). After connecting headphones, when the user makes a sound, they can hear their own voice.
After enabling the headphone monitor function, it will only take effect after headphones are connected.
engine->enableHeadphoneMonitor(true);Set Headphone Monitor Volume
After enabling preview or starting publishing stream, call the setHeadphoneMonitorVolume interface to adjust the headphone monitor volume.
The parameter "volume" is the collection headphone monitor volume, ranging from [0, 200], default is 60.
engine->setHeadphoneMonitorVolume(60);Set Sound Channels
Both setAudioConfig and setAudioCaptureStereoMode need to 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 (default is mono 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 Collection Dual Channel Mode
For audio collection dual channel mode, the publishing side needs to use a device that supports dual channel collection as the audio input source. Generally, mobile phone microphones do not support dual channel collection.
Call the setAudioCaptureStereoMode method, and set the "Mode" parameter (default is not enabling dual channel, i.e., mono channel collection) to "Always enable dual channel collection" according to the actual scenario to enable audio dual channel collection.
ZegoExpressSDK::getEngine()->setAudioCaptureStereoMode(ZEGO_AUDIO_CAPTURE_STEREO_MODE_ALWAYS);Publish Stream
Refer to "Publish Stream" in Quick Start - Implementation Flow. At this time, the published audio is dual channel. The playing side does not need additional configuration and can directly play streams to play dual channel audio.
