简介
本文档提供关于实时文字翻译的相关 API 概览以及 SDK 示例代码。
API | 操作描述 |
腾讯云数据万象通过 AutoTranslationBlock 接口对文字块进行翻译,请求时需要携带签名。 |
实时文字翻译
腾讯云数据万象通过 AutoTranslationBlock 接口对文字块进行翻译,请求时需要携带签名。
方法原型
func (s *CIService) GetAutoTranslationBlock(ctx context.Context, opt *AutoTranslationBlockOptions) (*AutoTranslationBlockResults, *Response, error)
请求示例
// 将 examplebucket-1250000000 和 COS_REGION 修改为真实的信息bu, _ := url.Parse("https://examplebucket-1250000000.cos.COS_REGION.myqcloud.com")b := &cos.BaseURL{BucketURL: bu}c := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{SecretID: os.Getenv("SECRETID"),SecretKey: os.Getenv("SECRETKEY"),}})opt := &cos.AutoTranslationBlockOptions{InputText: "您好,很高兴认识您!",SourceLang: "zh",TargetLang: "en",}res, _, err := c.CI.GetAutoTranslationBlock(context.Background(), opt)log_status(err)fmt.Printf("%+v\\n", res.TranslationResult)
参数说明
type AutoTranslationBlockOptions struct {InputText string `url:"InputText,omitempty"`SourceLang string `url:"SourceLang,omitempty"`TargetLang string `url:"TargetLang,omitempty"`TextDomain string `url:"TextDomain,omitempty"`TextStyle string `url:"TextStyle,omitempty"`}
参数名称 | 参数描述 | 类型 | 是否必填 |
InputText | 待翻译的文本 | string | 是 |
SourceLang | 输入语言,如 "zh" | string | 是 |
TargetLang | 输出语言,如 "en" | string | 是 |
TextDomain | 文本所属业务领域,如: "ecommerce", 缺省值为 general | string | 否 |
TextStyle | 文本类型,如: "title", 缺省值为 sentence | string | 否 |
结果说明
调用 GetAutoTranslationBlock 函数,会解析 api 返回的 xml 内容到 AutoTranslationBlockResults 结构,具体返回参数可查看 实时文字翻译 文档。