logo
On this page

Headphone Monitor and Channel Setting

2023-11-21

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

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:

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.

Note

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

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

Note

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.

Previous

Sound Level and Audio Spectrum

Next

Audio 3A Processing