Efficient records management is more relevant now than ever. In our digital age, huge growth of information — audio, video, and more — must be handled in a limited time. This makes a real-time transcription function essential, because it is useful in many scenarios.
In audio or video conferencing, this function records meeting minutes that I can refer to later, which is more convenient than writing them all by myself. I've seen my kids struggling to take notes during their online courses, so I know this process can be so much easier with the help of the transcription function. In short, it removed the job of writing down everything the teacher says, allowing the kids to focus on the lecture itself and easily review the content again later. Also, the live captions provide viewers with real-time subtitles, for a better watching experience.
As a coder, I am a believer in "Actions speak louder than words". That's why I developed a real-time transcription function, with the help of a real-time transcription capability from ML Kit, like this.
Demo
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
This function transcribes up to 5 hours of speech into Chinese, English (or both), and French languages in real time. In addition, the output text is punctuated and contains timestamps.
This function has some requirements: the support for French is dependent on the mobile phone model, whereas Chinese and English are available on all mobile phone models. Also, the function requires Internet connection.
Okay, let's move on to the point of this article: How I developed this real-time transcription function.
Development Procedure1. Make necessary preparations. This is described in detail in the References section.
2. Create and then configure a speech recognizer.
Code:
MLSpeechRealTimeTranscriptionConfig config = new MLSpeechRealTimeTranscriptionConfig.Factory()
// Set the language, which can be Chinese, English, both Chinese and English, or French.
.setLanguage(MLSpeechRealTimeTranscriptionConstants.LAN_ZH_CN)
// Punctuate the text recognized from the speech.
.enablePunctuation(true)
// Set the sentence offset.
.enableSentenceTimeOffset(true)
// Set the word offset.
.enableWordTimeOffset(true)
.create();
MLSpeechRealTimeTranscription mSpeechRecognizer = MLSpeechRealTimeTranscription.getInstance();
3. Create a callback for the speech recognition result listener.
Code:
// Use the callback to implement the MLSpeechRealTimeTranscriptionListener API and methods in the API.
Protected class SpeechRecognitionListener implements MLSpeechRealTimeTranscriptionListener{
@Override
public void onStartListening() {
// The recorder starts to receive speech.
}
@Override
public void onStartingOfSpeech() {
// The speech recognizer detects the user speaking.
}
@Override
public void onVoiceDataReceived(byte[] data, float energy, Bundle bundle) {
// Return the original PCM stream and audio power to the user. The API does not run in the main thread, and the return result is processed in a sub-thread.
}
@Override
public void onRecognizingResults(Bundle partialResults) {
// Receive recognized text from MLSpeechRealTimeTranscription.
}
@Override
public void onError(int error, String errorMessage) {
// Callback when an error occurs during recognition.
}
@Override
public void onState(int state,Bundle params) {
// Notify the app of the recognizer status change.
}
}
4. Bind the speech recognizer.
Code:
mSpeechRecognizer.setRealTimeTranscriptionListener(new SpeechRecognitionListener());
5. Call startRecognizing to begin speech recognition.
Code:
mSpeechRecognizer.startRecognizing(config);
6. Stop recognition and release resources occupied by the recognizer when the recognition is complete.
Code:
if (mSpeechRecognizer!= null) {
mSpeechRecognizer.destroy();
}
ReferencesAudio Transcription: What It Is, What It Is Not, and Why It's in High Demand
Configuring Necessary Information During Preparation
Adding a Plug-In and the Maven Repository Address, and Configuring the Building Dependencies
Related
Introduction
Have you ever met a situation like this before? A novel is too long to read, it will spare you much time if the app can automatically read the novel for you. So a tool to transfer text into speech is urgently required. HUAWEI ML kit (machine learning) has the function of TTS, which can help your app quickly achieve text to speech function.
Text to Speech can convert text into human voice. This can be achieved by default methods also but they don’t provide natural or realistic sounds.
This service uses Deep Neural Networks in order to process the text and create a natural sound, rich timbres are also supported in order to enhance the result. This service is available globally.
As this service uses cloud service hence there is a limit of 500 characters. These characters are encoded using UTF-8
Below are the format supported currently.
· English – Male voice
· English – Female voice
· Mandarin Chinese – Male voice
· Mandarin Chinese – Female voice
· English + Chinese – Male voice
· English + Chinese – Female voice
Article Takeaway
Below is the final result which we will be going to achieve after implementing this Kit.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Steps to Integrate
Step 1: Create a new project in Android Studio
Step 2: Add the below dependencies into app.gradle file
implementation 'com.huawei.hms:ml-computer-voice-tts:1.0.4.300'
Step 3: Add agc plugin in the top of app.gradle file
apply plugin: 'com.huawei.agconnect'
Step 4: Create a callback in your activity
var callback: MLTtsCallback = object : MLTtsCallback {
override fun onError(taskId: String, err: MLTtsError) {
}
override fun onWarn(taskId: String, warn: MLTtsWarn) {
}
override fun onRangeStart(taskId: String, start: Int, end: Int) {
}
override fun onEvent(taskId: String, eventName: Int, bundle: Bundle?) {
if (eventName == MLTtsConstants.EVENT_PLAY_STOP) {
val isStop = bundle?.getBoolean(MLTtsConstants.EVENT_PLAY_STOP_INTERRUPTED)
}
}
}
Let us discuss this in detail.
4 callback methods are provided. Below are the details.
· OnError() - In case of any error the control will flow here, you can use this to notify user what error occurred and send the analytics data by HMS Analytics to console for further verification.
· OnWarn() - In case of warning like insufficient bandwidth the callback comes here.
· OnRangeStart() - It returns the mapping between the currently played segment and text
· OnEvent() - Whenever a new event occurs this method is called, example – In case of audio paused we will get EVENT_PLAY_STOP_INTERRUPTED parameter in bundle.
o If MLTtsConstants.EVENT_PLAY_STOP is false then whole audio is played without issue.
o If MLTtsConstants.EVENT_PLAY_STOP is true then there is some interruption.
Step 5: Object Initialization
mlConfigs = MLTtsConfig()
.setLanguage(MLTtsConstants.TTS_EN_US)
.setPerson(MLTtsConstants.TTS_SPEAKER_FEMALE_EN)
.setSpeed(1.0f)
.setVolume(1.0f)
mlTtsEngine = MLTtsEngine(mlConfigs)
mlTtsEngine.setTtsCallback(callback)
Let us discuss this in detail.
There are 2 ways by which we can create TTS Engine.
We will be using custom TTSEnigne by MLTtsConfig object.
· Language set to English by MLTtsConstants.TTS_EN_US
o You can set language by MLTtsConstants.TTS_ZH_HANS for Chinese.
· Set person voice by MLTtsConstants.TTS_SPEAKER_FEMALE_EN
o English Male – MLTtsConstants .TTS_SPEAKER_MALE_EN
o Chinese Female – MLTtsConstants .TTS_SPEAKER_FEMALE_ZH
o Chinese Male – MLTtsConstants .TTS_SPEAKER_MALE_ZH
· Set the speech speed. Range: 0.2–1.8. 1.0 indicates 1x speed.
· Set the volume. Range: 0.2–1.8. 1.0 indicates 1x volume.
· Create the object of MLTtsEngine and provide above MLTtsConfig object.
· Set the above created callback object into MLTtsEngine
Step 6: Add the below method in your activity and call it on click of a button
private fun startTtsService() {
val id = mlTtsEngine.speak(sourceText,MLTtsEngine.QUEUE_APPEND)
}
Let us discuss this in detail.
sourceText is the text entered by user.
· MLTtsEngine.QUEUE_APPENDED is used when we want queue system. Once first operation of TTS will complete then next will start.
· In case you want a functionality where you want to only process current operation then use MLTtsEngine. QUEUE_FLUSH
· In onPause() you can stop the MLTtsEngine by
override fun onPause() {
super.onPause()
mlTtsEngine.stop()
}
In onDestroy() you can release the resources occupied by MLTtsEngine.
override fun onDestroy() {
super.onDestroy()
mlTtsEngine.shutdown()
}
FAQ
Q: Is TTS only available on huawei devices?
A: Yes.
Q: Do you need internet access in order to use TTS service?
A: Yes, this is a cloud based service hence internet is required.
Conclusion
We have merely scratched the surface. The text-to-speech function provided by HUAWEI ML Kit is also applicable to the following scenarios: News reading, audio novels, stock information broadcast, voice navigation, and video dubbing.
Above are some areas which needs TTS as a main service. I hope you liked this article. I would love to hear your ideas on how you can use this kit in your Applications.
Below is the Github link where you can download the source code.
Github Link: https://github.com/HMS-Core/hms-ml-demo/tree/master/TTSSampleKotlin
Overview
When I try to perform voice commands on my devices, the device will often fail to recognize what I am trying to say, because of my poor pronunciation. For example, sometimes I can't distinguish between syllables, or make the "ch" and "sh" sounds, which have led to some frustrating experiences. I've always envied people who can enunciate well, and recite tongue twisters with ease, and have dreamed of the day when that could be me. By chance, I came across the game Tongue Twister, which integrates HUAWEI ML Kit's ASR service, and has changed my life for the better. Let's take a look at how the game works.
Application Scenarios
There are five levels in Tongue Twister, and as you'd expect, each level contains a tongue twister. The key for passing each level is ML Kit's ASR service. By integrating the service, the game is able to recognize the player's voice with a high degree of accuracy. Players are thus able to pass each level when they demonstrate clear enunciation. The service has proven itself to be highly useful in certain fields, enhancing recognition capabilities for product, movie, and music searches, as well as navigation services.
Now, let's look at what the game looks like in practice.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Piqued your interest? With the ASR service, why not create a tongue twister game of your own? Here's how...
Development Procedures
1. For details about how to set the authentication information for your app, please refer to Notes on Using Cloud Authentication Information.
2. Call an API to create a speech recognizer.
Code:
MLAsrRecognizer mSpeechRecognizer = MLAsrRecognizer.createAsrRecognizer(context);
3. Create a speech recognition result listener callback.
Code:
/**
* Use the callback to implement the MLAsrListener API and methods in the API.
*/
protected class SpeechRecognitionListener implements MLAsrListener {
@Override
public void onStartListening() {
// The recorder starts to receive speech.
}
@Override
public void onStartingOfSpeech() {
// The user starts to speak, that is, the speech recognizer detects that the user starts to speak.
}
@Override
public void onVoiceDataReceived(byte[] data, float energy, Bundle bundle) {
// Return the original PCM stream and audio power to the user.
}
@Override
public void onRecognizingResults(Bundle partialResults) {
// Receive the recognized text from MLAsrRecognizer.
}
@Override
public void onResults(Bundle results) {
// Text data of ASR.
}
}
@Override
public void onError(int error, String errorMessage) {
// If you don't add this, there will be no response after you cut the network
}
@Override
public void onState(int state, Bundle params) {
// Notify the app status change.
}
}
4. Bind the new result listener callback to the speech recognizer.
Code:
mSpeechRecognizer.setAsrListener(new SpeechRecognitionListener());
5. Set the recognition parameters and initiate speech recognition.
Code:
// Set parameters and start the audio device.
Intent mSpeechRecognizerIntent = new Intent(MLAsrConstants.ACTION_HMS_ASR_SPEECH);
mSpeechRecognizerIntent
// Set the language that can be recognized to English. If this parameter is not set,
// English is recognized by default. Example: "zh-CN": Chinese;"en-US": English;"fr-FR": French;"es-ES": Spanish;"de-DE": German;"it-IT": Italian.
.putExtra(MLAsrConstants.LANGUAGE, language)
// Set to return the recognition result along with the speech. If you ignore the setting, this mode is used by default. Options are as follows:
// MLAsrConstants.FEATURE_WORDFLUX: Recognizes and returns texts through onRecognizingResults.
// MLAsrConstants.FEATURE_ALLINONE: After the recognition is complete, texts are returned through onResults.
.putExtra(MLAsrConstants.FEATURE, MLAsrConstants.FEATURE_WORDFLUX);mSpeechRecognizer.startRecognizing(mSpeechRecognizerIntent);
6. Release resources when the recognition ends.
Code:
if (mSpeechRecognizer != null) {
mSpeechRecognizer.destroy();
mSpeechRecognizer = null;
}
Maven repository address
Code:
buildscript {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
}
allprojects {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
}
}
SDK import
Code:
dependencies {
// Automatic speech recognition Long voice SDK.
implementation 'com.huawei.hms:ml-computer-voice-realtimetranscription:2.0.3.300'
// Automatic speech recognition SDK.
implementation 'com.huawei.hms:ml-computer-voice-asr:2.0.3.300'
// Automatic speech recognition plugin.
implementation 'com.huawei.hms:ml-computer-voice-asr-plugin:2.0.3.300'
}
Manifest files
Code:
<manifest
...
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value="ocr />
...
</manifest>
Permission
Code:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Dynamic permission application
Code:
private void requestCameraPermission() {
final String[] permissions = new String[]{Manifest.permission.RECORD_AUDIO};
if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.RECORD_AUDIO)) { ActivityCompat.requestPermissions(this,
permissions,
TongueTwisterActivity.AUDIO_CODE);
return;
}
}
Summary
In addition to game applications, ML Kit's ASR service also takes effect in other scenarios, such as in shopping apps. The service is able to recognize a spoken product name or feature, and convert it into text to search for the product. For music apps, the service can likewise, recognize song and artist names. For navigation as well, the driver will naturally prefer to speak a destination rather than type it, and have it converted into text using ASR, to enjoy an optimally safe driving experience.
Learn More
For more information, please visit HUAWEI Developers.
For detailed instructions, please visit Development Guide.
You can join the HMS Core developer discussion by going to Reddit.
You can download the demo and sample code on GitHub.
To solve integration problems, please go to Stack Overflow.
Text to speech (TTS) is highly sought after by audio/video editors, thanks to its ability to automatically turn text into naturally sounding speech, as a low cost alternative to human dubbing. It can be used on all kinds of video, regardless of whether the video is long or short.
I recently stumbled upon the AI dubbing capability of HMS Core Audio Editor Kit, which does just that. It is able to turn input text into speech with just a tap, and comes loaded with a selection of smooth, naturally-sounding male and female timbres.
This is ideal for developing apps that involve e-books, creating audio content, and editing audio/video. Below describes how I integrated this capability.
Making PreparationsComplete all necessary preparations by following the official guide.
Configuring the Project1. Set the app authentication information
The information can be set via an API key or access token (recommended).
Use setAccessToken to set an access token during app initialization.
Java:
HAEApplication.getInstance().setAccessToken("your access token");
Or, use setApiKey to set an API key during app initialization. The API key needs to be set only once.
Java:
HAEApplication.getInstance().setApiKey("your ApiKey");
2. Initialize the runtime environment
Initialize HuaweiAudioEditor, and create a timeline and necessary lanes.
Java:
// Create a HuaweiAudioEditor instance.
HuaweiAudioEditor mEditor = HuaweiAudioEditor.create(mContext);
// Initialize the runtime environment of HuaweiAudioEditor.
mEditor.initEnvironment();
// Create a timeline.
HAETimeLine mTimeLine = mEditor.getTimeLine();
// Create a lane.
HAEAudioLane audioLane = mTimeLine.appendAudioLane();
Import audio.
Java:
// Add an audio asset to the end of the lane.
HAEAudioAsset audioAsset = audioLane.appendAudioAsset("/sdcard/download/test.mp3", mTimeLine.getCurrentTime());
3. Integrate AI dubbing.
Call HAEAiDubbingEngine to implement AI dubbing.
Java:
// Configure the AI dubbing engine.
HAEAiDubbingConfig haeAiDubbingConfig = new HAEAiDubbingConfig()
// Set the volume.
.setVolume(volumeVal)
// Set the speech speed.
.setSpeed(speedVal)
// Set the speaker.
.setType(defaultSpeakerType);
// Create a callback for an AI dubbing task.
HAEAiDubbingCallback callback = new HAEAiDubbingCallback() {
@Override
public void onError(String taskId, HAEAiDubbingError err) {
// Callback when an error occurs.
}
@Override
public void onWarn(String taskId, HAEAiDubbingWarn warn) {}
@Override
public void onRangeStart(String taskId, int start, int end) {}
@Override
public void onAudioAvailable(String taskId, HAEAiDubbingAudioInfo haeAiDubbingAudioFragment, int i, Pair<Integer, Integer> pair, Bundle bundle) {
// Start receiving and then saving the file.
}
@Override
public void onEvent(String taskId, int eventID, Bundle bundle) {
// Synthesis is complete.
if (eventID == HAEAiDubbingConstants.EVENT_SYNTHESIS_COMPLETE) {
// The AI dubbing task has been complete. That is, the synthesized audio data is completely processed.
}
}
@Override
public void onSpeakerUpdate(List<HAEAiDubbingSpeaker> speakerList, List<String> lanList,
List<String> lanDescList) { }
};
// AI dubbing engine.
HAEAiDubbingEngine mHAEAiDubbingEngine = new HAEAiDubbingEngine(haeAiDubbingConfig);
// Set the listener for the playback process of an AI dubbing task.
mHAEAiDubbingEngine.setAiDubbingCallback(callback);
// Convert text to speech and play the speech. In the method, text indicates the text to be converted to speech, and mode indicates the mode for playing the converted audio.
String taskId = mHAEAiDubbingEngine.speak(text, mode);
// Pause playback.
mHAEAiDubbingEngine.pause();
// Resume playback.
mHAEAiDubbingEngine.resume();
// Stop AI dubbing.
mHAEAiDubbingEngine.stop();
ResultIn the demo below, I successfully implement the AI dubbing function in app. Now, I can converts text into emotionally expressive speech, with default and custom timbres.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To learn more, please visit:
>> Audio Editor Kit official website
>> Audio Editor Kit Development Guide
>> Reddit to join developer discussions
>> GitHub to download the sample code
>> Stack Overflow to solve integration problems
Follow our official account for the latest HMS Core-related news and updates.
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.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I don't want to brag, but I myself still find this function amazing. Let's move on to how it's developed.
Making PreparationsEnsure you have completed these steps first.
Configuring the ProjectSet 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.
Java:
HAEApplication.getInstance().setAccessToken("your access token");
Or, use setApiKey to set an API key during app initialization. This only needs to be set once.
Code:
HAEApplication.getInstance().setApiKey("your ApiKey");
Calling the File APICall 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 CapabilityCall 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.
ReferencesVoice Changer
BackgroundIt'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.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Development ProcessMaking PreparationsComplete these prerequisites.
Configuring the Project1. 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.
Code:
HAEApplication.getInstance().setAccessToken("your access token");
Or, call setApiKey to set an API key during app initialization. This needs to be set only once.
Code:
HAEApplication.getInstance().setApiKey("your ApiKey");
2. Call the file API for the noise reduction capability. Before this, the callback for the file API must have been created.
Code:
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.
}
};
3. Call applyAudioFile for noise reduction.
Code:
// Reduce noise.
HAENoiseReductionFile haeNoiseReductionFile = new HAENoiseReductionFile();
// API calling.
haeNoiseReductionFile.applyAudioFile(inAudioPath, outAudioDir, outAudioName, callBack);
// Cancel the noise reduction task.
haeNoiseReductionFile.cancel();
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.
ReferencesTypes of Noise
How to Implement Noise Reduction?