- Documentation
- Video Call
- Upgrade using advanced features
- Advanced features
- Configure the video
- Beautify & Change the voice
Beautify & Change the voice
1 Introduction
- Voice change: By changing the user's pitch, the output sound is sensory different from the original sound, and various effects such as changing the male voice to the female voice are realized.
- Reverberation: Through special processing of the sound, the reverberation effect of different environments is created, making the sound appear as if it is in a concert hall, a cathedral, etc.
- Reverberation echo: Through special processing of the sound, it can be matched with voice change and reverberation to achieve a variety of custom sound effects, such as ethereal and robot sounds.
- Virtual stereo: Through the deep use of dual-channel technology, each position and angle of the sound source is virtualized to achieve stereo sound, 3D surround sound, and sound discrimination.
In the live broadcast, chat room, and karaoke room scenes, in order to increase the fun and interactivity, players can change the voice to make things funny, reverberate the atmosphere, and use stereo to make the sound more three-dimensional. ZegoExpress SDK provides a variety of preset voice change, reverberation, reverberation echo, and stereo effects. Developers can flexibly set the sound they want. If you need to listen to it, you can enable ear return for testing.
The function is only effective for the sound collected by the SDK. Developers can dynamically adjust the voice change, reverberation, reverberation echo, and virtual stereo during a call or live broadcast.
2 Download the Sample Codes
Please refer to Sample Codes for how to download and run the sample code.
For the source code of the audio preprocessing module, please view the source files in the "/ZegoExpressExample/SoundProcessing" directory. This module shows how to use voice change, reverb, and virtual stereo interfaces.
3 Prerequisites
Before you begin, make sure you complete the following:
Create a project in ZEGOCLOUD Admin Console and get the AppID and AppSign of your project.
Refer to the Quick Start doc to complete the SDK integration and basic function implementation.
4 Implementation Steps
4.1 Voice Change
4.1.1 Set Preset Voice Changer
Call the setVoiceChangerPreset method to use SDK preset voice changer effect.
ZegoVoiceChangerPreset preset voice changing effects are as follows, developers can choose according to their needs:
Type | Description | Voice Change Type |
---|---|---|
NONE | No Voice Changer | - |
MEN_TO_CHILD | Male voice becomes a child voice | Voice Change |
MEN_TO_WOMEN | Male voice to female voice | Voice Change |
WOMEN_TO_CHILD | Female voice becomes child's voice | Voice Change |
WOMEN_TO_MEN | Female voice to male voice | Voice Change |
FOREIGNER | Foreigner Sound Effects | Voice Change |
OPTIMUS_PRIME | Optimus Prime Sound Effects | Voice Change |
ANDROID | Robot sound effect | Voice Change |
ETHEREAL | Ethereal Sound Effects | Tone Change |
MALE_MAGNETIC | Magnetic Male | Room Bel Canto |
FEMALE_FRESH | Fresh Women | Room Bel Canto |
The following sample code takes a male voice to a child voice as an example:
ZegoExpressEngine.getEngine().setVoiceChangerPreset(ZegoVoiceChangerPreset.MEN_TO_CHILD);
4.1.2 Set Custom Voice Changer
If the sound changing effect preset by the SDK cannot meet the needs, the developer can call ZegoVoiceChangerParam Method, through the pitch parameter pitch
to set a custom voice changer, the value range of this parameter is [-8.0, 8.0], the larger the value, the sharper the sound, the default value is 0.0 (ie no voice change).
ZegoVoiceChangerParam voiceChangerParam = new ZegoVoiceChangerParam();
param.pitch = 2.0f;
ZegoExpressEngine.getEngine().setVoiceChangerParam(param);
4.2 Reverberation
4.2.1 Set Preset Reverb
Call setReverbPreset to set reverberation through preset enumeration.
ZegoReverbPreset preset reverb effects are as follows, developers can choose according to their needs:
Type | 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 | Space Shaping |
VOCAL_CONCERT | Concert | Space Shaping |
POPULAR | Pop | Music style |
ROCK | Rock | Genre |
The following sample code takes the large room mode as an example:
ZegoExpressEngine.getEngine().setReverbPreset(ZegoReverbPreset.LARGE_ROOM);
4.2.2 Set Custom Reverb
If the SDK preset reverb type cannot meet the needs, developers can call ZegoReverbAdvancedParam method, to achieve the reverberation effect required by the developer through the configuration of related parameters (for detailed parameter description, please refer to the API documentation).
ZegoReverbAdvancedParam reverbParam = new ZegoReverbAdvancedParam();
reverbParam.damping = 50.0; // Reverberation damping
reverbParam.reverberance = 50.0; // Reverberation
reverbParam.roomSize = 50.0; // room size
reverbParam.wetOnly = false;
reverbParam.wetGain = 5.0;
reverbParam.dryGain = 5.0;
reverbParam.toneLow = 80.0;
reverbParam.toneHigh = 80.0;
reverbParam.preDelay = 20.0;
reverbParam.stereoWidth = 0.0;
ZegoExpressEngine.getEngine().setReverbAdvancedParam(reverbParam);
After setting the custom reverb parameters, the preset reverb effect set when reverb is enabled will be invalid. If you want to use the SDK preset parameters again, you can use setReverbPreset . Set enumeration method to set.
4.3 Reverberation Echo
Call the setReverbEchoParam method and set the relevant parameters to realize the developer The required reverberation echo effect (for detailed parameter description, please refer to the API document).
The following sample code takes the ethereal effect as an example:
ZegoReverbEchoParam echoParam = new ZegoReverbEchoParam();
echoParam.inGain = 0.8f;
echoParam.outGain =1.0f;
echoParam.numDelays = 7;
int[] delay ={230,460,690,920,1150,1380,1610};
echoParam.delay=delay;
float[] decay={0.41f,0.18f,0.08f,0.03f,0.009f,0.003f,0.001f};
echoParam.decay=decay;
zegoReverbEchoParamDatas.add(echoParam);
ZegoExpressEngine.getEngine().setReverbEchoParam(echoParam);
4.4 Virtual Stereo
4.4.1 Set the Number of Streaming Audio Channels
If you need to turn on the virtual stereo function, you must first call the setAudioConfig method to set before pushing the stream The audio encoding channel is Stereo dual channel (default is Mono).
The example here uses the preset enumeration structure ZegoAudioConfig to be set to dual-channel.
ZegoAudioConfig audioConfig = new ZegoAudioConfig(STANDARD_QUALITY_STEREO);
ZegoExpressEngine.getEngine().setAudioConfig(audioConfig);
4.4.2 Set Virtual Stereo Parameters
After setting the audio encoding channel to dual channel, call the enableVirtualStereo method, Turn on the virtual stereo through the enable parameter, and set the sound source angle of the virtual stereo through the angle parameter to have the stereo effect. The angle range is 0 to 180, and generally can be set to 90 degrees (that is, straight ahead).
The example here is to turn on virtual stereo and set the angle to 90 degrees:
ZegoExpressEngine.getEngine().enableVirtualStereo(true, 90);
5 API Reference
Method | Description |
---|---|
setVoiceChangerPreset | Set by preset enumeration change voice. |
ZegoVoiceChangerParam | Voice changer parameters. |
setReverbPreset | Set reverb via preset enumeration. |
setReverbParam | Audio reverberation parameters. |
setReverbEchoParam | Set the reverb echo effect. |
ZegoReverbParam | Set custom reverb. |
setAudioConfig | Set audio configuration. |
enableVirtualStereo | Set virtual stereo. |