简介
本文档提供关于提交一个语音合成任务的相关 API 概览以及 SDK 示例代码。
API | 操作描述 |
提交一个语音合成任务。 |
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];
注意:
Swift
let request = QCloudPostVoiceSynthesisRequest()request.bucket = "sample-1250000000"request.regionName = "COS_REGIONNAME"request.input = QCloudPostVoiceSynthesis()// 创建任务的 Tag:Tts;是否必传:是request.input.tag = "Tts"// 操作规则;是否必传:是request.input.operation = QCloudPostVoiceSynthesisOperation()// 语音合成参数(模板);是否必传:否request.input.operation.ttsTpl = QCloudPostVoiceSynthesisTtsTpl()// 语音合成任务参数;是否必传:是request.input.operation.ttsConfig = 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 = ""// 结果输出配置;是否必传:是request.input.operation.output = QCloudPostVoiceSynthesisOutput()// 存储桶的地域;是否必传:是request.input.operation.output.region = ""// 存储结果的存储桶;是否必传:是request.input.operation.output.bucket = ""// 结果文件名;是否必传:是request.input.operation.output.object = ""// 任务回调 TDMQ 配置,当 CallBackType 为 TDMQ 时必填;是否必传:否request.input.callBackMqConfig = QCloudCallBackMqConfig()// 消息队列所属园区,目前支持园区 sh(上海)、bj(北京)、gz(广州)、cd(成都)、hk(中国香港);是否必传:是request.input.callBackMqConfig.mqRegion = ""// 消息队列使用模式,默认 Queue;主题订阅:Topic,队列服务:Queue;是否必传:是request.input.callBackMqConfig.mqMode = ""// TDMQ 主题名称;是否必传:是request.input.callBackMqConfig.mqName = ""request.setFinishBlock { outputObject, error in// outputObject:QCloudPostVoiceSynthesisResponse 包含所有的响应// 具体查看代码注释或 API 文档:https://cloud.tencent.com/document/product/460/84797// outputObject 返回 JobId,使用 QCloudGetMediaJobRequest 查询结果}QCloudCOSXMLService.defaultCOSXML().postVoiceSynthesis(request)
注意: