Headphone Monitor and Channel Settings
Feature Introduction
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 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 mono channel 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 it.
Sample Source Code Download
Please refer to Download Sample Source Code to get the source code.
For related source code, please check the files in the "/ZegoExpressExample/Examples/AdvancedAudioProcessing/EarReturnAndChannelSettings" directory.
Prerequisites
Before setting headphone monitor and 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 the project and implemented basic audio and 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 starting preview or starting publishing 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 when headphones are connected.
[[ZegoExpressEngine sharedEngine] enableHeadphoneMonitor:YES];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], defaulting to 60.
[[ZegoExpressEngine sharedEngine] setHeadphoneMonitorVolume:60];Set channels
Both setAudioConfig and setAudioCaptureStereoMode need to be called before startPublishingStream, startPlayingStream, startPreview, createMediaPlayer, and createAudioEffectPlayer to take effect.
Set audio dual channel encoding
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 configWithPreset:ZegoAudioConfigPresetHighQualityStereo];
[[ZegoExpressEngine sharedEngine] setAudioConfig:audioConfig];Set audio capture dual channel mode
Audio capture dual channel mode requires the publishing end 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 according to the actual scenario (default is not enabling dual channel, i.e., mono channel capture) to "Always enable dual channel capture" to enable audio dual channel capture.
[[ZegoExpressEngine sharedEngine] setAudioCaptureStereoMode:ZegoAudioCaptureStereoModeAlways];Publish stream
Please refer to "Publish Stream" in Quick Start - Implementation Flow. At this time, the published audio is dual channel, and the playing end does not need additional configuration. Simply playing the stream can play dual channel audio.
FAQ
-
After the publishing end enables dual channel capture, the playing end (iOS) can normally play dual channels using wired headphones, but when using AirPods, it becomes mono channel?
Due to iOS system limitations, when using Bluetooth headphones, the following scenarios exist:
- If the playing end needs to both publish and play streams, for example, performing playback and recording operations simultaneously in a call scenario, only mono channel can be played.
- If it is determined that the playing end only needs to play streams and does not need to publish streams, you can contact ZEGOCLOUD Technical Support to get a solution.
