Headphone Monitor and Audio Channel Settings
Feature Overview
ZEGO Express SDK provides headphone monitor and dual channel features, which developers can set as needed.
- Headphone 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 headphone side of the device.
- Dual channel refers to two audio channels. When hearing sound, you can determine 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 capture. When developers have high audio quality requirements, they can enable the dual channel capture function. Dedicated dual channel capture devices can be used to capture dual channel audio data and publish streams.
Example Source Code Download
Please refer to Download Example Source Code to get the source code.
For related source code, please check the files in the "/ZegoExpressExample/AdvancedAudioProcessing/src/main/java/im/zego/advancedaudioprocessing/earreturnandchannelsettings" directory.
Prerequisites
Before setting headphone monitor and audio 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 the ZEGO Express SDK in your project and implemented basic audio and video streaming functionality. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
Usage Steps
Set headphone monitor
Enable headphone monitor
After starting preview or starting publishing stream, call the enableHeadphoneMonitor interface to enable headphone monitor (i.e., enable capture monitoring). After connecting headphones, when users make sounds, they can hear their own voices.
After enabling the headphone monitor function, it will only take effect after headphones are connected.
engine.enableHeadphoneMonitor(true);Set headphone monitor volume
After starting preview or starting publishing stream, call the setHeadphoneMonitorVolume interface to adjust the volume of the headphone monitor.
The parameter "volume" is the capture headphone monitor volume, with a value range of [0, 200], and the default is 60.
engine.setHeadphoneMonitorVolume(60);Set audio 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 (the default is mono channel encoding), and other parameters can use the default values.
ZegoAudioConfig audioConfig = new ZegoAudioConfig(ZegoAudioConfigPreset.HIGH_QUALITY_STEREO);
ZegoExpressEngine.getEngine().setAudioConfig(audioConfig);Set audio capture dual channel mode
Audio capture dual channel mode requires the publishing stream side 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 (the default is not to enable dual channel, i.e., mono channel capture) to "Always enable dual channel capture" according to the actual scenario to enable audio dual channel capture.
ZegoExpressEngine.getEngine().setAudioCaptureStereoMode(ZegoAudioCaptureStereoMode.ALWAYS);Publish stream
Please refer to "Publish Stream" in Quick Start - Implementation. At this time, the published audio is dual channel. The playing stream side does not need additional configuration and can directly play the stream to play dual channel audio.
