Super simple integration! Teach you to realize audio editing ability

Time:2021-10-22

Nowadays, short video is popular, BGM is everywhere, and users want to add personalized audio wherever they can show. As a developer, we need to constantly explore and cater to users’ behavior preferences. Audio editing function has become a necessity for users in editing personal information, content creation, life sharing and other scenarios.

Huawei audio editor kit is a collection of audio processing capabilities provided by Huawei for global developers. It has functions such as basic audio editing, audio extraction, adding audio effects, streaming dual microphone noise reduction, and supports a variety of sound changing styles and four format conversion. It can be widely used in music creation, podcasts, games and other scenes. Let’s see how to integrate Huawei audio editor Kit!

Demo effect

Development preparation

1. Configure Maven warehouse address in project level build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        //Configure the Maven warehouse address of the HMS core SDK.
        maven {url 'https://developer.huawei.com/repo/'}
    }
    dependencies {
        ...
        //Add AGCP plug-in configuration.
        classpath 'com.huawei.agconnect:agcp:1.4.2.300'
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        //Configure the Maven warehouse address of the HMS core SDK.
        maven {url 'https://developer.huawei.com/repo/'}
    }
}

2. File header add configuration

apply plugin: 'com.huawei.agconnect'

3. SDK dependencies are configured 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

Code development

1. Create an activity interface customized by your application to select audio and return the audio file path to the audio editing SDK in the following way.

//Return the audio file path list to the audio editing page
private void sendAudioToSdk() {
    //Get the audio file path filepath
    String filePath = "/sdcard/AudioEdit/audio/music.aac";
    ArrayList audioList = new ArrayList<>();
    audioList.add(filePath);
    //Return the audio file path to the audio editing page
    Intent intent = new Intent();
    //Use haeconstant.audio provided by SDK_ PATH_ LIST
    intent.putExtra(HAEConstant.AUDIO_PATH_LIST, audioList);
    //Use haeconstant.result provided by SDK_ Code is the result code
    this.setResult(HAEConstant.RESULT_CODE, intent);
    finish();
}

2. When importing audio in the UI interface, the SDK will send an intent with an action value of com.huawei.hms.audioeditor.chooseaudio to jump to the activity. Therefore, the registration form in the activity “androidmanifest. XML” is as follows.

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

HAEUIManager.getInstance().launchEditorActivity(this);

4. Audio format conversion.
Call the transformaudiousedefaultpath interface to convert the audio format, and export the converted audio file to the default path.

//Audio format converter
HAEAudioExpansion.getInstance().transformAudioUseDefaultPath(context,inAudioPath, audioFormat, new OnTransformCallBack() {
    //Progress callback (0-100)
    @Override
    public void onProgress(int progress) {
    }
    //Conversion failed
    @Override
    public void onFail(int errorCode) {
    }
    //Conversion succeeded
    @Override
    public void onSuccess(String outPutPath) {
    }
    //Cancel conversion
    @Override
    public void onCancel() {
    }
    });
//Cancel conversion任务接口
HAEAudioExpansion.getInstance().cancelTransformAudio();

Call the transformaudio interface for audio format conversion, and export the converted audio file to the target path.

//Audio format converter
HAEAudioExpansion.getInstance().transformAudio(context,inAudioPath, outAudioPath, new OnTransformCallBack(){
    //Progress callback (0-100)
    @Override
    public void onProgress(int progress) {
    }
    //Conversion failed
    @Override
    public void onFail(int errorCode) {
    }
    //Conversion succeeded
    @Override
    public void onSuccess(String outPutPath) {
    }
    //Cancel conversion
    @Override
    public void onCancel() {
    }
    });
//Cancel conversion任务接口
HAEAudioExpansion.getInstance().cancelTransformAudio();

5. Call the extractaudio interface for audio extraction, extract audio files from the video and export them to the specified directory.

//The folder path of audio saved extracted by outaudiodir. It is not required
//Outaudioname: the extracted audio name, without suffix, is not required
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

visitHuawei audio editing service official website

obtainHuawei audio editing service development guidance document

Huawei audio editing service open source warehouse address:GitHubGitee

Huawei HMS core official forum

Solve integration problemsStack Overflow

Click the attention on the right side of the avatar in the upper right corner to understand it for the first timeHMS CoreLatest technology~

Recommended Today

SQL statement of three-level linkage of provinces, cities and counties

The first is the table creation statement Copy codeThe code is as follows: CREATE TABLE `t_address_province` ( `id` INT AUTO_ Increment primary key comment ‘primary key’,`Code ` char (6) not null comment ‘province code’,`Name ` varchar (40) not null comment ‘province name’)Engine = InnoDB default charset = utf8 comment = ‘province information table’; CREATE TABLE […]