Now that short video is in the air and BGM is everywhere, users want to add audio with personal expression wherever they can show off. As a developer, it is necessary to continuously explore and cater to users’ behavioral preferences. Audio editing function has become a necessity for users in situations such as editing personal information, content creation, life sharing and so on.

Huawei Audio editing services (Audio Editor kit) is a set of huawei to developers worldwide Audio processing ability, has based edit Audio, Audio extraction, add Audio effect, current dual mic noise reduction, and other functions, and support for multiple voice and four kinds of format conversion, can be widely used in the creation of music, podcasts, games, etc. Let’s see how to integrate Huawei Audio Editor Kit!

Effect of the Demo

The development of preparation

1. Configure the Maven repository address in the project level build.gradle

BuildScript {Repositories {Google () JCenter () // Set the Maven repository location for the HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} } dependencies { ... // Add AGCP plugin configuration. Classpath 'com. Huawei. Agconnect: agcp: 1.4.2.300'}} allprojects {repositories {Google jcenter () () / / configure HMS Core The SDK's Maven repository address. maven {url 'https://developer.huawei.com/repo/'} } }

2, file header added configuration

apply plugin: 'com.huawei.agconnect'

3. Configure SDK dependencies in application-level build.gradle

dependencies{
    implementation 'com.huawei.hms:audio-editor-ui:{version}'
}

4. Apply for the following permissions in the AndroidManifest.xml file

<! Shaking -- permissions - > < USES - permission android: name = "android. Permission. VIBRATE" / > <! - the microphone permissions - > < USES - permission android: name = "android. Permission. RECORD_AUDIO" / > <! (permission) android:name="android.permission. Write_external_storage "/> <! (permission) android:name="android.permission. READ_EXternal_STORAGE "/> <! - INTERNET access - > < USES - permission android: name = "android. Permission. INTERNET" / > <! - network state authority - > < USES - permission android: name = ". Android. Permission ACCESS_NETWORK_STATE "/ >

Code development

1. Create your application’s custom Activity interface for selecting audio, and return the audio file path to the audio editing SDK as follows.

Private void sendAudioToSDK () {private void sendAudioToSDK () {private void sendAudioToSDK () {private void sendAudioToSDK () {private void sendAudioToSDK () "/sdcard/AudioEdit/audio/music.aac"; ArrayList<String> audioList = new ArrayList<>(); audioList.add(filePath); // Return the audio file path to the audio editing page. Intent = new Intent(); AUDIO_PATH_LIST intent.putExtra(Haeconstant.audio_path_list, audioList); // Use the Haeconstant.result_code provided by the SDK as the result CODE this.setResult(Haeconstant.result_code, intent); finish(); }

2, the UI interface to import audio, the SDK will send a action value of com. Huawei. HMS. Audioeditor. Chooseaudio intent to jump to the activity. Therefore, the registration form in the activity “AndroidManifest.xml” looks like this.

<activity android:name="Activity ">
<intent-filter>
<action android:name="com.huawei.hms.audioeditor.chooseaudio"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

3. Start the audio editing page, click “Add audio”, and the SDK will actively call the activity defined in 2.1. After adding the audio, you can edit the audio, add special effects, and export the edited audio.

HAEUIManager.getInstance().launchEditorActivity(this);

4, audio format conversion. Call transformAudioUseDefaultPath interface in audio format conversion, the converted audio file to the default path is deduced.

/ / audio format conversion interface HAEAudioExpansion getInstance () transformAudioUseDefaultPath (context, inAudioPath audioFormat, New OnTransformCallback () {// Override public void onProgress(int progress) {} // Override public Void onFail(int errorCode) {} public void onSuccess(String outputPath) {} // Override public void onCancel() { } }); / / cancel the transformation interface HAEAudioExpansion getInstance () cancelTransformAudio ();

Call the TransformAudio interface to convert the audio format and export the converted audio file to the target path.

/ / audio format conversion interface HAEAudioExpansion getInstance () transformAudio (context, inAudioPath outAudioPath, New OnTransformCallback (){// Override public void onProgress(int progress) {} // Override public Void onFail(int errorCode) {} public void onSuccess(String outputPath) {} // Override public void onCancel() { } }); / / cancel the transformation interface HAEAudioExpansion getInstance () cancelTransformAudio ();

5, call ExtractAudio interface for audio extraction, extractAudio files from the video export to the specified directory.

// OutAudiodir is the directory where the audio is saved, not required. // OutAudiodir is the directory where the audio is saved. The mandatory HAEAudioExpansion. GetInstance (). ExtractAudio (context, inVideoPath outAudioDir, outAudioName,new AudioExtractCallBack() { @Override public void onSuccess(String audioPath) { Log.d(TAG, "ExtractAudio onSuccess : " + audioPath); } @Override public void onProgress(int progress) { Log.d(TAG, "ExtractAudio onProgress : " + progress); } @Override public void onFail(int errCode) { Log.i(TAG, "ExtractAudio onFail : " + errCode); } @Override public void onCancel() { Log.d(TAG, "ExtractAudio onCancel."); }}); / / cancel audio extraction task interface HAEAudioExpansion. GetInstance () cancelExtractAudio ();

Learn more about it

Visit the official website of Huawei Audio Editing Service

Obtain Huawei Audio Editing Service Development Guidance Document

Address of Huawei Audio Editing Service Open Source Warehouse: Github, Gitee

Huawei HMS Core Official Forum

To solve integration problems, go to Stack Overflow

Click the attention on the upper right corner of the image to get to know the latest HMS Core technology in the first time