DEV Community

Jackson for HMS Core

Posted on • Edited on

2 2

How to Implement a Voice Changer Capability

Research has shown that our voice is often an indicator of our personalities, and this is why we're so fascinated with changing our voice to make it sound more fun and uplifting in, for example, videos and live streams.

As a mobile developer, I have implemented the voice changing function into my own app, which you can try out in my demo. This function allows users to mask their voice using seven preset voices: seasoned, cute, male, female, monster, cartoon, and robots.

I don't want to brag, but I myself still find this function amazing. Let's move on to how it's developed.

Making Preparations

Ensure you have completed these steps first.

Configuring the Project

Set the app authentication information.
This can be set via an API key or access token.

  • Call setAccessToken during app initialization to set an access token. This only needs to be set once.
HAEApplication.getInstance().setAccessToken("your access token");
Enter fullscreen mode Exit fullscreen mode
  • Or, use setApiKey to set an API key during app initialization. This only needs to be set once.
HAEApplication.getInstance().setApiKey("your ApiKey");
Enter fullscreen mode Exit fullscreen mode

Calling the File API

Call the file API for the voice changer function, which is necessary for calling back the file API.

private ChangeSoundCallback callBack = new ChangeSoundCallback() {
    @Override
    public void onSuccess(String outAudioPath) {
        // Callback when the processing is successful.
    }
    @Override
    public void onProgress(int progress) {
        // Callback when the processing progress is received.
    }
    @Override
    public void onFail(int errorCode) {
        // Callback when the processing fails.
    }
    @Override
    public void onCancel() {
        // Callback when the processing is canceled.
    }
};
Enter fullscreen mode Exit fullscreen mode

Implementing the Voice Changer Capability

Call applyAudioFile to change the voice.

// Change the voice.
HAEChangeVoiceFile haeChangeVoiceFile = new HAEChangeVoiceFile();
ChangeVoiceOption changeVoiceOption = new ChangeVoiceOption();
changeVoiceOption.setSpeakerSex(ChangeVoiceOption.SpeakerSex.MALE);
changeVoiceOption.setVoiceType(ChangeVoiceOption.VoiceType.CUTE);
haeChangeVoiceFile.changeVoiceOption(changeVoiceOption);
// Call the API.
haeChangeVoiceFile.applyAudioFile(inAudioPath, outAudioDir, outAudioName, callBack);
// Cancel the task of changing the voice.
haeChangeVoiceFile.cancel();
Enter fullscreen mode Exit fullscreen mode

And now it's implemented. Easy, right? I hope this article can help you develop your own voice changer, and feel free to leave a comment if you want to learn more about my development journey.

References

Why Your Voice Is Important
Voice - How humans communicate?
Voice changer

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay