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

Voice Changer Demo


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.

Java
 
HAEApplication.getInstance().setAccessToken("your access token");
Java
 
HAEApplication.getInstance().setApiKey("your ApiKey");

Calling the File API

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

Java
 
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.
    }
};

Implementing the Voice Changer Capability

Call applyAudioFile to change the voice.

Java
 
// 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();

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.

 

 

 

 

Top