The ARTC SDK provides real-time audio effects, including voice change, reverberation, and voice beautification. During a Real-Time Communication (RTC) call, you can call APIs to apply these effects to a local user's voice and create a more engaging and entertaining experience.
Features
You can quickly enable these audio effects by calling the relevant APIs:
-
Voice change: Change the user's voice to sound like an elder, a boy, or a girl.
-
Reverberation: Add a reverberation effect to create a spatial ambiance, making the user's voice sound as if it's coming from a specific venue.
-
Voice beautification: Fine-tune the timbre of a voice to a specific style, such as Magnetic or Fresh.
-
Custom voice effect: In addition to the preset modes, you can call APIs to adjust the pitch, reverberation, and equalizer settings to create custom voice effects.
Sample code
ARTC provides an open-source sample project. You can download the project or view the source code at the following locations:
Configure voice change, reverberation, and voice beautification on Android: Android/ARTCExample/BasicUsage/src/main/java/com/aliyun/artc/api/basicusage/VoiceChange/VoiceChangeActivity.java
Configure voice change, reverberation, and voice beautification on iOS: iOS/ARTCExample/BasicUsage/VoiceChange/VoiceChangeVC.swift
Prerequisites
Before you begin, ensure you have completed the following:
-
You have a valid Alibaba Cloud account and have created an RTC application. For more information, see Create an application. Obtain an App ID and an App Key from the Application Management console.
-
You have completed the SDK integration and implemented basic RTC functionality in your project. For SDK integration instructions, see Download and integrate the SDK. To implement a basic call, see Implement an audio and video call.
Implementation
This section describes how to call the APIs in your project to apply various audio effects.
Voice change
Call the setAudioEffectVoiceChangerMode method to apply a voice change effect, such as Elder, Boy, or Girl. Each effect corresponds to an enumeration value, listed in the table below:
|
Voice change mode |
Enumeration |
|
Off |
|
|
Elder |
|
|
Boy |
|
|
Girl |
|
|
Robot |
|
|
Devil |
|
|
KTV |
|
|
Echo |
|
|
Dialect |
|
|
Roar |
|
|
Electronic |
|
|
Phonograph |
|
Android
// Set the preset voice change mode.
mAliRtcEngine.setAudioEffectVoiceChangerMode(mode);
iOS
// Set the preset voice change mode.
self.rtcEngine?.setAudioEffectVoiceChangerMode(mode)
Mac
// Set the preset voice change mode.
[self.rtcEngine setAudioEffectVoiceChangerMode:mode];
Windows
// Set the preset voice change mode.
mAliRtcEngine->SetAudioEffectVoiceChangerMode(mode);
Reverberation
Call the setAudioEffectReverbMode method to apply a reverberation effect. This creates a spatial ambiance that makes the voice sound as if in a specific venue. The table below lists the available modes:
|
Reverberation mode |
Enumeration |
|
Off |
|
|
Vocal I |
|
|
Vocal II |
|
|
Bathroom |
|
|
Small bright room |
|
|
Small dark room |
|
|
Medium room |
|
|
Large room |
|
|
Church hall |
|
Android
// Set the preset reverberation mode.
mAliRtcEngine.setAudioEffectReverbMode(mode);
// You can also configure the effect by using parameters.
iOS
// Set the preset reverberation mode.
self.rtcEngine?.setAudioEffectReverbMode(mode)
Mac
// Set the preset reverberation mode.
[self.engine setAudioEffectReverbMode:selectMode];
Windows
// Set the preset reverberation mode.
mAliRtcEngine->SetAudioEffectReverbMode(mode);
// You can also configure the effect by using parameters.
Voice beautification
Call the setAudioEffectBeautifyMode method to apply a voice beautification effect. Two preset modes are available: Magnetic and Fresh.
|
Voice beautification mode |
Enumeration |
|
Magnetic |
|
|
Fresh |
|
Android
// Set the preset voice beautification mode.
mAliRtcEngine.setAudioEffectBeautifyMode(mode);
// You can also configure the effect by using parameters.
iOS
// Set the preset voice beautification mode.
self.rtcEngine?.setAudioEffectBeautifyMode(mode)
Mac
// Set the preset voice beautification mode.
[self.engine setAudioEffectBeautifyMode:selectMode];
Windows
// Set the preset voice beautification mode.
mAliRtcEngine->SetAudioEffectBeautifyMode(mode);
// You can also configure the effect by using parameters.
Custom voice effect
If the preset audio effects do not meet your needs, you can call the following methods to adjust the pitch, equalizer, and reverberation parameters to create a custom voice effect.
You can use the following methods:
-
setAudioEffectPitchValue(value): Sets the voice pitch.-
value: The pitch value. The range is [0.5, 2.0]. The default value is 1.0, which indicates no change. A value less than 1.0 lowers the pitch, and a value greater than 1.0 raises the pitch.
-
-
setAudioEffectReverbParamType(type, value): Sets a specific reverberation parameter. You must call this method after callingsetAudioEffectReverbMode.-
type: The type of reverberation parameter. For more information, see AliRtcAudioEffectReverbParamType. -
value: The value of the reverberation parameter. Each parameter type has a different value range. For details, see AliRtcAudioEffectReverbParamType.
-
-
setAudioEffectEqualizationParam(bandIndex, gain): Sets an equalizer parameter. You must call this method after callingsetAudioEffectBeautifyMode.-
bandIndex: The index of the equalizer band. The range is [0, 9], which corresponds to the 10 frequency bands: 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, and 16000 Hz. -
gain: The gain of the band in dB. The range is [-15, 15]. The default value is 0.
-
Android
// Set the pitch. The value ranges from 0.5 to 2.0. The default is 1.0.
// A value less than 1.0 lowers the pitch, and a value greater than 1.0 raises it.
mAliRtcEngine.setAudioEffectPitchValue(1.5);
// To set custom reverb parameters, you must first set a reverb mode.
// Example: Set the mode to Large Room, then adjust the room size.
mAliRtcEngine.setAudioEffectReverbMode(AliRtcEngine.AliRtcAudioEffectReverbMode.AliRtcSdk_AudioEffect_Reverb_Large_Room);
mAliRtcEngine.setAudioEffectReverbParamType(AliRtcEngine.AliRtcAudioEffectReverbParamType.AliRtcSdk_AudioEffect_Reverb_Room_Size, 50);
// To set custom equalizer parameters, you must first set a voice beautification mode.
// Example: Set the mode to Magnetic, then adjust the gain of a specific band.
mAliRtcEngine.setAudioEffectBeautifyMode(AliRtcEngine.AliRtcAudioEffectBeautifyMode.AliRtcSdk_AudioEffect_Beautify_Magnetic);
mAliRtcEngine.setAudioEffectEqualizationParam(AliRtcEngine.AliRtcAudioEffectEqualizationBandFrequency.AliRtcSdk_AudioEffect_EqualizationBand1K, 5);
iOS
// Set the pitch. The value ranges from 0.5 to 2.0. The default is 1.0.
// A value less than 1.0 lowers the pitch, and a value greater than 1.0 raises it.
let pitch = 1.5
self.rtcEngine?.setAudioEffectPitchValue(pitch)
// To set custom reverb parameters, you must first set a reverb mode.
// Example: Set the mode to Large Room, then adjust the room size.
self.rtcEngine?.setAudioEffectReverbMode(.large_Room)
self.rtcEngine?.setAudioEffectReverbParamType(.room_Size, value: 50)
// To set custom equalizer parameters, you must first set a voice beautification mode.
// Example: Set the mode to Magnetic, then adjust the gain of a specific band.
self.rtcEngine?.setAudioEffectBeautifyMode(.magnetic)
self.rtcEngine?.setAudioEffectEqualizationParam(.band1K, gain: 5)
Mac
// Set the pitch. The value ranges from 0.5 to 2.0. The default is 1.0.
// A value less than 1.0 lowers the pitch, and a value greater than 1.0 raises it.
int pitch = 1.5;
[self.rtcEngine setAudioEffectPitchValue:pitch];
// To set custom reverb parameters, you must first set a reverb mode.
// Example: Set the mode to Large Room, then adjust the room size.
[self.rtcEngine setAudioEffectReverbMode:AliRtcAudioEffectReverb_Large_Room];
[self.rtcEngine setAudioEffectReverbParamType:AliRtcAudioEffectReverb_Room_Size value:50.0];
// To set custom equalizer parameters, you must first set a voice beautification mode.
// Example: Set the mode to Magnetic, then adjust the gain of a specific band.
[self.rtcEngine setAudioEffectBeautifyMode:AliRtcAudioEffectBeautify_Magnetic];
[self.rtcEngine setAudioEffectEqualizationParam:AliRtcAudioEffectEqualizationBand1K gain:5.0];
Windows
// Set the pitch. The value ranges from 0.5 to 2.0. The default is 1.0.
// A value less than 1.0 lowers the pitch, and a value greater than 1.0 raises it.
mAliRtcEngine->SetAudioEffectPitchValue(1.5);
// To set custom reverb parameters, you must first set a reverb mode.
// Example: Set the mode to Large Room, then adjust the room size.
mAliRtcEngine->SetAudioEffectReverbMode(AliEngineAudioEffectReverbMode::AliEngineAudioEffectReverb_Large_Room);
mAliRtcEngine->SetAudioEffectReverbParamType(AliEngineAudioEffectReverbParamType::AliEngineAudioEffectReverbParamType_Room_Size, 50.0f);
// To set custom equalizer parameters, you must first set a voice beautification mode.
// Example: Set the mode to Magnetic, then adjust the gain of a specific band.
mAliRtcEngine->SetAudioEffectBeautifyMode(AliEngineAudioEffectBeautifyMode::AliEngineAudioEffectBeautify_Magnetic);
mAliRtcEngine->SetAudioEffectEqualizationParam(AliEngineAudioEffectEqualizationBandFrequency::AliEngineAudioEffectEqualizationBandFrequency_Band1K, 5.0f);