Voice Changer/Reverb/Stereo
Function Overview
This document does not apply to the Web platform.
In live streaming, voice chat rooms, and karaoke rooms scenarios, to increase fun and interactivity, players can use voice changing to be funny, use reverb to enhance the atmosphere, and use stereo to make sound more three-dimensional. ZegoExpress SDK provides various preset voice changer, reverb, reverb echo, and stereo effects. Developers can flexibly set the desired sound. If you need to preview, you can enable in-ear monitoring for testing.
- Voice Changer: By changing the user's pitch, the output sound is perceptually different from the original sound, achieving effects such as male voice changing to female voice.
- Reverb: Through special processing of sound, create reverb effects of different environments, making the sound appear as if it were in a concert hall, cathedral, etc.
- Reverb Echo: Through special processing of sound, it can be combined with voice changer and reverb to achieve various customized sound effects, such as ethereal, robotic sounds.
- Virtual Stereo: By deeply using dual-channel technology, virtualize various positions and angles of sound sources, achieving stereo, 3D surround sound, sound positioning, and other effects.
You can experience the SDK's preset voice effects through the Sound Effects Experience DEMO provided by ZEGO.
This function only applies to sound captured by the SDK. Developers can dynamically adjust voice changer, reverb, reverb echo, and virtual stereo during calls or live streaming.
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 "lib\topics\AudioAdvanced\voice_change" directory.
Prerequisites
Before proceeding with Voice Changer/Reverb/Stereo, please ensure:
- ZEGO Express SDK has been integrated in the project and basic real-time audio and video functions have been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
- A project has been created in the ZEGOCLOUD Console and valid AppID and AppSign have been applied. For details, please refer to Console - Project Information.
Usage Steps
Voice Changer
There are two ways to set voice changer: preset voice changer and custom voice changer.
Set Preset Voice Changer
If you need to set custom voice changer, please refer to Set Custom Voice Changer.
Call the setVoiceChangerPreset method to use the SDK's preset voice changer effects.
The preset voice changer effects of ZegoVoiceChangerPreset are as follows. Developers can choose according to their needs:
| Type Name | Description | Voice Changer Type |
|---|---|---|
| None | No voice changer | - |
| MenToChild | Male to child voice (loli sound effect) | Voice changer |
| MenToWomen | Male to female voice (kindergarten sound effect) | Voice changer |
| WomenToChild | Female to child voice | Voice changer |
| WomenToMen | Female to male voice | Voice changer |
| Foreigner | Foreigner sound effect | Voice changer |
| OptimusPrime | Optimus Prime sound effect | Voice changer |
| Android | Robot sound effect | Voice changer |
| Ethereal | Ethereal sound effect | Timbre transformation |
| MaleMagnetic | Magnetic male | Room beautification |
| FemaleFresh | Fresh female | Room beautification |
| MajorC | C major electronic music | Electronic sound effect |
| MinorA | A minor electronic music | Electronic sound effect |
| HarmonicMinor | Harmonic minor electronic music | Electronic sound effect |
| FemaleEnergetic | Energetic female sound effect | Room beautification |
| RichNess | Rich sound effect | Room beautification |
| Muffled | Muffled sound effect | Timbre transformation |
| Roundness | Mellow sound effect | Room beautification |
| Falsetto | Falsetto sound effect | Room beautification |
| Fullness | Full sound effect | Room beautification |
| Clear | Clear sound effect | Room beautification |
| HighlyResonant | High-pitched sound effect | Room beautification |
| LoudClear | Loud and clear sound effect | Room beautification |
| Minions | Minion sound effect | Voice changer |
| Autobot | Autobot sound effect | Voice changer |
| OutOfPower | Out of power sound effect | Voice changer |
To use the Autobot and OutOfPower voice changer effects, please contact technical support for custom SDK packaging.
The following example code uses "Male to Child Voice" as an example:
ZegoExpressEngine.instance.setVoiceChangerPreset(ZegoVoiceChangerPreset.MenToChild);Set Custom Voice Changer
If you need to set preset voice changer, please refer to Set Preset Voice Changer.
If the SDK's preset voice changer effects cannot meet your needs, developers can call the ZegoVoiceChangerParam method and set custom voice changer through the pitch parameter "pitch". The value range of this parameter is [-12.0, 12.0]. The larger the value, the sharper the sound. The default value is "0.0" (i.e., no voice changer).
For versions 2.18.0 and earlier, the value range is [-8.0, 8.0].
var voiceChangerParam = ZegoVoiceChangerParam(2.0);
ZegoExpressEngine.instance.setVoiceChangerParam(ZegoMediaPlayerAudioChannel.All, param);Reverb
There are two ways to set reverb: preset reverb and custom reverb.
Set Preset Reverb
If you need to set custom reverb, please refer to Set Custom Reverb.
Call setReverbPreset to set reverb through preset enumeration.
The preset reverb effects of ZegoReverbPreset are as follows. Developers can choose according to their needs:
| Type Name | Description | Reverb Type |
|---|---|---|
| NONE | None | - |
| SOFT_ROOM | Small room | Space shaping |
| LARGE_ROOM | Large room | Space shaping |
| CONCERT_HALL | Concert hall | Space shaping |
| VALLEY | Valley | Space shaping |
| RECORDING_STUDIO | Recording studio | Space shaping |
| BASEMENT | Basement | Space shaping |
| KTV | KTV, suitable for users with more obvious vocal flaws | Space shaping |
| POPULAR | Popular | Music style |
| ROCK | Rock | Music style |
| VOCAL_CONCERT | Vocal concert | Space shaping |
| GRAMO_PHONE | Gramophone | Space shaping |
| ENHANCED_KTV | Enhanced KTV, more focused and brighter KTV vocal effect, suitable for ordinary users and professional users | Space shaping |
The following example code uses "Large Room" mode as an example:
ZegoExpressEngine.instance.setReverbPreset(ZegoReverbPreset.LargeRoom);Set Custom Reverb
If you need to set preset reverb, please refer to Set Preset Reverb.
If the SDK's preset reverb types cannot meet your needs, developers can call the ZegoReverbAdvancedParam method and set relevant parameters in combination to achieve the reverb effect developers need (for detailed parameter description, please refer to the API documentation).
var reverbParam = ZegoReverbAdvancedParam(
50.0, // roomSize Room size (percentage)
50.0, // reverberance Reverberation (percentage)
50.0, // damping Reverb damping (percentage)
false, // wetOnly Wet signal only
5.0, // wetGain Wet signal gain(dB)
5.0, // dryGain Dry signal gain(dB)
80.0, // toneLow Low frequency attenuation
80.0, // toneHigh High frequency attenuation
20.0, // preDelay Initial delay time(ms)
0.0 // stereoWidth Stereo width (percentage)
);
ZegoExpressEngine.instance.setReverbAdvancedParam(reverbParam);When custom reverb parameters are set, the preset reverb effect set when enabling reverb will become invalid. If you want to use the SDK preset parameters again, you can use the setReverbPreset preset enumeration method to set.
Reverb Echo
Call the setReverbEchoParam method and set relevant parameters in combination to achieve the reverb echo effect developers need (for detailed parameter description, please refer to the API documentation).
The following example code takes implementing "ethereal sound effect" as an example:
var echoParam = ZegoReverbEchoParam(
0.8, // inGain Input audio signal gain
1.0, // outGain Output audio signal gain
7, // numDelays Number of echoes
[230,460,690,920,1150,1380,1610], // delay Delay of echo signals respectively, in milliseconds
[0.41f,0.18f,0.08f,0.03f,0.009f,0.003f,0.001f] // decay Decay coefficient of echo signals respectively
);
ZegoExpressEngine.instance.setReverbEchoParam(echoParam);Virtual Stereo
Set Publishing Audio Channel Count
If you need to enable the virtual stereo function, you must call the setAudioConfig method before publishing to set the audio encoding channel to Stereo dual channel (the default is Mono single channel).
This example constructs ZegoAudioConfig through preset enumeration and sets it to dual channel.
var audioConfig = ZegoAudioConfig.preset(ZegoAudioConfigPreset.StandardQualityStereo);
ZegoExpressEngine.instance.setAudioConfig(audioConfig);Set Virtual Stereo Parameters
After setting the audio encoding channel to dual channel, call the enableVirtualStereo method and set the virtual stereo source angle through the enable parameter to have a stereo effect. The angle range is 0 ~ 360. Generally, it can be set to 90 degrees (i.e., directly in front).
Since version 2.15.0, the SDK has added support for all-around virtual stereo effect. The usage is to set the angle parameter to "-1".
This example enables virtual stereo and sets the angle to 90 degrees:
ZegoExpressEngine.instance.enableVirtualStereo(true, 90);This example enables all-around virtual stereo:
ZegoExpressEngine.instance.enableVirtualStereo(true, -1);