语音合成

最近更新时间:2024-05-17 16:46:52

我的收藏

简介

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

SDK API 参考

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

提交任务

功能说明

提交一个语音合成任务。
说明:
COS iOS SDK 版本需要大于等于 v6.2.9。

示例代码

Objective-C
QCloudPostVoiceSynthesisRequest * request = [QCloudPostVoiceSynthesisRequest new];
request.bucket = @"sample-1250000000";
request.regionName = @"COS_REGIONNAME";
request.input = [QCloudPostVoiceSynthesis new];
// 创建任务的 Tag:Tts;是否必传:是
request.input.Tag = @"";
// 操作规则;是否必传:是
request.input.Operation = [QCloudPostVoiceSynthesisOperation new];
// 语音合成参数;是否必传:否
request.input.Operation.TtsTpl = [QCloudPostVoiceSynthesisTtsTpl new];
// 语音合成任务参数;是否必传:是
request.input.Operation.TtsConfig = [QCloudPostVoiceSynthesisTtsConfig new];
// 输入类型,Url/Text;是否必传:是
request.input.Operation.TtsConfig.InputType = @"";
// 当 InputType 为 Url 时, 必须是合法的 COS 地址,文件必须是utf-8编码,且大小不超过 10M。如果合成方式为同步处理,则文件内容不超过 300 个 utf-8 字符;如果合成方式为异步处理,则文件内容不超过 10000 个 utf-8 字符。当 InputType 为 Text 时, 输入必须是 utf-8 字符, 且不超过 300 个字符。;是否必传:是
request.input.Operation.TtsConfig.Input = @"";
// 结果输出配置;是否必传:是
request.input.Operation.Output = [QCloudPostVoiceSynthesisOutput new];
// 存储桶的地域;是否必传:是
request.input.Operation.Output.Region = @"";
// 存储结果的存储桶;是否必传:是
request.input.Operation.Output.Bucket = @"";
// 结果文件名;是否必传:是
request.input.Operation.Output.Object = @"";
// 任务回调TDMQ配置,当 CallBackType 为 TDMQ 时必填。详情见 CallBackMqConfig;是否必传:否
request.input.CallBackMqConfig = [QCloudCallBackMqConfig new];
// 消息队列所属园区,目前支持园区 sh(上海)、bj(北京)、gz(广州)、cd(成都)、hk(中国香港);是否必传:是
request.input.CallBackMqConfig.MqRegion = @"";
// 消息队列使用模式,默认 Queue :主题订阅:Topic队列服务: Queue;是否必传:是
request.input.CallBackMqConfig.MqMode = @"";
// TDMQ 主题名称;是否必传:是
request.input.CallBackMqConfig.MqName = @"";

[request setFinishBlock:^(QCloudPostVoiceSynthesisResponse * outputObject, NSError *error) {
// result:QCloudPostVoiceSynthesisResponse 包含所有的响应;
// 具体查看代码注释或api文档:https://cloud.tencent.com/document/product/460/84797
// outputObject返回JobId,使用QCloudGetMediaJobRequest 查询结果
}];
[[QCloudCOSXMLService defaultCOSXML] PostVoiceSynthesis:request];

注意:
更多完整示例,请前往 GitHub 查看。
Swift
let request : QCloudPostVoiceSynthesisRequest = QCloudPostVoiceSynthesisRequest();
request.bucket = "sample-1250000000";
request.regionName = "COS_REGIONNAME";
let postVoiceSynthesis : QCloudPostVoiceSynthesis = QCloudPostVoiceSynthesis();
// 创建任务的 Tag:Tts;是否必传:是
request.input.tag = "";
// 操作规则;是否必传:是
let operation : QCloudPostVoiceSynthesisOperation = QCloudPostVoiceSynthesisOperation();
// 语音合成参数;是否必传:否
let ttsTpl : QCloudPostVoiceSynthesisTtsTpl = QCloudPostVoiceSynthesisTtsTpl();
// 语音合成任务参数;是否必传:是
let ttsConfig : QCloudPostVoiceSynthesisTtsConfig = QCloudPostVoiceSynthesisTtsConfig();
// 输入类型,Url/Text;是否必传:是
request.input.operation.ttsConfig.inputType = "";
// 当 InputType 为 Url 时, 必须是合法的 COS 地址,文件必须是utf-8编码,且大小不超过 10M。如果合成方式为同步处理,则文件内容不超过 300 个 utf-8 字符;如果合成方式为异步处理,则文件内容不超过 10000 个 utf-8 字符。当 InputType 为 Text 时, 输入必须是 utf-8 字符, 且不超过 300 个字符。;是否必传:是
request.input.operation.ttsConfig.input = "";
// 结果输出配置;是否必传:是
let output : QCloudPostVoiceSynthesisOutput = QCloudPostVoiceSynthesisOutput();
// 存储桶的地域;是否必传:是
request.input.operation.output.region = "";
// 存储结果的存储桶;是否必传:是
request.input.operation.output.bucket = "";
// 结果文件名;是否必传:是
request.input.operation.output.object = "";
request.finishBlock = { result, error in
// result:QCloudPostVoiceSynthesisResponse 包含所有的响应;
// 具体查看代码注释或api文档:https://cloud.tencent.com/document/product/460/84797
};
QCloudCOSXMLService.defaultCOSXML().postVoiceSynthesis(request);

注意:
更多完整示例,请前往 GitHub 查看。