Extensions Marketplace: How to Add Voice Changing Feature in Your Android Application with Agora and Voicemod
When I say video chat app, you may think I mean another generic application like Zoom or Google Meet. But you can make the app more than that by adding unique features, such as AR face filters.
Back in September of this year, Agora announced Extensions Marketplace at the RTE2021 conference. Extensions Marketplace is a revolutionary solution to add many unique, superpower features to an app without the hurdles and negotiation with various vendors and research into compatibility. It makes adding fun features very easy and straightforward.
Today, let me walk you through the process of implementing a voice-changing feature in an Android application so that your users can change voices and tunes during video call sessions.
We will use the Agora Android SDK and Voicemod from Extensions Marketplace. Let’s get started!
In this article, we have covered everything necessary to set up a simple 1–1 video calling android app with voice changing feature using Agora Android Video Call SDK and Voicemod extension.
- Prerequisites needed to set up the project
- How to set up a basic video calling app using Agora Android SDK
- How to activate the Voicemod extension from the Agora console
- How to link the extension in our local project
- Necessary code modifications needed to use the extension and stopping the extension
- How to run the app, plus other resources for reference
- Basic knowledge of Java/Kotlin and the Android SDK
- Android Studio
- Agora Developer Account
- Agora Android SDK (v4.0.0 Preview)
- Agora Android UI Kit
We need to first set up a basic video-calling app using the Agora Android UI Kit. Follow the steps below to set up your project.
- Initialize your Android project
- Download this GitHub repository (ngsdk-update branch)
- Import the “agorauikit_android” folder as a module into your project from the downloaded Android UI Kit project
- Add the following permissions in your AndroidManifest.xml
5. Add the following code in your project-level build.gradle
Activate the Voicemod Extension
To activate an extension:
- Log in to Agora Console.
- In the left navigation panel, click Extensions Marketplace, then click the extension you want to activate.
You are now on the extension detail page.
- Select a pricing plan and click the Activate button.
- If you have created an Agora project, the Projects section appears and lists all of your projects.
- If you do not have any Agora project, create a new project on the Project Management page. Once the project is created, it appears in the Projects section.
- Under Projects on the extension detail page, find the project in which you want to use the extension, then turn on the switch in the Action column.
Get APIKey and APISecret
The apiKey and apiSecret are credentials used by extension vendors for authentication purposes. They prove that you are authorized to use the extension.
To get your apiKey and apiSecret, find the project you are using under Projects on the extension detail page, then click the View button in the Secret column.
Download the extension and Agora SDK
To download the extension, click this link. This will be an Android Archive (.aar) file. We will talk about adding this file to our project in the next section.
Great going so far! We are halfway done. Now we will begin with Using the extension we just activated.
Using the Extension
- Place the downloaded Android Archive (.aar) file in two places, first in /app/libs and secondly in /agorauikit_android/libs.
- Add the following code to your build.gradle at app/build.gradle and at /agorauikit_android/build.gradle.kts.
Setting up the video call
Add the following code to initialize the Agora Android UI Kit and get started.
- Create a new Java/Kotlin file and name it ConnectionData. Add the following code in that file.
- To initialise the Agora Android UI Kit, create an AgoraVideoViewer instance in app/src/main/java/com.example<projectname>/MainActivity or the activity used for the video call
- Check if permissions have been given. If not, request permissions and join the desired channel.
Enable and use the extension
Enabling the extension is super easy, thanks to the Agora Android SDK. All we need to do is the following:
- Add the extension to the RtcEngineConfig. The add extension function has the extension name as a parameter. This is a very crucial step because it will help us use the extension later in our project.
Add the following code in /agorauikit_android/src/main/java/io/agora/agorauikit_android/AgoraVideoViewer.kt in the initAgoraEngine() function.
Initialize the Voicemod extension
Now that we have added the extension to our engine, the next step is to initialize the extension. The following steps must be followed:
- The setExtensionProperty of the RTCEngine class takes the extension’s vendor name, the extension’s Audio Filter name, the key “vcmd_user_data”, and our userData.
- userData consists simply of the APIKey and the APISecret obtained from the Agora Console when you enabled the extension there. If you haven’t stored them, you can go to the console and obtain them again.
- Strictly follow the format of the userData string shown below to avoid errors:
- All required names of the extension can be easily called using the ExtensionManager class, without having to write them ourselves.
Add the following code for initVoiceMod() function.
Run the Voicemod session
Now that we have successfully added and initialized our extension, it’s time for giving it a go!
- There is a list of supported voices. We can choose any one of these.
- We again use the setExtensionProperty of the RTCEngine class, but this time for the key “vcmd_voice”. We need to pass the following strings to the function: The extension’s vendor r name, the Audio Filter name, the key “vcmd_voice”, and the name of one of the supported voices as a String. Remember that the voices are predefined and that only these voices are currently supported.
- We should always wrap the code around with a try-catch block to avoid app crashes and easier debugging/logging:
Add the following code for runVoiceMod() function.
And we have successfully ran the Voicemod extension! Congratulations!!
Stop the Voicemod session
Now that we have successfully ran the Voicemod Extension, we should also remember to stop the extension. The rest of the code is same as that of disposing a Agora Android Video call SDK.
While this is not required to run the extension, it’s extremely important to add the following code to prevent app crashes and memory leaks.
- We use enableExtension function of the RTCEngine class. Simply pass the Extension’s vendor name, Extension’s Audio Filter name and pass false as the third parameter.
Test the extension
To test whether the extension works properly, follow these steps:
- Connect the Android device to the computer.
Run appon your Android Studio. A moment later you will see the project installed on your device.
- When the app launches, start speaking and you will notice the change in your voice once you start speaking.
Congratulations! You now have your video calling application with a cool voice changing effect and perfect understanding of the Agora Android SDK and Voicemod extension.
You can get the complete code for this application here.
Also, you may refer to this repository for a better understanding.
And take a look at the complete documentation for the Voicemod discussed above here.
For more information about Agora applications, take a look at the Agora Video Call Quickstart Guide and Agora API Reference.
I also invite you to join the Agora Developer Slack community.