DEV Community

Jackson for HMS Core

Posted on

How to Develop a Noise Reduction Function

Background

It's now possible to carry a mobile recording studio in your pocket, thanks to a range of apps on the market that allow music enthusiasts to sing and record themselves anytime and anywhere.
However, you'll often find that nasty background noise creeps into recordings. That's where HMS Core Audio Editor Kit comes into the mix, which, when integrated into an app, will cancel out background noise. Let's see how to integrate it to develop a noise reduction function.

Image description

Development Process

Making Preparations

Complete these prerequisites.

Configuring the Project

1) Set the app authentication information via an access token or API key.

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

2) Call the file API for the noise reduction capability. Before this, the callback for the file API must have been created.

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 failed.
    }
    @Override
    public void onCancel() {
        // Callback when the processing is canceled.
    }
};
Enter fullscreen mode Exit fullscreen mode

3) Call applyAudioFile for noise reduction.

// Reduce noise.
HAENoiseReductionFile haeNoiseReductionFile = new HAENoiseReductionFile();
// API calling.
haeNoiseReductionFile.applyAudioFile(inAudioPath, outAudioDir, outAudioName, callBack);
// Cancel the noise reduction task.
haeNoiseReductionFile.cancel();
Enter fullscreen mode Exit fullscreen mode

And the function is now created.
This function is ideal for audio/video editing, karaoke, live streaming, instant messaging, and for holding online conferences, as it helps mute steady state noise and loud sounds captured from one or two microphones, to make a person's voice sound crystal clear. How would you use this function? Share your ideas in the comments section.

Top comments (0)