Headphone Monitor and Channel Setting
Function 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 local headphone side.
- Dual channel refers to two sound 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 dual channel capture functionality. Through dedicated dual channel capture devices, they can capture dual channel audio data and publish stream.
This feature does not support running in WebGL environment.
Example Source Code Download
Please refer to Download Example Source Code to get the source code.
For related source code, please see the "Assets/ZegoExpressExample/Examples/AdvancedAudioProcessing/HeadphoneMonitor.cs" file.
Prerequisites
Before setting headphone monitor and channel, please ensure:
- You have created a project in ZEGOCLOUD Console and applied for 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 and video streaming functions. 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 to publish stream, call the EnableHeadphoneMonitor interface to enable headphone monitor (i.e., enable capture 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 starting preview or starting to publish stream, call the SetHeadphoneMonitorVolume interface to adjust the headphone monitor volume.
The parameter "volume" is the capture headphone monitor volume level, with a value range of [0, 200], defaulting to 60.
engine.SetHeadphoneMonitorVolume(100);Set Channel
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 value is mono channel encoding), and other parameters can take default values.
ZegoAudioConfig audioConfig = new ZegoAudioConfig(ZegoAudioConfigPreset.HighQualityStereo);
engine.SetAudioConfig(audioConfig);Set Audio Capture Dual Channel Mode
For audio capture dual channel mode, the publishing end needs 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, i.e., mono capture) to "Always enable dual channel capture" according to the actual scenario to enable audio dual channel capture.
engine.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 end does not need additional configuration and can directly play stream to play dual channel audio.
