logo
On this page

Headphone Monitor and Audio Channel Settings

2024-02-26

Overview

Caution

This document does not apply to the Web platform.

ZEGO Express SDK provides headphone monitor and dual channel features, which developers can set as needed.

  • Headphone monitor refers to monitoring through headphones. After inserting headphones (regular 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 audio quality requirements, they can enable the dual-channel capture feature. Through dedicated dual-channel capture devices, dual-channel audio data can be captured and published.

Demo Source Code Download

Please refer to Download Demo Source Code to obtain the source code.

For related source code, please check the files in the "lib/topics/AudioAdvanced/ear_return_and_channel_settings" directory.

Prerequisites

Before setting headphone monitor and audio channels, 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 feature, it will only take effect when headphones are connected.

ZegoExpressEngine.instance.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, ranging from [0, 200], with a default of 60.

ZegoExpressEngine.instance.setHeadphoneMonitorVolume(100);

Set audio channels

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 single-channel encoding), and other parameters can take default values.

var audioConfig = ZegoAudioConfig.preset(ZegoAudioConfigPreset.HighQualityStereo);
ZegoExpressEngine.instance.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., single-channel capture) to "Always enable dual-channel capture" according to the actual scenario to enable audio dual-channel capture.

ZegoExpressEngine.instance.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 dual-channel audio by playing stream.

Previous

Sound Level and Spectrum

Next

Audio 3A Processing

On this page

Back to top