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.
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.
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 or singing voice: |
|
Audio effect setAudioEffectPreset |
Voice changer | 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 or singing voice: |
|
Pitch correction | Audio and video scenarios focusing on a user’s singing voice: |
|
Voice conversion setVoiceConversionPreset |
Voice conversion | Audio and video scenarios focusing on a user’s speaking or singing voice: |
Chat beautifier refers to beautifying the characteristics of male or female voices without altering the original voice beyond recognition.
You can implement the chat beautifier by the enumerations in setVoiceBeautifierPreset
as follows:
Enumeration | Description |
---|---|
CHAT_BEAUTIFIER_MAGNETIC |
(For male-sounding voice only) A more magnetic voice. Agora recommends using this enumerator to process a male-sounding voice; otherwise, you may experience vocal distortion. |
CHAT_BEAUTIFIER_FRESH |
(For female-sounding voice only) A fresher voice. Agora recommends using this enumerator to process a female-sounding voice; otherwise, you may experience vocal distortion. |
CHAT_BEAUTIFIER_VITALITY |
(For female-sounding voice only) A more vital voice. Agora recommends using this enumerator to process a female-sounding voice; otherwise, you may experience vocal distortion. |
VOICE_BEAUTIFIER_PRESET preset;
// Beautifies the local voice by making it sound more magnetic (for male only).
preset = CHAT_BEAUTIFIER_MAGNETIC;
rtcEngine.setVoiceBeautifierPreset(preset);
// Disables voice effects.
preset = VOICE_BEAUTIFIER_OFF;
rtcEngine.setVoiceBeautifierPreset(preset);
Singing beautifier refers to beautifying male or female singing voices without greatly altering their original characteristics, as well as adding a reverberation effect.
You can implement the singing beautifier by the enumeration SINGING_BEAUTIFIER
.
setVoiceBeautifierPreset(SINGING_BEAUTIFIER)
, you can beautify a male-sounding voice and add a reverberation effect that sounds like singing in a small room. Agora recommends not using setVoiceBeautifierPreset(SINGING_BEAUTIFIER)
to process a female-sounding voice; otherwise, you may experience vocal distortion.setVoiceBeautifierParameters(SINGING_BEAUTIFIER, param1, param2)
, you can beautify a male- or female-sounding voice and add one of several reverberation effects.VOICE_BEAUTIFIER_PRESET preset;
preset = SINGING_BEAUTIFIER;
// Beautifies the singing voice of the local user.
rtcEngine.setVoiceBeautifierPreset(preset);
// Beautifies a female-sounding voice and add a reverberation effect that sounds like singing in a hall.
rtcEngine.setVoiceBeautifierParameters(preset, 2, 3);
// Disables voice effects.
preset = VOICE_BEAUTIFIER_OFF;
rtcEngine.setVoiceBeautifierPreset(preset);
Timbre transformation changes the timbre of a voice in a specific way. Users can choose the most appropriate effect for their voice.
You can implement the timbre transformation by the enumerations in setVoiceBeautifierPreset
as follows:
Enumeration | Description |
---|---|
TIMBRE_TRANSFORMATION_VIGOROUS |
A more vigorous voice. |
TIMBRE_TRANSFORMATION_DEEP |
A deeper voice. |
TIMBRE_TRANSFORMATION_MELLOW |
A mellower voice. |
TIMBRE_TRANSFORMATION_FALSETTO |
A falsetto voice. |
TIMBRE_TRANSFORMATION_FULL |
A fuller voice. |
TIMBRE_TRANSFORMATION_CLEAR |
A clearer voice. |
TIMBRE_TRANSFORMATION_RESOUNDING |
A more resounding voice. |
TIMBRE_TRANSFORMATION_RINGING |
A more ringing voice. |
VOICE_BEAUTIFIER_PRESET preset;
// Beautifies the local voice by making it sound more vigorous.
preset = TIMBRE_TRANSFORMATION_VIGOROUS;
rtcEngine.setVoiceBeautifierPreset(preset);
// Disables voice effects.
preset = VOICE_BEAUTIFIER_OFF;
rtcEngine.setVoiceBeautifierPreset(preset);
Voice changer changes the original voice mainly for fun effects. This effect makes the original voice less natural, so that listeners can tell that the voice has been changed.
You can implement the voice changer effect by the enumerations in setAudioEffectPreset
as follows:
Enumeration | Description |
---|---|
VOICE_CHANGER_EFFECT_UNCLE |
The voice of an uncle. Agora recommends using this enumerator to process a male-sounding voice; otherwise, you may not hear the anticipated voice effect. |
VOICE_CHANGER_EFFECT_OLDMAN |
The voice of an old man. Agora recommends using this enumerator to process a male-sounding voice; otherwise, you may not hear the anticipated voice effect. |
VOICE_CHANGER_EFFECT_BOY |
The voice of a boy. Agora recommends using this enumerator to process a male-sounding voice; otherwise, you may not hear the anticipated voice effect. |
VOICE_CHANGER_EFFECT_SISTER |
The voice of a young woman. Agora recommends using this enumerator to process a female-sounding voice; otherwise, you may not hear the anticipated voice effect. |
VOICE_CHANGER_EFFECT_GIRL |
The voice of a girl. Agora recommends using this enumerator to process a female-sounding voice; otherwise, you may not hear the anticipated voice effect. |
VOICE_CHANGER_EFFECT_PIGKING |
The voice of Pig King, a character in Journey to the West who has a voice like a growling bear. |
VOICE_CHANGER_EFFECT_HULK |
The voice of Hulk. |
AUDIO_EFFECT_PRESET preset;
// Presets the local voice by making it sound like the Hulk.
preset = VOICE_CHANGER_EFFECT_HULK;
rtcEngine.setAudioEffectPreset(preset);
// Disables voice effects.
preset = AUDIO_EFFECT_OFF;
rtcEngine.setAudioEffectPreset(preset);
A style transformation makes singing more harmonious for specific styles of songs.
You can implement the style transformation by the enumerations in setAudioEffectPreset
as follows:
Enumeration | Description |
---|---|
STYLE_TRANSFORMATION_POPULAR |
An audio effect typical of popular music. |
STYLE_TRANSFORMATION_RNB |
An audio effect typical of R&B music. |
AUDIO_EFFECT_PRESET preset;
// Presets the local voice to the style of pop music.
preset = STYLE_TRANSFORMATION_POPULAR;
rtcEngine.setAudioEffectPreset(preset);
// Disables voice effects.
preset = AUDIO_EFFECT_OFF;
rtcEngine.setAudioEffectPreset(preset);
Room acoustics refers to the spatial dimension added to a user’s voice for making the voice seem to come from a specific type of enclosed place.
You can implement the space construction by the enumerations in setAudioEffectPreset
as follows:
Enumeration | Description |
---|---|
ROOM_ACOUSTICS_KTV |
An audio effect typical of a KTV venue. |
ROOM_ACOUSTICS_VOCAL_CONCERT |
An audio effect typical of a concert hall. |
ROOM_ACOUSTICS_STUDIO |
An audio effect typical of a recording studio. |
ROOM_ACOUSTICS_PHONOGRAPH |
An audio effect typical of a vintage phonograph. |
ROOM_ACOUSTICS_VIRTUAL_STEREO |
A virtual stereo effect that renders monophonic audio as stereo audio. Note setAudioProfile and set the profile parameter to AUDIO_PROFILE_MUSIC_STANDARD_STEREO(3) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5) before setting this enumerator; otherwise, the enumerator setting does not take effect.scenario parameter of setAudioProfile to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator. |
ROOM_ACOUSTICS_SPACIAL |
A more spatial audio effect. |
ROOM_ACOUSTICS_ETHEREAL |
A more ethereal audio effect. |
ROOM_ACOUSTICS_3D_VOICE |
A 3D voice effect that makes the voice appear to be moving around the user. The default cycle period of the 3D voice effect is 10 seconds. To change the cycle period, call setAudioEffectParameters after this method.Note setAudioProfile and set the profile parameter to AUDIO_PROFILE_MUSIC_STANDARD_STEREO(3) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5) before setting this enumerator; otherwise, the enumerator setting does not take effect.scenario parameter of setAudioProfile to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator. |
AUDIO_EFFECT_PRESET preset;
// Presets the local voice by making it appear to be moving around the user.
preset = ROOM_ACOUSTICS_3D_VOICE;
rtcEngine.setAudioEffectPreset(preset);
// Changes the cycle period to 30 seconds.
rtcEngine.setAudioEffectParameters(preset, 30, 0);
// Disables voice effects.
preset = AUDIO_EFFECT_OFF;
rtcEngine.setAudioEffectPreset(preset);
Pitch correction refers to the effect for correcting a singing voice to make it match the song based on the basic mode and the tonic pitch.
You can implement the pitch correction by the enumerations in setAudioEffectPreset
as follows:
Enumeration | Description |
---|---|
PITCH_CORRECTION |
A pitch correction effect that corrects the user's pitch based on the pitch of the natural C major scale. To change the basic mode and tonic pitch, call setAudioEffectParameters after this method. |
AUDIO_EFFECT_PRESET preset;
// Presets the local voice by making it match the song.
preset = PITCH_CORRECTION;
rtcEngine.setAudioEffectPreset(preset);
// Changes the basic mode to natural minor scale and the tonic pitch to D.
rtcEngine.setAudioEffectParameters(preset, 2, 6);
// Disables voice effects.
preset = AUDIO_EFFECT_OFF;
rtcEngine.setAudioEffectPreset(preset);
Voice conversion naturally changes the original voice mainly for anonymous effects. Listeners cannot tell that the voice has been changed without listening to the original voice.
You can implement the voice changer by the enumerations in setVoiceConversionPreset
as follows:
Enumeration | Description |
---|---|
VOICE_CONVERSION_OFF |
Turn off voice conversion effects and use the original voice. |
VOICE_CHANGER_NEUTRAL |
A gender-neutral voice. To avoid audio distortion, ensure that you use this enumerator to process a female-sounding voice. |
VOICE_CHANGER_SWEET |
A sweet voice. To avoid audio distortion, ensure that you use this enumerator to process a female-sounding voice. |
VOICE_CHANGER_SOLID |
A steady voice. To avoid audio distortion, ensure that you use this enumerator to process a male-sounding voice. |
VOICE_CHANGER_BASS |
A deep voice. To avoid audio distortion, ensure that you use this enumerator to process a male-sounding voice. |
VOICE_CONVERSION_PRESET preset;
// Presets the local voice by making it sound like a gender-neutral voice.
preset = VOICE_CHANGER_NEUTRAL;
rtcEngine.setVoiceConversionPreset(preset);
// Disables voice effects.
preset = VOICE_CONVERSION_OFF;
rtcEngine.setVoiceConversionPreset(preset);
If the preset effect does not meet your requirement, you can also customize the voice effects by adjusting the voice pitch, equalization, and reverberation settings through setLocalVoicePitch
, setLocalVoiceEqualization
, and setLocalVoiceReverb
.
The following sample code shows how to change the original user's voice to the 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.
int nRet = rtcEngine.setLocalVoicePitch(0.5);
// 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.
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_31, -15);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_62, 3);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_125, -9);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_250, -8);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_500, -6);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_1K, -4);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_2K, -3);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_4K, -2);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_8K, -1);
nRet = rtcEngine.setLocalVoiceEqualization(AUDIO_EQUALIZATION_BAND_16K, 1);
// The level of the dry signal in dB. The value ranges between -20 and 10.
nRet = rtcEngine.setLocalVoiceReverb(AUDIO_REVERB_DRY_LEVEL, 10);
// The level of the early reflection signal (wet signal) in dB. The value ranges between -20 and 10.
nRet = rtcEngine.setLocalVoiceReverb(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.
nRet = rtcEngine.setLocalVoiceReverb(AUDIO_REVERB_ROOM_SIZE, 6);
// The length of the initial delay of the wet signal (ms). The value ranges between 0 and 200.
nRet = rtcEngine.setLocalVoiceReverb(AUDIO_REVERB_WET_DELAY, 124);
// The reverberation strength. The value ranges between 0 and 100. The higher the value, the stronger the reverberation.
nRet = rtcEngine.setLocalVoiceReverb(AUDIO_REVERB_STRENGTH, 78);
Preset voice effects
setAudioEffectPreset
setVoiceBeautifierPreset
setAudioEffectParameters
setVoiceBeautifierParameters
setVoiceConversionPreset
Customized voice effects
profile
parameter of setAudioProfile
to AUDIO_PROFILE_SPEECH_STANDARD(1)
or AUDIO_PROFILE_IOT(6)
; otherwise, the following methods do not take effect.setAudioEffectPreset
setVoiceBeautifierPreset
setAudioEffectParameters
setVoiceBeautifierParameters
setVoiceConversionPreset
setAudioEffectPreset
setVoiceBeautifierPreset
setAudioEffectParameters
setVoiceBeautifierParameters
setVoiceConversionPreset
setLocalVoicePitch
setLocalVoiceEqualizationOfBandFrequency
setLocalVoiceReverbOfType