提交一个语音合成任务

最近更新时间:2024-07-23 18:12:12

我的收藏

简介

本文档提供关于提交一个语音合成任务的相关 API 概览以及 SDK 示例代码。
API
操作描述
提交一个语音合成任务

SDK API 参考

SDK 所有接口的具体参数与方法说明,请参考 SDK API

提交任务

功能说明

提交一个语音合成任务。
注意:
COS Android SDK 版本需要大于等于 v5.9.32。

示例代码

// 存储桶名称,格式为 BucketName-APPID
String bucket = "examplebucket-1250000000";
PostVoiceSynthesisRequest request = new PostVoiceSynthesisRequest(bucket);
PostVoiceSynthesis postVoiceSynthesis = new PostVoiceSynthesis();// 提交任务请求体
request.setPostVoiceSynthesis(postVoiceSynthesis);// 设置请求
PostVoiceSynthesis.PostVoiceSynthesisOperation postVoiceSynthesisOperation = new PostVoiceSynthesis.PostVoiceSynthesisOperation();
postVoiceSynthesis.operation = postVoiceSynthesisOperation;
// 设置语音合成模板 ID;是否必传:否
postVoiceSynthesisOperation.templateId = "t1460606b9752148c4ab182f55163ba7cd";
PostVoiceSynthesis.PostVoiceSynthesisTtsConfig postVoiceSynthesisTtsConfig = new PostVoiceSynthesis.PostVoiceSynthesisTtsConfig();
postVoiceSynthesisOperation.ttsConfig = postVoiceSynthesisTtsConfig;
// 设置输入类型,Url/Text;是否必传:是
postVoiceSynthesisTtsConfig.inputType = "Text";
// 设置当 InputType 为 Url 时, 必须是合法的 COS 地址,文件必须是utf-8编码,且大小不超过 10M。如果合成方式为同步处理,则文件内容不超过 300 个 utf-8 字符;如果合成方式为异步处理,则文件内容不超过 10000 个 utf-8 字符。当 InputType 为 Text 时, 输入必须是 utf-8 字符, 且不超过 300 个字符。;是否必传:是
postVoiceSynthesisTtsConfig.input = "床前明月光,疑是地上霜";
PostVoiceSynthesis.PostVoiceSynthesisOutput postVoiceSynthesisOutput = new PostVoiceSynthesis.PostVoiceSynthesisOutput();
postVoiceSynthesisOperation.output = postVoiceSynthesisOutput;
// 设置存储桶的地域;是否必传:是
postVoiceSynthesisOutput.region = "ap-chongqing";
// 设置存储结果的存储桶;是否必传:是
postVoiceSynthesisOutput.bucket = "test-123456789";
// 设置结果文件名;是否必传:是
postVoiceSynthesisOutput.object = "demo.mp3";
// 设置透传用户信息,可打印的 ASCII 码,长度不超过1024;是否必传:否
postVoiceSynthesisOperation.userData = "This is my data.";
// 设置任务优先级,级别限制:0 、1 、2 。级别越大任务优先级越高,默认为0;是否必传:否
postVoiceSynthesisOperation.jobLevel = "0";
// 设置任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
postVoiceSynthesis.callBackFormat = "JSON";
// 设置任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
postVoiceSynthesis.callBack = "http://callback.demo.com";

ciService.postVoiceSynthesisAsync(request, new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult cosResult) {
// result 提交任务的结果
// 详细字段请查看api文档或者SDK源码
PostVoiceSynthesisResult result = (PostVoiceSynthesisResult) cosResult;

}
@Override
public void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});

说明:
更多完整示例,请前往 GitHub 查看。