简介
本文档提供关于实时文字翻译的相关 API 概览以及 SDK 示例代码。
API | 操作描述 |
实时文字翻译 |
功能说明
腾讯云数据万象通过 AutoTranslationBlock 接口对文字块进行翻译,请求时需要携带签名。
示例代码
from qcloud_cos import AIRecognitionClientfrom qcloud_cos import CosConfig# 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capisecret_id = os.environ["SECRETID"]# 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capisecret_key = os.environ["SECRETKEY"]# 替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucketregion = 'ap-chongqing'# COS 支持的所有 region 列表参见 https://www.qcloud.com/document/product/436/6224# 如果使用永久密钥不需要填入 token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见 https://cloud.tencent.com/document/product/436/14048token = Noneconfig = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token)client = AIRecognitionClient(config)bucket_name = 'test-1250000000'def cos_auto_translation_block():# 实时文字翻译response, data = client.cos_auto_translation_block(Bucket=bucket_name, InputText="测试", SourceLang="zh", TargetLang="en", TextDomain="general", TextStyle="sentence")print(response)print(data)return response, data
参数说明
调用 cos_auto_translation_block 函数,具体请求参数如下:
参数名称 | 参数描述 | 类型 | 是否必填 |
Bucket | 存储桶名称 | String | 是 |
InputText | 待翻译的文本 | String | 是 |
SourceLang | 输入语言,如 "zh" | String | 是 |
TargetLang | 输出语言,如 "en" | String | 是 |
TextDomain | 文本所属业务领域,如: "ecommerce", 缺省值为 general | String | 否 |
TextStyle | 文本类型,如: "title", 缺省值为 sentence | String | 否 |
返回结果说明
response 为响应头,data 为实时文字翻译结果,数据类型都为 dict。
response内容
响应体data
响应体具体数据内容如下:
参数名称 | 参数描述 | 类型 |
TranslationResult | 翻译结果 | String |