Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

You are looking at Interactive Live Streaming v3.x Docs. The newest version is  Interactive Live Streaming 4.x

Android
iOS
macOS
Windows C++
Windows C#
Unity
Flutter
React Native
Electron
Cocos Creator
Cocos2d-x

Set the Voice Effect

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 Video 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.

Sample project

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.

Use preset voice effects

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:
  • Blind date
  • Emotional radio
  • Co-host audio streaming
  • Voice-only PK Hosting
  • Gaming chatroom
  • Singing beautifier Audio and video scenarios focusing on a user’s singing voice:
  • Online KTV
  • Music radio
  • Live-streaming showroom
  • Timbre transformation Audio and video scenarios focusing on a user’s speaking or singing voice:
  • Co-host audio streaming
  • Voice PK hosting
  • Gaming chatroom
  • Blind date
  • Online KTV
  • FM radio
  • Audio effect

    setAudioEffectPreset

    Voice changer 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 or singing voice:
  • Co-host audio streaming
  • Voice PK hosting
  • Gaming chatroom
  • Blind date
  • Online KTV
  • FM radio
  • Pitch correction Audio and video scenarios focusing on a user’s singing voice:
  • Online KTV
  • Music radio
  • Live-streaming showroom
  • Voice conversion

    setVoiceConversionPreset

    Voice conversion Audio and video scenarios focusing on a user’s speaking or singing voice:
  • Co-host audio streaming
  • Voice PK hosting
  • Gaming chatroom
  • Blind date
  • Online KTV
  • FM radio
  • 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 setVoiceBeautifierPreset as follows:

    EnumerationDescription
    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.
    To achieve better audio effect quality, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

    _4
    // Beautifies the local voice by making it sound more magnetic (for male only).
    _4
    mRtcEngine.setVoiceBeautifierPreset(Constants.CHAT_BEAUTIFIER_MAGNETIC);
    _4
    // Disables voice effects.
    _4
    mRtcEngine.setVoiceBeautifierPreset(Constants.VOICE_BEAUTIFIER_OFF);

    Singing beautifier

    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.

    • If you call 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.
    • If you call setVoiceBeautifierParameters(SINGING_BEAUTIFIER, param1, param2), you can beautify a male- or female-sounding voice and add one of several reverberation effects.
    To achieve better audio effect quality, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

    _6
    // Beautifies the singing voice of the local user.
    _6
    mRtcEngine.setVoiceBeautifierPreset(Constants.SINGING_BEAUTIFIER);
    _6
    // Beautifies a female-sounding voice and add a reverberation effect that sounds like singing in a hall.
    _6
    mRtcEngine.setVoiceBeautifierParameters(Constants.SINGING_BEAUTIFIER, 2, 3);
    _6
    // Disables voice effects.
    _6
    mRtcEngine.setVoiceBeautifierPreset(Constants.VOICE_BEAUTIFIER_OFF);

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

    EnumerationDescription
    TIMBRE_TRANSFORMATION_VIGOROUSA more vigorous voice.
    TIMBRE_TRANSFORMATION_DEEPA deeper voice.
    TIMBRE_TRANSFORMATION_MELLOWA mellower voice.
    TIMBRE_TRANSFORMATION_FALSETTOA falsetto voice.
    TIMBRE_TRANSFORMATION_FULLA fuller voice.
    TIMBRE_TRANSFORMATION_CLEARA clearer voice.
    TIMBRE_TRANSFORMATION_RESOUNDINGA more resounding voice.
    TIMBRE_TRANSFORMATION_RINGINGA more ringing voice.
    To achieve better audio effect quality, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

    _4
    // Beautifies the local voice by making it sound more vigorous.
    _4
    mRtcEngine.setVoiceBeautifierPreset(Constants.TIMBRE_TRANSFORMATION_VIGOROUS);
    _4
    // Disables voice effects.
    _4
    mRtcEngine.setVoiceBeautifierPreset(Constants.VOICE_BEAUTIFIER_OFF);

    Voice changer

    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:

    EnumerationDescription
    VOICE_CHANGER_EFFECT_UNCLEThe 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_OLDMANThe 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_BOYThe 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_SISTERThe 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_GIRLThe 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_PIGKINGThe voice of Pig King, a character in Journey to the West who has a voice like a growling bear.
    VOICE_CHANGER_EFFECT_HULKThe voice of Hulk.
    To achieve better audio effect quality, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

    _4
    // Presets the local voice by making it sound like the Hulk.
    _4
    mRtcEngine.setAudioEffectPreset(Constants.VOICE_CHANGER_EFFECT_HULK);
    _4
    // Disables voice effects.
    _4
    mRtcEngine.setAudioEffectPreset(Constants.AUDIO_EFFECT_OFF);

    Style transformation

    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:

    EnumerationDescription
    STYLE_TRANSFORMATION_POPULARAn audio effect typical of popular music.
    STYLE_TRANSFORMATION_RNBAn audio effect typical of R&B music.
  • Call setAudioProfile and set the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5) before setting this enumerator; otherwise, the enumerator setting does not take effect.
  • To achieve better audio effect quality, Agora recommends setting the scenario parameter of setAudioProfile to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

  • _4
    // Presets the local voice to the style of pop music.
    _4
    mRtcEngine.setAudioEffectPreset(Constants.STYLE_TRANSFORMATION_POPULAR);
    _4
    // Disables voice effects.
    _4
    mRtcEngine.setAudioEffectPreset(Constants.AUDIO_EFFECT_OFF);

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

    EnumerationDescription
    ROOM_ACOUSTICS_KTVAn audio effect typical of a KTV venue.
    ROOM_ACOUSTICS_VOCAL_CONCERTAn audio effect typical of a concert hall.
    ROOM_ACOUSTICS_STUDIOAn audio effect typical of a recording studio.
    ROOM_ACOUSTICS_PHONOGRAPHAn audio effect typical of a vintage phonograph.
    ROOM_ACOUSTICS_VIRTUAL_STEREOA virtual stereo effect that renders monophonic audio as stereo audio.

    Note

  • Call 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.
  • To achieve better audio effect quality, Agora recommends setting the scenario parameter of setAudioProfile to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.
  • ROOM_ACOUSTICS_SPACIALA more spatial audio effect.
    ROOM_ACOUSTICS_ETHEREALA more ethereal audio effect.
    ROOM_ACOUSTICS_3D_VOICEA 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

  • Call 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.
  • To achieve better audio effect quality, Agora recommends setting the scenario parameter of setAudioProfile to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.
  • If the 3D voice effect is enabled, users need to use stereo audio playback devices to hear the anticipated voice effect.
  • If you use an enumerator excluding ROOM_ACOUSTICS_VIRTUAL_STEREO or ROOM_ACOUSTICS_3D_VOICE to implement better voice effects, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

    _6
    // Presets the local voice by making it appear to be moving around the user.
    _6
    mRtcEngine.setAudioEffectPreset(Constants.ROOM_ACOUSTICS_3D_VOICE);
    _6
    // Changes the cycle period to 30 seconds.
    _6
    mRtcEngine.setAudioEffectParameters(Constants.ROOM_ACOUSTICS_3D_VOICE, 30, 0);
    _6
    // Disables voice effects.
    _6
    mRtcEngine.setAudioEffectPreset(Constants.AUDIO_EFFECT_OFF);

    Pitch correction

    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:

    EnumerationDescription
    PITCH_CORRECTIONA 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.
  • To achieve better audio effect quality, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.
  • Different songs have different modes and tonic pitches. Agora recommends bounding this method with interface elements to enable users to adjust the pitch correction interactively.

  • _6
    // Presets the local voice by making it match the song.
    _6
    mRtcEngine.setAudioEffectPreset(Constants.PITCH_CORRECTION);
    _6
    // Changes the basic mode to natural minor scale and the tonic pitch to D.
    _6
    mRtcEngine.setAudioEffectParameters(Constants.PITCH_CORRECTION, 2, 6);
    _6
    // Disables voice effects.
    _6
    mRtcEngine.setAudioEffectPreset(Constants.AUDIO_EFFECT_OFF);

    Voice conversion

    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:

    EnumerationDescription
    VOICE_CONVERSION_OFFTurn off voice conversion effects and use the original voice.
    VOICE_CHANGER_NEUTRALA gender-neutral voice. To avoid audio distortion, ensure that you use this enumerator to process a female-sounding voice.
    VOICE_CHANGER_SWEETA sweet voice. To avoid audio distortion, ensure that you use this enumerator to process a female-sounding voice.
    VOICE_CHANGER_SOLIDA steady voice. To avoid audio distortion, ensure that you use this enumerator to process a male-sounding voice.
    VOICE_CHANGER_BASSA deep voice. To avoid audio distortion, ensure that you use this enumerator to process a male-sounding voice.
    To achieve better audio effect quality, Agora recommends calling setAudioProfile, setting the profile parameter to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4) or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and setting the scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3) before setting this enumerator.

    _4
    // Presets the local voice by making it sound like a gender-neutral voice.
    _4
    mRtcEngine.setVoiceConversionPreset(Constants.VOICE_CHANGER_NEUTRAL);
    _4
    // Disables voice effects.
    _4
    mRtcEngine.setVoiceConversionPreset(Constants.VOICE_CONVERSION_OFF);

    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.


    _32
    // 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.
    _32
    double pitch = 0.5;
    _32
    mRtcEngine.setLocalVoicePitch(pitch);
    _32
    _32
    // Sets the local voice equalization.
    _32
    // 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.
    _32
    // The second parameter sets the gain of each band. The value ranges between -15 and 15 dB. The default value is 0.
    _32
    mRtcEngine.setLocalVoiceEqualization(0, -15);
    _32
    mRtcEngine.setLocalVoiceEqualization(1, 3);
    _32
    mRtcEngine.setLocalVoiceEqualization(2, -9);
    _32
    mRtcEngine.setLocalVoiceEqualization(3, -8);
    _32
    mRtcEngine.setLocalVoiceEqualization(4, -6);
    _32
    mRtcEngine.setLocalVoiceEqualization(5, -4);
    _32
    mRtcEngine.setLocalVoiceEqualization(6, -3);
    _32
    mRtcEngine.setLocalVoiceEqualization(7, -2);
    _32
    mRtcEngine.setLocalVoiceEqualization(8, -1);
    _32
    mRtcEngine.setLocalVoiceEqualization(9, 1);
    _32
    _32
    // The level of the dry signal in dB. The value ranges between -20 and 10.
    _32
    mRtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_DRY_LEVEL, 10);
    _32
    _32
    // The level of the early reflection signal (wet signal) in dB. The value ranges between -20 and 10.
    _32
    mRtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_WET_LEVEL, 7);
    _32
    _32
    // The room size of the reverberation. A larger room size means a stronger reverberation. The value ranges between 0 and 100.
    _32
    mRtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_ROOM_SIZE, 6);
    _32
    _32
    // The length of the initial delay of the wet signal (ms). The value ranges between 0 and 200.
    _32
    mRtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_WET_DELAY, 124);
    _32
    _32
    // The reverberation strength. The value ranges between 0 and 100. The higher the value, the stronger the reverberation.
    _32
    mRtcEngine.setLocalVoiceReverb(Constants.AUDIO_REVERB_STRENGTH, 78);

    API reference

    Preset voice effects

    Customized voice effects

    Considerations

    • Do not set the profile parameter of setAudioProfile to AUDIO_PROFILE_SPEECH_STANDARD(1); otherwise, the following methods do not take effect.
    • setAudioEffectPreset
    • setVoiceBeautifierPreset
    • setAudioEffectParameters
    • setVoiceBeautifierParameters
    • setVoiceConversionPreset
    • All methods mentioned in this article work best with the human voice. Agora does not recommend using them for audio containing both music and voice.
    • Agora recommends not calling the following methods together, because the method called subsequently overrides whichever one is called before it:
      • setAudioEffectPreset
      • setVoiceBeautifierPreset
      • setAudioEffectParameters
      • setVoiceBeautifierParameters
      • setVoiceConversionPreset
      • setLocalVoicePitch
      • setLocalVoiceEqualizationOfBandFrequency
      • setLocalVoiceReverbOfType

    Interactive Live Streaming