阿里云音频拼接如何调用

最近在调研阿里云的音频拼接接口,需要将多个音频拼接在一起
流程:
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();
        }
    }
}
  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值