What should I do if I want to get the accompaniment of a song but can't find the resource? It's okay, we can figure it out ourselves. The audio editing service provides the function of sound source separation, helping developers to build the function of separating vocals and accompaniment in the application.
At present, the sound source separation function has opened up a variety of ways to separate vocals from accompaniment, instruments, etc. It can analyze and extract the vocals and various musical instrument elements in the instrument in real time to independent audio tracks, so as to satisfy the creator's need for accompaniment production. , tape, music creation and other scenarios of application needs. Moreover, without the need for professional audio processing software, as long as the Huawei audio editing service is integrated, audio editing can be easily completed on the mobile terminal, allowing creators to feel the charm of sound more conveniently.
Demo
Let's practice how to access Huawei's audio editing service to achieve the effect of sound source separation.
development practice
1. Development preparation
For detailed preparation steps, please refer to the official website of Huawei Developer Alliance :
2. Edit project integration
2.1 Set the authentication information of the application
Developers need to set application authentication information through api_key or Access Token.
- (Recommended) Set the Access Token through the setAccessToken method, and initialize the settings when the application starts
HAEApplication.getInstance().setAccessToken("your access token");
- The api_key is set by the setApiKey method, which can be initialized and set once when the application starts, and there is no need to set it multiple times.
HAEApplication.getInstance().setApiKey("your ApiKey");
2.2 Initialize the environment
Initialize the audio editing management class, create the timeline, and the required swimlanes.
// 创建音频编辑管理类
HuaweiAudioEditor mEditor = HuaweiAudioEditor.create(mContext);
// 初始化Editor的运行环境
mEditor.initEnvironment();
// 创建时间线
HAETimeLine mTimeLine = mEditor.getTimeLine();
// 创建泳道
HAEAudioLane audioLane = mTimeLine.appendAudioLane();
导入音乐。
// 泳道末尾添加音频资源
HAEAudioAsset audioAsset = audioLane.appendAudioAsset("/sdcard/download/test.mp3", mTimeLine.getCurrentTime());
3. Audio source separation function integration
调用getInstruments和startSeparationTasks接口进行音源分离。
// 音源分离
// SeparationCloudCallBack:获取类型的回调
HAEAudioSeparationFile haeAudioSeparationFile = new HAEAudioSeparationFile();
haeAudioSeparationFile.getInstruments(new SeparationCloudCallBack<List<SeparationBean>>() {
@Override
public void onFinish(List<SeparationBean> response) {
// 返回的数据
}
@Override
public void onError(int errorCode) {
// 失败返回
}
});
// 设置要提取的伴奏参数
haeAudioSeparationFile.setInstruments(伴奏id集合);
// 开始分离
haeAudioSeparationFile.startSeparationTasks(inAudioPath, outAudioDir, outAudioName, new AudioSeparationCallBack() {
@Override
public void onResult(SeparationBean separationBean) { }
@Override
public void onFinish(List<SeparationBean> separationBeans) {}
@Override
public void onFail(int errorCode) {}
@Override
public void onCancel() {}
});
// 取消分离任务
haeAudioSeparationFile.cancel();
In addition to the audio source separation function, Huawei Audio Editing Service also provides developers with a one-stop audio editing service, covering dozens of professional capabilities required for audio/music processing. Access to powerful audio processing capabilities can greatly help customers improve audio/music processing efficiency.
For more details about Huawei Audio Editing Service, please refer to:
Service official website: https://developer.huawei.com/consumer/cn/hms/huawei-audio-editor/?ha_source=hms1
Get guidance documents: https://developer.huawei.com/consumer/cn/doc/development/Media-Guides/client-dev-0000001107465102?ha_source=hms1
Learn more details>>
Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee
Follow us to know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。