In social and entertainment scenarios, users often want various voice effects to improve their interactive experiences. For example, in chat rooms, a user can select a voice effect to add a virtual stereo effect to their voice.
To accomplish this, Agora RTC SDK provides preset voice effects. You can also dynamically change the users' voices, such as adjusting the pitch, setting the equalization, and reverberation modes. Try out the preset voice effects on the online Demo provided by Agora.
<%
if (os == "android") { %>
Agora provides an open-source sample project (VoiceEffects.java) that implements the voice beautifier and audio effects functions on GitHub. You can download it to try out this function and view the source code.
<% }
if (os == "windows") { %>
Agora provides an open-source sample project (BeautyAudio) that implements the voice beautifier and audio effects functions on GitHub. You can download it to try out this function and view the source code.
<% }
if (os == "apple") { %>
Agora provides the following open-source sample projects that implement the voice beautifier and audio effects functions on GitHub. You can download them to try out this function and view the source code.
Before proceeding, ensure that you have implemented the basic real-time communication functions in your project.
To meet the requirements for voice effects in different scenarios, Agora provides setVoiceBeautifierPreset
and setAudioEffectPreset
. You can use the following SDK preset voice effects:
Category | Scenario | |
---|---|---|
Voice beautifier setVoiceBeautifierPreset |
Chat beautifier | Audio and video scenarios focusing on a user’s speaking voice: |
Singing beautifier | Audio and video scenarios focusing on a user’s singing voice: |
|
Timbre transformation | Audio and video scenarios focusing on a user’s speaking voice or singing voice: |
|
Audio effect setAudioEffectPreset |
Voice changer effect | Audio and video scenarios focusing on a user’s speaking voice: |
Style transformation | Audio and video scenarios focusing on a user’s singing voice: |
|
Room acoustics | Audio and video scenarios focusing on a user’s speaking voice or singing voice: |
|
Pitch correction | Audio and video scenarios focusing on a user’s singing voice: |
Ensure that you prepare the development environment. See Integrate the SDK.
You can use one of the following preset voice changer options by calling the setLocalVoiceChanger
method:
// Sets to an old man's voice.
mRtcEngine.setLocalVoiceChanger(VOICE_CHANGER_OLDMAN);
// Sets to the user's original voice.
mRtcEngine.setLocalVoiceChanger(VOICE_CHANGER_OFF);
You can use one of the following preset reverberation effects by calling the setLocalVoiceReverbPreset
method:
// Sets the preset reverberation effect to pop music.
mRtcEngine.setLocalVoiceReverbPreset(AUDIO_REVERB_POPULAR);
// Turns off reverberation.
mRtcEngine.setLocalVoiceReverbPreset(AUDIO_REVERB_OFF);
You can also customize the voice effects by adjusting the voice pitch, equalization, and reverberation settings.
The following sample code shows how to change from the original voice to Hulk's voice.
// Sets the pitch. The value ranges between 0.5 and 2.0. The lower the value, the lower the pitch. The default value is 1.0, which is the original pitch.
double pitch = 0.5;
rtcEngine.setLocalVoicePitch(pitch);
// Sets the local voice equalization.
// The first parameter sets the band frequency. The value ranges between 0 and 9. Each value represents the center frequency of the band: 31, 62, 125, 250, 500, 1k, 2k, 4k, 8k, and 16k Hz
// The second parameter sets the gain of each band. The value ranges between -15 and 15 dB. The default value is 0.
rtcEngine.setLocalVoiceEqualization(0, -15);
rtcEngine.setLocalVoiceEqualization(1, 3);
rtcEngine.setLocalVoiceEqualization(2, -9);
rtcEngine.setLocalVoiceEqualization(3, -8);
rtcEngine.setLocalVoiceEqualization(4, -6);
rtcEngine.setLocalVoiceEqualization(5, -4);
rtcEngine.setLocalVoiceEqualization(6, -3);
rtcEngine.setLocalVoiceEqualization(7, -2);
rtcEngine.setLocalVoiceEqualization(8, -1);
rtcEngine.setLocalVoiceEqualization(9, 1);
// The level of the dry signal in dB. The value ranges between -20 and 10.
rtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_DRY_LEVEL, 10);
// The level of the early reflection signal (wet signal) in dB. The value ranges between -20 and 10.
rtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_WET_LEVEL, 7);
// The room size of the reverberation. A larger room size means a stronger reverberation. The value ranges between 0 and 100.
rtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_ROOM_SIZE, 6);
// The length of the initial delay of the wet signal (ms). The value ranges between 0 and 200.
rtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_WET_DELAY, 124);
// The reverberation strength. The value ranges between 0 and 100. The higher the value, the stronger the reverberation.
rtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_STRENGTH, 78);
setLocalVoiceChanger
setLocalVoiceReverbPreset
setLocalVoicePitch
setLocalVoiceEqualization
setLocalVoiceReverb
Agora provides an open source sample code that implements voice changer and reverberation. You can go to the Chatroom GitHub Repo to download it.
The API methods have return values. If the method call fails, the return value is < 0.