最近在调研阿里云的音频拼接接口,需要将多个音频拼接在一起
流程:
1、开通zip包自动解压到某个文件夹
可参考阿里云文档:https://help.aliyun.com/zh/oss/user-guide/zip-package-decompression
2、配置IMM
https://help.aliyun.com/document_detail/478221.html?spm=a2c4g.609319.0.i1
3、写代码
https://help.aliyun.com/zh/oss/user-guide/audio-stitching?spm=5176.28426678.J_HeJR_wZokYt378dwP-lLl.1.42cb5181zTlaJO&scm=20140722.S_help@@%E6%96%87%E6%A1%A3@@2330731..ID_help@@%E6%96%87%E6%A1%A3@@2330731-RL%E9%9F%B3%E9%A2%91%E6%8B%BC%E6%8E%A5%E7%A4%BA%E4%BE%8B-LOC_llm-OR_ser-V_3-RK_rerank-P0_0
下面展示一个可以调通的例子
String styleBuilder = "audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_音频地址1,t_2000/sur,o_音频地址2,ss_4000,t_10000|sys/saveas,b_bucketName,o_targetFile/notify,topic_QXVkaW9Db252ZXJ0";
下面是官方示例
package samples;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.model.*;
public class AsyncProcessObjectSample {
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
private static String endpoint = "<endpoint, http://oss-cn-hangzhou.aliyuncs.com>";
// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// 填写Bucket名称。
private static String bucketName = "<bucketName>";
// 异步处理后保存在OSS上的文件名。
private static final String saveAsKey = "<syncSaveObjectName>";
// OSS上的文件名。
private static final String key = "<objectName>";
public static void main(String[] args) {
/*
* Constructs a client instance with your account for accessing OSS
*/
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
try {
StringBuilder styleBuilder = new StringBuilder();
// 对文件进行视频转码,转码输出媒体文件为MP4,视频流格式为H.265,分辨率为1920x1080,帧率为30 fps,视频码率为2 Mbps,音频编码格式为AAC,音频码率为100 Kbps,禁用字幕流,转码完成后保存。
styleBuilder.append("video/convert,f_mp4,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1"); // resize
styleBuilder.append("|sys/saveas,");
styleBuilder.append("o_" + BinaryUtil.toBase64String(saveAsKey.getBytes()).replaceAll("=", ""));
styleBuilder.append(",");
styleBuilder.append("b_" + BinaryUtil.toBase64String(bucketName.getBytes()).replaceAll("=", ""));
AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, key, styleBuilder.toString());
AsyncProcessObjectResult asyncProcessObject = ossClient.asyncProcessObject(request);
System.out.println(asyncProcessObject.getAsyncRequestId());
System.out.println(asyncProcessObject.getEventId());
System.out.println(asyncProcessObject.getTaskId());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message: " + oe.getMessage());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message: " + ce.getMessage());
} finally {
/*
* Do not forget to shut down the client finally to release all allocated resources.
*/
ossClient.shutdown();
}
}
}