您可以通过智能文档翻译功能,将文本翻译为中文、英文等多种语言。通过人工智能技术,可以更高效、精准、便捷地进行多种语言的翻译。
注意事项
文档智能翻译功能仅支持同步处理(x-oss-process处理方式)。
该接口需采用POST方式请求。
使用智能文档翻译前,需要先绑定IMM Project。关于控制台和API如何绑定,请参见快速入门和AttachOSSBucket。
不支持匿名访问。
必须拥有IMM处理所需的相关权限。更多信息,请参见权限。
参数说明
操作名称:doc/translate
具体参数如下表所示。
参数 | 类型 | 是否必须 | 描述 |
language | string | 是 | 需要翻译成的目标语言。取值:
|
content | string | 是 | 需要翻译的文档内容,需经过URL安全的Base64编码。 说明
|
format | string | 否 | 指定返回数据的方式。取值:
|
返回参数如下表所示:
参数 | 类型 | 描述 |
RequestId | string | 当次请求的Request ID。 |
Output | struct | 输出的结果内容。 子节点:Text, FinishReason |
Text | string | 本次请求的处理得到的结果内容。 父节点:Output |
FinishReason | string | 表明当前生成结果的现状。取值:
父节点:Output |
使用REST API
使用普通模式进行文档智能翻译
处理方式
待处理文件:example.doc
待翻译文本:“四大名著,即四大小说名著,是指《三国演义》、《西游记》、《水浒传》、《红楼梦》4部中国古典章回小说。”
翻译目标语言:en_US
返回结果方式:json
处理示例
POST /demo.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS qn6q**************:77Dv****************
x-oss-process=doc/translate,language_en_US,content_5Zub5aSn5ZCN6JGX77yM5Y2z5Zub5aSn5bCP6K-05ZCN6JGX77yM5piv5oyH44CK5LiJ5Zu95ryU5LmJ44CL44CB44CK6KW_5ri46K6w44CL44CB44CK5rC05rWS5Lyg44CL44CB44CK57qi5qW85qKm44CLNOmDqOS4reWbveWPpOWFuOeroOWbnuWwj-ivtOOAgg==
返回示例
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:09:00 GMT
Content-Type: application/json;charset=UTF-8
Connection: close
Vary: Accept-Encoding
x-oss-request-id: 64D4C54A88339E30320E5E2E
x-oss-server-time: 2010
Content-Encoding: gzip
{
"RequestId":"6597C1C04479D830303AF61D",
"Output":{
"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese episodic novels: \"Romance of the Three Kingdoms,\" \"Journey to the West,\" \"Water Margin,\" and \"Dream of the Red Chamber.\"",
"FinishReason":"stop"
}
}
使用SSE进行文档智能翻译
处理方式
待处理文件:example.doc
待翻译文本:“四大名著,即四大小说名著,是指《三国演义》、《西游记》、《水浒传》、《红楼梦》4部中国古典章回小说。”
翻译目标语言:en_US
返回结果方式:event-stream
处理示例
POST /demo.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS qn6q**************:77Dv****************
x-oss-process=doc/translate,language_en_US,format_event-stream,content_5Zub5aSn5ZCN6JGX77yM5Y2z5Zub5aSn5bCP6K-05ZCN6JGX77yM5piv5oyH44CK5LiJ5Zu95ryU5LmJ44CL44CB44CK6KW_5ri46K6w44CL44CB44CK5rC05rWS5Lyg44CL44CB44CK57qi5qW85qKm44CLNOmDqOS4reWbveWPpOWFuOeroOWbnuWwj-ivtOOAgg==
返回示例
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:20:11 GMT
Content-Type: text/event-stream;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
x-oss-request-id: 64D4C7EA88339E30351A6A2E
x-oss-server-time: 587
id: 0
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The","FinishReason":"null"}}
id: 1
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four","FinishReason":"null"}}
id: 2
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great","FinishReason":"null"}}
id: 3
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also","FinishReason":"null"}}
id: 4
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese","FinishReason":"null"}}
id: 5
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese","FinishReason":"null"}}
id: 6
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese episodic novels: \"Romance of","FinishReason":"null"}}
id: 7
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese episodic novels: \"Romance of the Three Kingdoms,\" \"Journey","FinishReason":"null"}}
id: 8
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese episodic novels: \"Romance of the Three Kingdoms,\" \"Journey to the West,\" \"Water Margin,\"","FinishReason":"null"}}
id: 9
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese episodic novels: \"Romance of the Three Kingdoms,\" \"Journey to the West,\" \"Water Margin,\" and \"Dream of the Red Chamber.\"","FinishReason":"null"}}
id: 10
event: Result
data: {"RequestId":"6597C2174479D83837AE0C1E","Output":{"Text":"The Four Great Classical Novels, also known as the Four Masterpieces of Chinese Fiction, refer to the four traditional Chinese episodic novels: \"Romance of the Three Kingdoms,\" \"Journey to the West,\" \"Water Margin,\" and \"Dream of the Red Chamber.\"","FinishReason":"stop"}}
使用SDK
智能文档翻译仅支持同步处理,SDK使用方法请参见使用SDK。