设为首页 加入收藏

TOP

AI赋能音乐创作,人人都是音视频创作者(六)
2023-07-23 13:31:59 】 浏览:171
Tags:能音乐 都是音
X-Country-Code", countryCode); // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6" postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId); // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx" postMethod.setRequestHeader("certFingerprint", certFingerprint); // 设置动态获取的AccessToken(String) postMethod.setRequestHeader("Authorization","Bearer " + accessToken); // 设置请求body Map<String, Object> bodyMap = new HashMap<>(); // taskId对应的值是创建异步任务时返回的任务ID(taskId) bodyMap.put("taskId", taskId); RequestEntity requestEntity = new StringRequestEntity(JSONObject.toJSONString(bodyMap),"application/json" ,"UTF-8"); postMethod.setRequestEntity(requestEntity); HttpClient httpClient = new HttpClient(); int ret = httpClient.executeMethod(postMethod); String rpsContent = postMethod.getResponseBodyAsString(); if (ret == 200) { System.out.println(rpsContent); } else { System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent); } }

注意:

上述代码中xxxxx对应的值请根据实际情况填写,具体取值请参见查询异步任务状态

2.2.3取消异步任务

用户创建歌声合成异步任务后,可以通过调用此接口,取消指定异步任务并删除相应任务数据。

通过access_token信息和创建异步任务获取到的taskId,发送HTTPS POST取消异步任务。

示例代码(Java)如下所示:

其中requestUrl = "https://audioeditor-api-drcn.cloud.huawei.com/v1/audioeditor/gateway/ai/ttsing/async/task/cancel"。

  /**
     * 调用取消异步任务接口
     * @param taskId 创建异步任务获取的taskId
     * @throws Exception IO异常
     */
    private static void cancelAsyncTask(String taskId) throws Exception {
        
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        // taskId对应的值是创建异步任务时返回的任务ID(taskId)
        bodyMap.put("taskId", taskId);
        RequestEntity requestEntity = new StringRequestEntity(JSONObject.toJSONString(bodyMap),"application/json" ,"UTF-8");
        postMethod.setRequestEntity(requestEntity);

        HttpClient httpClient = new HttpClient();
        int ret = httpClient.executeMethod(postMethod);
        String rpsContent = postMethod.getResponseBodyAsString();
        if (ret == 200) {
            System.out.println(rpsContent);
        } else {
            System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent);
        }
    }

注意:

上述代码中xxxxx对应的值请根据实际情况填写,具体取值请参见

首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇如何优化大场景实时渲染?HMS Cor.. 下一篇安卓工程错误1

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目