Introduction

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.

Implementation

Before proceeding, ensure that you implement a basic call or the live interactive streaming in your project. See Start a Call or Start Live Interactive Streaming for details.

Use preset voice effects

The SDK provides voice beautifier and voice effects for different scenarios, as follows:

Category Scenario
Voice beautifier Chat beautifier Audio and video scenarios focusing on a user’s speaking voice:
  • Blind date
  • Emotional radio
  • Co-host audio streaming
  • Voice-only PK Hosting
  • Gaming chatroom
  • Timbre transformation Audio and video scenarios focusing on a user’s speaking voice or singing voice:
  • Co-host audio streaming
  • Voice PK hosting
  • Gaming chatroom
  • Blind date
  • Online KTV
  • FM radio
  • Audio effect Voice changer effect Audio and video scenarios focusing on a user’s speaking voice:
  • Co-host audio streaming
  • Voice-only PK Hosting
  • Gaming chatroom
  • Style transformation Audio and video scenarios focusing on a user’s singing voice:
  • Online KTV
  • Music radio
  • Live-streaming showroom
  • Room acoustics Audio and video scenarios focusing on a user’s speaking voice or singing voice:
  • Co-host audio streaming
  • Voice PK hosting
  • Gaming chatroom
  • Blind date
  • Online KTV
  • FM radio
  • You can use the preset voice effects by calling setLocalVoiceChanger or setLocalVoiceReverbPreset.

  • Before calling the method, you need to set the profile parameter of setAudioProfile to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and to set scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3).
  • The voice effects preset in setLocalVoiceChanger and setLocalVoiceReverbPreset are mutually exclusive. The method called later overrides the one called earlier.
  • Chat beautifier

    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 setLocalVoiceChanger as follows:

    Enumeration Description
    GENERAL_BEAUTY_VOICE_MALE_MAGNETIC (For male-sounding voice only) A more magnetic voice. Do not use for speakers with a female-sounding voice; otherwise, voice distortion occurs.
    GENERAL_BEAUTY_VOICE_FEMALE_FRESH (For female-sounding voice only) A fresher voice. Do not use for speakers with a male-sounding voice; otherwise, voice distortion occurs.
    GENERAL_BEAUTY_VOICE_FEMALE_VITALITY (For female-sounding voice only) A more vital voice. Do not use for speakers with a male-sounding voice; otherwise, voice distortion occurs.
    VOICE_CHANGER_PRESET voiceChanger;
    // Beautifies the local voice by making it sound more magnetic (for male only).
    voiceChanger = GENERAL_BEAUTY_VOICE_MALE_MAGNETIC;
    rtcEngine.setLocalVoiceChanger(voiceChanger);
    // Disables voice effects.
    voiceChanger = VOICE_CHANGER_OFF;
    rtcEngine.setLocalVoiceChanger(voiceChanger);

    Timbre transformation

    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 setLocalVoiceChanger as follows:

    Enumeration Description
    VOICE_BEAUTY_VIGOROUS A more vigorous voice.
    VOICE_BEAUTY_DEEP A deeper voice.
    VOICE_BEAUTY_MELLOW A mellower voice.
    VOICE_BEAUTY_FALSETTO Falsetto.
    VOICE_BEAUTY_FULL A fuller voice.
    VOICE_BEAUTY_CLEAR A clearer voice.
    VOICE_BEAUTY_RESOUNDING A more resounding voice.
    VOICE_BEAUTY_RINGING A more ringing voice.
    VOICE_CHANGER_PRESET voiceChanger;
    // Beautifies the local voice by making it sound more vigorous.
    voiceChanger = VOICE_BEAUTY_VIGOROUS;
    rtcEngine.setLocalVoiceChanger(voiceChanger);
    // Disables voice effects.
    voiceChanger = VOICE_CHANGER_OFF;
    rtcEngine.setLocalVoiceChanger(voiceChanger);

    Voice changer effect

    Voice changer effects adjust the voice to make it sound different from the original.

    You can implement the voice changer effect by the enumerations in setLocalVoiceChanger or setLocalVoiceReverbPreset as follows:

    Method Enumeration Description
    setLocalVoiceChanger VOICE_CHANGER_OLDMAN (For male-sounding voice only) Voice of an old man.
    VOICE_CHANGER_BABYBOY (For male-sounding voice only) Voice of a little boy.
    VOICE_CHANGER_BABYGIRL (For female-sounding voice only) Voice of a little girl.
    VOICE_CHANGER_ZHUBAJIE Voice of the Zhu Bajie, a character in Journey to the West who has a voice like that of a growling bear.
    VOICE_CHANGER_HULK Voice of the Hulk.
    setLocalVoiceReverbPreset AUDIO_REVERB_FX_UNCLE (For male-sounding voice only) Voice of a middle-aged uncle.
    AUDIO_REVERB_FX_SISTER (For female-sounding voice only) Voice of a maiden.
    VOICE_CHANGER_PRESET voiceChanger;
    // Presets the local voice by making it sound like the Hulk.
    voiceChanger = VOICE_CHANGER_HULK;
    rtcEngine.setLocalVoiceChanger(voiceChanger);
    // Disables voice effects.
    voiceChanger = VOICE_CHANGER_OFF;
    rtcEngine.setLocalVoiceChanger(voiceChanger);
    AUDIO_REVERB_PRESET reverbPreset;
    // Presets the local voice by making it sound like a middle-aged uncle (for male-sounding voice only).
    reverbPreset = AUDIO_REVERB_FX_UNCLE;
    rtcEngine.setLocalVoiceReverbPreset(reverbPreset);
    // Disables voice effects.
    reverbPreset = AUDIO_REVERB_OFF;
    rtcEngine.setLocalVoiceReverbPreset(reverbPreset);

    Style transformation

    A style transformation makes singing more harmonious for specific styles of songs.

    You can implement the style transformation by the enumerations in setLocalVoiceReverbPreset as follows:

    To implement better voice effects, Agora recommends enumerations with AUDIO_REVERB_FX as the prefix.
    Enumeration Description
    AUDIO_REVERB_FX_POPULAR The reverberation style typical of pop music.
    AUDIO_REVERB_POPULAR The reverberation style typical of pop music (old version).
    AUDIO_REVERB_FX_RNB The reverberation style typical of R&B music.
    AUDIO_REVERB_RNB The reverberation style typical of R&B music (old version).
    AUDIO_REVERB_ROCK The reverberation style typical of rock music.
    AUDIO_REVERB_HIPHOP The reverberation style typical of hip-hop music.
    AUDIO_REVERB_PRESET reverbPreset;
    // Presets the local voice to the style of pop music.
    reverbPreset = AUDIO_REVERB_FX_POPULAR;
    rtcEngine.setLocalVoiceReverbPreset(reverbPreset);
    // Disables voice effects.
    reverbPreset = AUDIO_REVERB_OFF;
    rtcEngine.setLocalVoiceReverbPreset(reverbPreset);

    Room acoustics

    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 setLocalVoiceChanger or setLocalVoiceReverbPreset as follows:

  • To implement better voice effects, Agora recommends enumerations with AUDIO_REVERB_FX as the prefix.
  • To achieve better virtual stereo reverberation, Agora recommends setting the profile parameter of setAudioProfile as AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5).
  • Method Enumeration Description
    setLocalVoiceChanger VOICE_BEAUTY_SPACIAL A more spatially resonant voice.
    VOICE_CHANGER_ETHEREAL An ethereal voice
    setLocalVoiceReverbPreset AUDIO_REVERB_FX_VOCAL_CONCERT The reverberation style typical of a concert hall.
    AUDIO_REVERB_VOCAL_CONCERT The reverberation style typical of a concert hall (old version).
    AUDIO_REVERB_FX_KTV The reverberation style typical of a KTV venue.
    AUDIO_REVERB_KTV The reverberation style typical of a KTV venue (old version).
    AUDIO_REVERB_FX_STUDIO The reverberation style typical of a recording studio.
    AUDIO_REVERB_STUDIO The reverberation style typical of a recording studio (old version).
    AUDIO_REVERB_FX_PHONOGRAPH The reverberation style typical of a vintage phonograph.
    AUDIO_VIRTUAL_STEREO A reverberation style that adds a virtual stereo effect. The virtual stereo is an effect that renders the monophonic audio as stereo.
    VOICE_CHANGER_PRESET voiceChanger;
    // Presets the local voice by making it sound more spatially resonant.
    voiceChanger = VOICE_BEAUTY_SPACIAL;
    rtcEngine.setLocalVoiceChanger(voiceChanger);
    // Disables voice effects.
    voiceChanger = VOICE_CHANGER_OFF;
    rtcEngine.setLocalVoiceChanger(voiceChanger);
    AUDIO_REVERB_PRESET reverbPreset;
    // Presets the local voice by making it sound like it is coming from a concert hall.
    reverbPreset = AUDIO_REVERB_FX_VOCAL_CONCERT;
    rtcEngine.setLocalVoiceReverbPreset(reverbPreset);
    // Disables voice effects.
    reverbPreset = AUDIO_REVERB_OFF;
    rtcEngine.setLocalVoiceReverbPreset(reverbPreset);

    Customize voice effects

    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);

    API reference

    Preset voice effects

    Customized voice effects

    Considerations

    • All methods mentioned in this article work best with the human voice only. Agora does not recommend using them for audio containing both music and voice.
    • Agora recommends not using the methods for presetting voice effects and for customizing voice effects together, as undefined behaviors may result. If you want to use preset voice effects together with methods that customize voice effects, call the preset methods before the customization methods, or the method called later overrides the one called earlier.