提示:当前为新版开放平台,仅支持页数计费相关显示。旧版付费模式(积分模式),请切换旧版(http://open.fanyigou.com)使用,感谢您的理解!

文档翻译

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口调用流程

1.普通文档翻译流程

  • a. 上传文档进行翻译(详见文档上传接口
  • b. 查询翻译进度(详见任务查询进度接口
  • c. 下载译文(详见文档下载接口

2.文档检测页数后提交翻译流程

  • a. 上传文档检测页数(上传文件检测页数接口
  • b. 若a未返回文档页数,则c,否则d
  • c. 查询文档检测页数(任务查询进度接口),有页数返回则d
  • d. 把上述检测出页数的文档提交翻译(检测页数文件提交翻译接口)
  • e. 查询翻译进度(任务查询进度接口
  • f. 下载译文(下载接口

接口说明

文档上传接口

接口名称:uploadTranslate

接口完整路径:https://www.fanyigou.com/TranslateApi/api/uploadTranslate

请求方式:post(file参数请以 multipart/form-data 方式的表单 POST 提交)

注意:

1.上传格式:pdf、Microsoft Office(doc、docx、dot、dotx、dotm、docm、xml、odt)、WPS Office(wps、wpt)、xls、xlsx、et、ett、ppt、pptx、dps、dpt、txt、rtf;

2.上传文件最大50M(如有更高需求请联系销售);

3. 不支持图纸、纯图片文档,加密文件请先去除密码;

4.翻译完成后按页从主账号里扣费;

5.目前普通账户支持一条翻译通道(即只能同时进行一个文件的上传翻译),(如有更高需求请联系销售);

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源语言String见语言列表
to目标语言(不支持自动检测)String见语言列表
md5源文件md5Stringmd5小写
industryId行业代码int见行业列表
transImg文档内图片翻译int0:不翻译文档内图片(默认),1:翻译文档内图片。目前支持中、英、日、韩的文档内图片翻译。(如有需要请联系销售开通)
excelMode指定excel翻译模式int0:只翻译当前打开sheet(默认),1:翻译全部sheet(页数按全部sheet字符数来计算)
bilingualControl指定翻译模式int0:译文单独为一个文档(默认),1:双语对照(原文和译文在一个文档)

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
tid翻译idString通过该id可查询翻译进度等

返回结果:

{"code": 100,"data": {"tid": 14587},"msg": "请求成功"}

文档下载接口

接口名称:downloadFile

接口完整路径:https://www.fanyigou.com/TranslateApi/api/downloadFile

接口说明:根据tid下载文档(任务完成才能下载)

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
dtype下载的文件类型(new):
2:翻译后的pdf文件,支持格式:word、pdf、img。
3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
6:转换完成文档
int
tid查询状态结果Idint上传源文件后可获取该ID

出参列表配置:

说明:1.判断Response Headers 中 detectLanguage 的值,若存在且不为空即为自动检测出的语言(可能为多种语言),仅供参考
2.判断Response Headers 中Content-Type 的值,若包含"application/octet-stream" 则可直接进行下载,否则即为以下返回值

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String

返回结果:

{"code": 312,"msg": "该翻译不存在"}

任务查询进度接口

接口名称:queryTransProgress

接口完整路径:https://www.fanyigou.com/TranslateApi/api/queryTransProgress

接口说明:提交任务完成后可调用此接口实时查询翻译、转换进度或检测页数进度

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
tid查询状态结果Id int

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
tid查询翻译idint通过该id可查询翻译进度等
title文件名String
docType文件类型String
fromLan源语言String
toLan目标语言String
detectLan检测语言String不为空即为自动检测出的主要语言,仅供参考
percent进度String
pageCount文件页数int
status状态int详见文件状态码,314为翻译完成,330为检测页数完成
msg状态说明String
createTime创建时间String
updateTime更新时间String

返回结果:

                                
                {
                    "code": 100,
                    "data": {
                        "createTime": "2018-03-27 16:57:51",
                        "docType": "docx",
                        "fromLan": "",
                        "msg": "正在翻译",
                        "pageCount": 1,
                        "percent": "99.00",
                        "status": 313,
                        "tid": 14587,
                        "title": "测试",
                        "toLan": "中文",
                        "updateTime": "2018-03-27 16:58:00"
                    },
                    "msg": "请求成功"
                }
                            

上传文件检测页数

接口名称:detectDocPage

接口完整路径:https://www.fanyigou.com/TranslateApi/api/detectDocPage

接口说明:用户调用接口进行 源文件上传,上传完成后可调用查询进度接口查询页数。注意:

1.上传格式:pdf、Microsoft Office(doc、docx、dot、dotx、dotm、docm、xml、odt)、WPS Office(wps、wpt)、xls、xlsx、et、ett、ppt、pptx、dps、dpt、txt、rtf

2.上传文件最大50M(如有更高需求请联系销售)

3.不支持图纸、纯图片文档,加密文件请先去除密码

4.该功能需联系客服开通

调用说明:请求方式:post, file参数请以 multipart/form-data 方式的表单 POST 提交

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
md5源文件md5Stringmd5小写
excelMode指定excel翻译模式int0:只翻译当前打开sheet(默认),1:翻译全部sheet(页数按全部sheet字符数来计算)

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
tid翻译idint通过该id可查询任务进度等
page检测到的页数int检测页数(大于0即检测成功,等于0则转入后台检测,需要调用进度接口查询页数,返回页数大于0即为成功)

返回结果:

{"code": 100,"data": {"tid": 14587,"page",20},"msg": "请求成功"}

检测页数文件提交翻译

接口名称:submitForDetectDoc

接口完整路径:https://www.fanyigou.com/TranslateApi/api/submitForDetectDoc

接口说明:用户调用检测页数接口的文档提交翻译,注意:

同一个tid提交一次翻译即可。

调用说明:请求方式:get,post

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
tid检测文档页数接口返回的tidint
from源语言String见语言列表
to目标语言(不支持自动检测)String见语言列表
industryId行业代码int见行业列表
transImg文档内图片翻译int0:不翻译文档内图片(默认),1:翻译文档内图片。目前支持中、英、日、韩的文档内图片翻译。(如有需要请联系销售开通)
bilingualControl指定翻译模式int0:译文单独为一个文档(默认),1:双语对照(原文和译文在一个文档)

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

返回结果:

{"code": 100,"msg": "请求成功"}

文字翻译

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口说明

文字翻译接口

接口名称:trans

接口完整路径:https://www.fanyigou.com/TranslateApi/api/trans

接口说明:

1.待翻译文本字符长度不能超过2000;

2.语言方向:英、日、俄、韩、德、法、意 到中;中、日、俄、韩、德、法、意 到英

调用说明:请求方式:post

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源语言String
to目标语言String
text待翻译文本,需UTF-8编码String

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
msg状态说明String
transResult翻译译文String
status任务状态int

返回结果:

{"code":0,"data":{"msg":"翻译成功","transResult":"Test text translation time ","status":314},"msg":"请求成功"}

格式转换

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口调用流程

1.上传文档进行转换(详见文档转换接口

2.查询转换进度(详见任务查询进度接口

3.下载转换文档(详见下载接口

接口说明

文档转换接口

接口名称:convert

接口完整路径:https://www.fanyigou.com/TranslateApi/api/convert

接口说明:用户调用接口进行 源文件上传,上传完成后会自动进行转换,通过tid可以查询转换的进度等数据。注意:

1.上传格式:pdf、doc、docx、ppt、pptx、xls、xlsx、hwp、caj、ofd

2.上传文件最大50M (如有更高需求请联系销售)

3.加密文件请先去除密码

4.转换完成后按页从主账号里扣费

调用说明:请求方式:post, file参数请以 multipart/form-data 方式的表单 POST 提交

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源文件的语言(扫描件需设置语言)String
conversionFormat转换的目标格式(目前支持pdf到其它格式的转换(excel,ppt,word,ofd),及其它格式(excel,ppt,word,hwp,caj,ofd)到pdf的转换) -1:word;-3:excel;-6:pptx,-8:pdf,-9:ofd。int
md5源文件md5String

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
tid任务idString通过该id可查询进度等

返回结果:

{"code": 100,"data": {"tid": 14587},"msg": "请求成功"}

任务查询进度接口

接口名称:queryTransProgress

接口完整路径:https://www.fanyigou.com/TranslateApi/api/queryTransProgress

接口说明:提交任务完成后可调用此接口实时查询翻译、转换进度或检测页数进度

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
tid查询状态结果Id int

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
tid查询转换idint通过该id可查询进度等
title文件名String
docType文件类型String
fromLan源语言String
toLan目标语言String
detectLan检测语言String不为空即为自动检测出的主要语言,仅供参考
percent进度String
pageCount文件页数int
status状态int详见文件状态码,314为转换完成
msg状态说明String
createTime创建时间String
updateTime更新时间String

返回结果:

                                
                {
                    "code": 100,
                    "data": {
                        "createTime": "2018-03-27 16:57:51",
                        "docType": "docx",
                        "fromLan": "",
                        "msg": "进行中",
                        "pageCount": 1,
                        "percent": "99.00",
                        "status": 313,
                        "tid": 14587,
                        "title": "测试",
                        "toLan": "中文",
                        "updateTime": "2018-03-27 16:58:00"
                    },
                    "msg": "请求成功"
                }
                            

下载接口

接口名称:downloadFile

接口完整路径:https://www.fanyigou.com/TranslateApi/api/downloadFile

接口说明:根据tid下载文档(任务完成才能下载)

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
dtype下载的文件类型(new):
2:翻译后的pdf文件,支持格式:word、pdf、img。
3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
6:转换完成文档
int
tid查询状态结果Idint上传源文件后可获取该ID

出参列表配置:

说明:1.判断Response Headers 中 detectLanguage 的值,若存在且不为空即为自动检测出的语言(可能为多种语言),仅供参考
2.判断Response Headers 中Content-Type 的值,若包含"application/octet-stream" 则可直接进行下载,否则即为以下返回值

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String

返回结果:

{"code": 312,"msg": "该转换不存在"}

图片翻译

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口调用流程

1.上传图片进行翻译(详见图片上传接口

2.获取图片翻译进度(详见图片翻译获取进度接口

3.下载译文图片(详见图片翻译下载接口

接口说明

图片上传接口

接口名称:uploadTranslateImage

接口完整路径:https://www.fanyigou.com/TranslateApi/api/image/uploadTranslateImage

接口说明:用户调用接口进行 源文件上传,上传完成后会自动进行翻译,通过tid可以查询翻译的进度等数据。注意:

1.上传格式:jpg、jpeg、png、bmp

2.上传文件最大4M

3.支持15*15 - 2048*2048px尺寸内

4.翻译完成后按页从主账号里扣费

调用说明:请求方式:post, file参数请以 multipart/form-data 方式的表单 POST 提交

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源语言String见图片语言列表
to目标语言String见图片语言列表
md5源文件md5Stringmd5小写

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
taskId翻译idString通过该id可查询翻译进度等

返回结果:

{"code": 100,"data": {"taskId": 14587},"msg": "请求成功"}

图片翻译获取进度接口

接口名称:queryImageTransProgress

接口完整路径:https://www.fanyigou.com/TranslateApi/api/image/queryImageTransProgress

接口说明:提交翻译完成后可调用此接口实时查询翻译进度或检测页数进度

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
tid查询状态结果Idint

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
fromLan源语言String
toLan目标语言String
detectLan检测语言String不为空即为自动检测出的主要语言,仅供参考
percent任务进度String
pageCount文件页数int
status任务状态int0 是完成 1 进行中 -1 翻译失败
msg状态说明String
createTime创建时间String
updateTime更新时间String

返回结果:

{
        "msg": "请求成功",
        "code": 100,
        "data": {
            "tid": 13417,
            "createTime": "2022-10-26 11:21:02",
            "updateTime": "2022-10-26 11:30:35",
            "status": 0,
            "title": "5120791b2f0967b54e057dd8af5d87e",
            "pageCount": 1,
            "percent": "100.00",
            "fromLan": "中文","detectLan": "",
            "toLan": "英语",
            "docType": "png",
            "msg": "翻译成功",
            "originalCharCount": 0
        }
    }          
                        

图片翻译下载接口

接口名称:downloadImage

接口完整路径:https://www.fanyigou.com/TranslateApi/api/image/downloadImage

接口说明:根据tid下载文档(任务完成才能下载)

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
tid查询状态结果Idint上传源文件后可获取该ID

出参列表配置:

说明:1.判断Response Headers 中Content-Type 的值,若包含"application/octet-stream" 则可直接进行下载,否则即为以下返回值

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String

返回结果:

{"code": 312,"msg": "该翻译不存在"}

OCR(图像识别)

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口说明

OCR上传接口

接口名称:ocrUploadImage

接口完整路径:https://www.fanyigou.com/TranslateApi/api/image/ocrUploadImage

接口说明:用户调用接口进行 源文件上传,上传完成后会自动进行识别并返回数据。注意:

1.上传格式:jpg、jpeg、png、bmp

2.上传文件最大4M

3.支持15*15 - 8192*8192px尺寸内

4.翻译完成后按次数从主账号里扣费

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源语言String见图片语言列表
md5源文件md5Stringmd5小写

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
words_result_num识别文字行数Int
words_result识别文字Array[]
words识别文字内容String
location文字位置Object
top顶部Int
leftInt
widthInt
heightInt

返回结果:

{"msg":"请求成功","code":100,"data":{"words_result":[{"words":"X Headers","location":{"top":0,"left":47,"width":96," height":10}}],"words_result_num":9}} 

语音识别翻译

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口调用流程

1.获取websocket链接标识(详见语音识别获取链接标识接口

2.连接webscoket进行语音识别翻译

3.下载译文音频文件(详见获取译文音频链接接口

接口说明

语音识别获取链接标识接口

接口名称:getConnectionId

接口完整路径:https://www.fanyigou.com/TranslateApi/api/voice/online/getConnectionId

调用说明:请求方式:get,post

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源语言(目前支持中文或者英文)String见语言列表
to目标语言(目前支持英文或者中文)String见语言列表

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集Json字符串

data结果集:

参数名称参数说明参数类型备注
recordId音频文件翻译idInteger
connectionId用来websocket连接的connectionId

说明

连接webscoket进行语音识别翻译

完整路径:wss://www.fanyigou.com/TranslateApi/api/voice/trans/online/{connectionId}

{connectionId}: 获取connectionId进行websocket连接(详见语音识别获取链接标识接口

并在地址上拼接如下参数:

注意:

1.语音识别获取链接标识接口与当前的websocket传入的appid必须一致

2.connectionId的只有二十分钟有效期

3.connenctionId连接成功并发送音频数据后不能再使用当前connectionId进行二次连接

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String

连接成功后:

1.发送采样率为16000,比特率为16bit,单声道的pcm格式数据

返回音频转换的原文文本{"state":"transing","transMsg":"转换的原文文本","msgType":0}

state":"transing" 表示当前正在翻译中,

音频转换原文内容为transMsg msgType为0表示为原文

返回音频转换的译文文本{"state":"transing","transMsg":"转换的译文文本","msgType":1}

2.录制结束

需要给服务器发送消息{"state":"recordend","transMsg":null,"msgType":null}

3.服务器翻译完成之后会返回翻译结果

翻译成功:{"state":"sucess","transMsg":null,"msgType":null}

翻译失败{"state":"fail","transMsg":null,"msgType":null}

如果返回翻译成功的则可以下载译文语音文件(详见获取译文音频链接接口

4.后端返回最终的翻译结果后,websocket连接可以关闭

5.注意:如果用户超过三十秒没有发送音频数据,超过最大实时语音的时长,或者余额不充足

服务器会返回

{"state":"receiveend","transMsg":null,"msgType":null}

结束翻译音频(之前发送的不受影响)

接口说明

获取译文音频链接接口

接口名称:getTransAudioLink

接口完整路径:https://www.fanyigou.com/TranslateApi/api/voice/online/getTransAudioLink

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
recordId音频文件翻译idInteger

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data译文音频下载链接String

音频识别翻译

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口调用流程

1.上传音频文件(详见音频文件上传接口

2.查询音频翻译进度(详见音频翻译任务查询接口

3.下载译文文本(详见音频下载译文链接接口

接口说明

音频文件上传接口

接口名称:upload

接口完整路径:https://www.fanyigou.com/TranslateApi/api/voice/audio/upload

请求方式:post(file参数请以 multipart/form-data 方式的表单 POST 提交)

语音识别翻译支持音频格式:

1.pcm(pcm_s16le)、wav音频格式文件;

2.文件大小仅支持10min、10M以内文件;

3.采样率为16000,比特率为16bit;

4.单声道;

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
from源语言(目前支持中文或者英文)String见语言列表
to目标语言(目前支持英文或者中文)String见语言列表

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data音频文件翻译idInteger通过该id可查询翻译进度等

音频翻译任务查询接口

接口名称:queryProgress

接口完整路径:https://www.fanyigou.com/TranslateApi/api/voice/audio/queryProgress

调用说明:请求方式:get,post

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
recordId音频文件翻译idInteger

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集Json字符串

data结果集:

参数名称参数说明参数类型备注
percent翻译进度String
status音频文件翻译Integer-1 上传失败 0 上传成功 6 正在翻译中 8 翻译成功 10 翻译失败

音频下载译文链接接口

接口名称:download

接口完整路径:https://www.fanyigou.com/TranslateApi/api/voice/audio/download

接口说明:请求方式:get,post

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
recordId音频文件翻译idInteger

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data下载链接String

词典

接入流程

注册翻译狗开放平台 登陆并添加开发者信息 创建应用 参考文档完成部署 测试完成

接口规则

为了带给客户简单、一致且易用的开发体验,我们规范了接口规则,你需要根据规范配置相关内容,请参考“接口规则”,如token的生成规则状态码列表等请查看该文档。

接口说明

词典搜索接口

接口名称:dict/search

接口完整路径:https://www.fanyigou.com/TranslateApi/api/dict/search

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
word搜索词String词语,小于等于15个字符

出参列表配置:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

返回结果:

{"msg":"请求成功","code":100,"data":{"dict":{"base":{"explain":{"word_means":[{"part":"n.","means":["入口,通道","(使用或见到的)机会/权利"]},{"part":"v.","means":["访问,存取(计算机信息)","到达,进入,使用"]}],"case_word":["ACCESS"]},"explain_zh":"","exchange":{"word_ing":["accessing"],"word_done":["accessed"],"word_past":["accessed"],"word_third":["accesses"],"word_pl":[]},"pron_zh":"","pron_am":{"text":"ˈækses","pronounce":""},"pron_en":{"text":"ˈækses","pronounce":""},"word":"access","pronounce":"https://qx-voice-dict.oss-cn-hangzhou.aliyuncs.com/word/en/access.wav?Expires=1693218092&OSSAccessKeyId=LTAI5tPjkAz1ACvr7rp9trNm&Signature=fTfIt675EJSNL%2Fva7GrY%2B5H014U%3D","chinese":false},"practical_sentences":[],"true_sentences":[{"tag":"四级","sentences":[]},{"tag":"六级","sentences":[]},{"tag":"高考","sentences":[{"text":"Depending on which role you choose, you could help to increase a community's access to safe drinking water, or help to protect valuable local cultures.","text_cn":"","source":"2019年高考英语北京卷 阅读理解 阅读A 原文"},{"text":"Designers have also created informal gathering places, and upgraded employees' access to heavily trafficked areas such as copy and coffee rooms.","text_cn":"","source":"2015年高考英语上海卷 选词填空 原文"},{"text":"Instead, computer users are developing stronger transactive memories; that is, people are learning how to organize huge quantities of information so that they are able to access it at a later date.","text_cn":"","source":"2015年高考英语安徽卷 阅读理解 阅读C 原文"},{"text":"It was really annoying; I couldn't get access to the data bank you had recommended.","text_cn":"","source":"2016年高考英语天津卷 单项填空 原文"},{"text":"One crucial factor is secure access to land.","text_cn":"","source":"2018年高考英语江苏卷 阅读理解 阅读C 原文"},{"text":"People have better access to health care than they used to, and they're living longer as a result.","text_cn":"","source":"2017年高考英语北京卷 单项填空 原文"},{"text":"Some also contain cd-roms and access to special online features.","text_cn":"","source":"2015年高考英语湖南卷 任务型读写 原文"},{"text":"Thus I have been allowed to gain access to their living environment.","text_cn":"","source":"2016年高考英语四川卷 阅读理解 阅读C 原文"},{"text":"Thus, the keyboard can determine people's identities, and by extension, whether they should be given access to the computer it's connected to—regardless of whether someone gets the password right.","text_cn":"","source":"2019年高考英语全国卷I 阅读理解 阅读C 原文"},{"text":"We need a better way to access information.","text_cn":"","source":"2015年高考英语安徽卷 阅读理解 阅读C 选项"}]},{"tag":"考研","sentences":[{"text":"Not only did they develop such a device but by the turn of the millennium they had also managed to embed it in a worldwide system accessed by billions of people every day.","text_cn":"","source":"出自-2012年考研阅读原文"},{"text":"When we don't understand the value of mental health and we don't know how to gain access to it, mental health will remain hidden from us.","text_cn":"","source":"出自-2016年考研翻译原文"},{"text":"The charter’s main tool of enforcement is to deny access for designers and modeling agencies to Copenhagen Fashion Week ( ' , CFW), which is run by the Danish Fashion Institute.","text_cn":"","source":"出自-2016年考研阅读原文"},{"text":"Rather officials must avoid double standards, or different types of access for average people and the wealthy.","text_cn":"","source":"出自-2017年考研阅读原文"},{"text":"Merely helping a gift-giver gain access to other officials, unless done with clear intent to pressure those officials, is not corruption, the justices found.","text_cn":"","source":"出自-2017年考研阅读原文"},{"text":"Favoritism in official access can fan public perceptions of corruption.","text_cn":"","source":"出自-2017年考研阅读原文"},{"text":"But the ruling reinforces the need for citizens and their elected representatives, not the courts, to ensure equality of access to government.","text_cn":"","source":"出自-2017年考研阅读原文"},{"text":"But it did so while holding its nose at the ethics of his conduct, which included accepting gifts such as a Rolex watch and a Ferrari automobile from a company seeking access to government.","text_cn":"","source":"出自-2017年考研阅读原文"},{"text":"But it did so while holding its nose at the ethics of his conduct, which included accepting gifts such as a Rolex watch and a Ferrari Automobile from a company seeking access to government.","text_cn":"","source":"2017年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"Critics make three main arguments against gene patents: a gene is a product of nature, so it may not be patented; gene patents suppress innovation rather than reward it; and patents'monopolies restrict access to genetic tests such as Myriad's.","text_cn":"","source":"2012年考研真题(英语二)阅读理解 Section Ⅱ"},{"text":"In Britain the move towards open access publishing has been driven by funding bodies.","text_cn":"","source":"2020年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"It can't when so many more employers have so much more access to so much more above average cheap foreign labor, cheap robotics, cheap software, cheap automation and cheap genius.","text_cn":"","source":"2013年考研真题(英语二)阅读理解 Section Ⅱ"},{"text":"Merely helping a gift-giver gain access to other officials, unless done with clear intent to pressure those officials, is not corruption, the Justices found.","text_cn":"","source":"2017年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"More than half of all British scientific research is now published under open access terms: either freely available from the moment of publication, or paywalled for a year or more so that the publishers can make a profit before being placed on general rel","text_cn":"","source":"2020年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"The charter's main tool of enforcement is to deny access for designers and modeling agencies to Copenhagen Fashion Week, which is run by the Danish Fashion Institute.","text_cn":"","source":"2016年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"The Dutch giant Elsevier, which claims to publish 25% of the scientific papers produced in the world, made profits of more than £900m last year, while UK universities alone spent more than £210m in 2016 to enable researchers to access their own publicly f","text_cn":"","source":"2020年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"The fact that this is not an uncommon occurrence means that dishonest persons might be able to access bank accounts in electronic payments systems and steal from someone else's accounts.","text_cn":"","source":"2013年考研真题(英语二)完形填空 Section Ⅰ"},{"text":"The most drastic, and thoroughly illegal, reaction has been the emergence of Sci-Hub, a kind of global photocopier for scientific papers, set up in 2012, which now claims to offer access to every paywalled article published since 2015.","text_cn":"","source":"2020年考研真题(英语一)阅读理解 Section Ⅱ"},{"text":"There are concerns that government, employers, and marketers might be able to access these data, thereby violating our privacy.","text_cn":"","source":"2013年考研真题(英语二)完形填空 Section Ⅰ"},{"text":"We often hear media reports that an unauthorized hacker has been able to access a computer database and to alter information stored there.","text_cn":"","source":"2013年考研真题(英语二)完形填空 Section Ⅰ"}]}],"ee_means":[],"roots_affixes":[],"phrases":[],"synonym":[{"part":"n.","word_means":[{"mean":"接近的机会","words":["of","way","entry","approach"]}]},{"part":"","word_means":[{"mean":"其他释义","words":["advent","retirement","admission","course","license","retreat","passport","accession","approach","door"]}]}],"antonym":[{"part":"n.","word_means":[{"mean":"接近;进入","words":["retirement","retreat"]}]}],"industry_dict":[],"synonym_explain":[],"collins":[{"entries":[{"define":"If you have access to a building or other place, you are able or allowed to go into it.","trans":"进入(权);通道;入径","part":"N-UNCOUNT","sentences":[{"origin":"The facilities have been adapted to give access to wheelchair users.","trans":"这些设施已经改造过以方便轮椅使用者进入。"},{"origin":"Scientists have only recently been able to gain access to the area...","trans":"科学家直到最近才得以进入该地区。"}]},{"define":"If you have access to something such as information or equipment, you have the opportunity or right to see it or use it.","trans":"查阅(或使用)的机会(或权利)","part":"N-UNCOUNT","sentences":[{"origin":"...a Code of Practice that would give patients right of access to their medical records.","trans":"允许病人查看自己病历的职业准则"},{"origin":"...whether one has access to a dish and the other accoutrements needed to watch satellite TV.","trans":"是否能使用碟型卫星天线以及其他观看卫星电视所需要的装备"}]},{"define":"If you have access to a person, you have the opportunity or right to see them or meet them.","trans":"接近(或面见)的机会(或权利)","part":"N-UNCOUNT","sentences":[{"origin":"He was not allowed access to a lawyer.","trans":"他未被获准见律师。"},{"origin":"My ex-wife deliberately sabotages my access to the children.","trans":"我的前妻蓄意阻挠我见孩子。"}]},{"define":"If you access something, especially information held on a computer, you succeed in finding or obtaining it.","trans":"存取,访问(计算机信息)","part":"VERB","sentences":[{"origin":"You've illegally accessed and misused confidential security files.","trans":"你已经非法访问并盗用了机密的安全文件。"}]}]}]}}}

回调通知

接口说明

目前文档翻译完成和格式转换完成支持回调(回调通知)

回调说明:翻译任务、转换任务,失败或成功时会发起回调

请求方式:post, application/json

目前回调地址需要后台设置,后续会开放设置

回调接口处理完成后须返回“success”字符串

回调参数列表:

参数名称参数说明参数类型备注
tid查询任务idint通过该id可查询任务进度等
title文件名String
docType文件类型String
fromLan源语言String
toLan目标语言String
detectLan检测语言String不为空即为自动检测出的主要语言,仅供参考
percent任务进度String
pageCount文件页数int
status任务状态int详见文件任务状态码
msg状态说明String
createTime创建时间String
updateTime更新时间String
type任务类型int1:文档翻译(默认),4:文档转换

回调JSON示例:

            {
                "createTime":"2021-08-25 14:27:47",
                "detectLan":"",
                "docType":"pdf",
                "fromLan":"中文",
                "msg":"完成",
                "pageCount":1,
                "percent":"100.00",
                "status":314,
                "tid":19432525,
                "title":"test",
                "toLan":"英语",
                "updateTime":"2021-08-25 14:27:47",
                "type":0
            }

账户相关

接口说明

获取账户信息接口

接口名称:getAccount

接口完整路径:https://www.fanyigou.com/TranslateApi/api/getAccount

接口说明:获取账户信息

入参列表配置:

参数名称参数说明参数类型备注是否必填
appid应用的唯一识别标记String
token签名String见token生成规则
nonce_str随机字符串String
type资源包类型 1.文档翻译 2.文字翻译 3.图片翻译 4.格式转换int 默认值1

出参列表:

参数名称参数说明参数类型备注
code状态码int详见状态码列表
msg返回状态说明String
data返回数据结果集StringJson字符串

data结果集:

参数名称参数说明参数类型备注
deductType0:按积分计费,1:按页计费int
balance余额int

返回结果:

{"code":100,"data":{"deductType":1,"balance":137684},"msg":"请求成功"}

安全规范

1、token的生成规则

签名生成的通用步骤如下:

第一步,设所有发送或者接收到的数据为集合M(包括平台生成的privatekey),将集合M内非空参数值的参数按照参数名ASCII码从小到大排序(字典序),使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串stringA。

特别注意以下重要规则:

◆ 参数名ASCII码从小到大排序(字典序);
◆ 如果参数的值为空不参与签名;
◆ 参数名区分大小写;
◆ 验证调用返回或主动通知签名时,传送的token参数不参与签名,将生成的签名与该token值作校验。
◆ 接口可能增加字段,验证签名时必须支持增加的扩展字段

第二步,对stringA进行MD5运算,再将得到的字符串所有字符转换为大写,得到token值。
◆ privatekey获取:个人中心(头像)-总览-开发者信息-密钥

举例:

假设传送的参数如下:

            appid:1522125815142
            nonce_str:ibuaiVcKdpRxkhJA
            from : en
            to : zh
            md5 : 5b21f2eeda4726c74274fc27a53bac74
    
            第一步:对参数按照key=value的格式(包括privatekey),并按照参数名ASCII字典序排序如下:
                                
            stringA="appid=1522125815142&from=en&md5=5b21f2eeda4726c74274fc27a53bac74&nonce_str=ibuaiVcKdpRxkhJA&privatekey=4892ef64ewf5sffdf&to=zh";
    
            第二步:加密:
    
            token=MD5(stringA).toUpperCase()="31956D481EFF09D7F3EB7C1312BC61E0" 
    
            最终得到最终发送的数据:
            appid:1522125815142
            nonce_str:ibuaiVcKdpRxkhJA
            from : en
            to : zh
            md5 : 5b21f2eeda4726c74274fc27a53bac74
            token : 31956D481EFF09D7F3EB7C1312BC61E0
                        

2、生成随机数算法

API接口协议中包含字段nonce_str,主要保证签名不可预测。我们推荐生成随机数算法如下:调用随机数函数生成,将得到的值转换为字符串。

协议规则

用户接入API时,调用API必须遵循以下规则:

提交方式统一采用POST方法提交,文件上传类接口使用multipart/form-data提交,
其它接口使用application/x-www-form-urlencoded提交,暂不支持使用json格式参数提交
字符编码统一采用UTF-8字符编码
签名算法MD5,后续会兼容SHA1、SHA256等。
签名要求请求需要校验签名,详细方法请参考安全规范-签名算法
判断逻辑先判断协议字段返回,再判断业务返回

语言列表

语言代码语言
"" 或 auto自动检测
zh中文
jp日语
th泰语
fra法语
en英语
spa西班牙语
kor韩语
tr土耳其语
vie越南语
ms马来语
de德语
ru俄语
ara阿拉伯语
est爱沙尼亚语
be白俄罗斯语
bul保加利亚语
hi印地语
is冰岛语
tl菲律宾语
fin芬兰语
nl荷兰语
ca加泰罗尼亚语
cs捷克语
hr克罗地亚语
lv拉脱维亚语
lt立陶宛语
rom罗马尼亚语
no挪威语
pt葡萄牙语
swe瑞典语
sr塞尔维亚语
eo世界语
sk斯洛伐克语
slo斯洛文尼亚语
sw斯瓦希里语
uk乌克兰语
iw希伯来语
el希腊语
hu匈牙利语
hy亚美尼亚语
it意大利语
id印尼语
sq阿尔巴尼亚语
am阿姆哈拉语
az阿塞拜疆语
eu巴斯克语
bn孟加拉语
bs波斯尼亚语
gl加利西亚语
ka格鲁吉亚语
gu古吉拉特语
ig伊博语
ga爱尔兰语
zu祖鲁语
kn卡纳达语
kk哈萨克语
ky吉尔吉斯语
lb卢森堡语
mk马其顿语
mt马耳他语
mi毛利语
mr马拉提语
ne尼泊尔语
pa旁遮普语
si僧加罗语
ta泰米尔语
te泰卢固语
ur乌尔都语
uz乌兹别克语
cy威尔士语
yo约鲁巴语
cht中文繁体

状态码列表

系统状态码:

状态码状态描述
100请求成功
101没有访问权限
102业务停机
103账户不存在
104账户异常
105系统错误
106参数异常
107黑名单管控
108访问地址频率过高
109该应用不存在
110该应用尚未启用
111无该功能权限

文档状态码:

状态码状态描述
300参数为空
301文件为空
302文件类型不支持
303文件MD5不匹配
304可用积分不足
305文档已加密或被保护
306文档不能识别
307文档损坏
309文档无法成功读取或读取超时,请将文件转换成其他版本的word或pdf后再次尝试
310自动处理超时,等待人工处理
311文件大小超过限制(50M)
312该翻译不存在
313进行中
314翻译完成
315正在传递
316处理超时
317已取消
318该文件不存在
320翻译通道已被占用(不能上传进行翻译,需等待正在翻译的文件翻译结束)
321没有读取到需要翻译的内容
322图片文件大小超过限制(20M)
323图片文件像素超过限制(1000万)
324图片文件解析失败
325正在人工处理
326重复翻译
327文档页数超限
328图片生成失败
329该文档状态异常
330检测页数完成

行业列表

行业代码行业
1法律
2金融
3农林牧渔
4医药卫生
5建筑建材
6冶金矿产
7石油化工
8水利水电
9交通运输
10信息产业
11机械机电
12轻工食品
13服装纺织
14专业服务
15安全防护
16环保绿化
17旅游休闲
18办公文教
19电子电工
20玩具礼品
21家居用品
22物资
23包装
24体育
25办公
26其他

JAVA-SDK调用说明

环境说明

运行环境:JDK8

操作步骤

在项目的pom.xml的dependencies中加入以下内容:

    <dependency>

        <groupId>com.qingxun</groupId>

        <artifactId>java-sdk-api</artifactId>

        <version>0.0.3</version>

    <dependency>         
                                            
示例代码
package com.qingxun.javasdkapi.examples;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.DocTransOpenApiClient;
import com.qingxun.javasdkapi.request.DownloadFileRequest;
import com.qingxun.javasdkapi.request.QueryTransProgressRequest;
import com.qingxun.javasdkapi.request.UploadTransRequest;
import com.qingxun.javasdkapi.response.DownloadFileResponse;
import com.qingxun.javasdkapi.response.QueryTransProgressResponse;
import com.qingxun.javasdkapi.response.UploadTransResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;

/**
* 文档翻译
*/
public class DocTransOpenApiClientDemo extends CommonDemo {


private final static String uploadFilePath = "需要上传的文件路径";
private final static String appId = "您的appId";
private final static String privateKey = "您的privateKey";
private final static String fromLan = "文件的原语言";
private final static String toLan = "文件的目标语言";
private final static String saveTransDirPath = "保存翻译后的文件目录名称";
private final static String saveTransFileName = "保存翻译后的文件名称";
/**
    * 下载的文件类型(new):
    * 2:翻译后的pdf文件,支持格式:word、pdf、img。
    * 3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
    * 6:转换完成文档
    */
private final static Integer dType = 3;

private final static Logger log = LoggerFactory.getLogger(DocTransOpenApiClientDemo.class);

private static DocTransOpenApiClient docTransOpenApiClient = new DocTransOpenApiClient(appId, privateKey);


public static UploadTransResponse upload(String path) {
    File file = new File(path);
    UploadTransRequest uploadTransRequest = new UploadTransRequest.Builder()
            .setFrom(fromLan)
            .setTo(toLan).setFile(file)
            .builder();
    return docTransOpenApiClient.excute(uploadTransRequest);
}

public static QueryTransProgressResponse queryTransProgress(Integer docId) {
    QueryTransProgressRequest queryTransProgressRequest = new QueryTransProgressRequest.Builder().setTid(docId).builder();
    return docTransOpenApiClient.excute(queryTransProgressRequest);
}

public static DownloadFileResponse downloadFile(Integer docId, Integer dType) {
    DownloadFileRequest downloadFileRequest = new DownloadFileRequest.Builder().setTid(docId).setDtype(dType).builder();
    return docTransOpenApiClient.excute(downloadFileRequest);
}

public static void main(String[] args) throws FileNotFoundException, JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    QueryTransProgressResponse queryTransProgressResponse;
    UploadTransResponse uploadTransResponse = upload(uploadFilePath);
    log.info("文档翻译上传结果: {}",objectMapper.writeValueAsString(uploadTransResponse));
    if (uploadTransResponse != null && uploadTransResponse.getTid() > 0) {
        boolean flag = true;
        while (flag) {
            queryTransProgressResponse = queryTransProgress(uploadTransResponse.getTid());
            log.info("文档翻译查询进度: {}",objectMapper.writeValueAsString(queryTransProgressResponse));
            if (queryTransProgressResponse.getStatus().equals(314)) {
                //下载格式转换后的文件
                DownloadFileResponse response = downloadFile(queryTransProgressResponse.getTid(), dType);
                //保存格式转换后得到的文件
                bytesToFile(response.getBytes(), saveTransDirPath, saveTransFileName + response.getDocType());
                return;
            }
            if (queryTransProgressResponse.getStatus().equals(313)) {
                flag = true;
            } else {
                flag = false;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
}
                                    
文档翻译示例代码
package com.qingxun.javasdkapi.examples;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.DocTransOpenApiClient;
import com.qingxun.javasdkapi.request.DownloadFileRequest;
import com.qingxun.javasdkapi.request.QueryTransProgressRequest;
import com.qingxun.javasdkapi.request.UploadTransRequest;
import com.qingxun.javasdkapi.response.DownloadFileResponse;
import com.qingxun.javasdkapi.response.QueryTransProgressResponse;
import com.qingxun.javasdkapi.response.UploadTransResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * 文档翻译
 */
public class DocTransOpenApiClientDemo extends CommonDemo {


    private final static String uploadFilePath = "需要上传的文件路径";
    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String fromLan = "文件的原语言";
    private final static String toLan = "文件的目标语言";
    private final static String saveTransDirPath = "保存翻译后的文件目录名称";
    private final static String saveTransFileName = "保存翻译后的文件名称";
    /**
        * 下载的文件类型(new):
        * 2:翻译后的pdf文件,支持格式:word、pdf、img。
        * 3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
        * 6:转换完成文档
        */
    private final static Integer dType = 3;

    private final static Logger log = LoggerFactory.getLogger(DocTransOpenApiClientDemo.class);

    private static DocTransOpenApiClient docTransOpenApiClient = new DocTransOpenApiClient(appId, privateKey);


    public static UploadTransResponse upload(String path) {
        File file = new File(path);
        UploadTransRequest uploadTransRequest = new UploadTransRequest.Builder()
                .setFrom(fromLan)
                .setTo(toLan).setFile(file)
                .builder();
        return docTransOpenApiClient.excute(uploadTransRequest);
    }

    public static QueryTransProgressResponse queryTransProgress(Integer docId) {
        QueryTransProgressRequest queryTransProgressRequest = new QueryTransProgressRequest.Builder().setTid(docId).builder();
        return docTransOpenApiClient.excute(queryTransProgressRequest);
    }

    public static DownloadFileResponse downloadFile(Integer docId, Integer dType) {
        DownloadFileRequest downloadFileRequest = new DownloadFileRequest.Builder().setTid(docId).setDtype(dType).builder();
        return docTransOpenApiClient.excute(downloadFileRequest);
    }

    public static void main(String[] args) throws FileNotFoundException, JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        QueryTransProgressResponse queryTransProgressResponse;
        UploadTransResponse uploadTransResponse = upload(uploadFilePath);
        log.info("文档翻译上传结果: {}",objectMapper.writeValueAsString(uploadTransResponse));
        if (uploadTransResponse != null && uploadTransResponse.getTid() > 0) {
            boolean flag = true;
            while (flag) {
                queryTransProgressResponse = queryTransProgress(uploadTransResponse.getTid());
                log.info("文档翻译查询进度: {}",objectMapper.writeValueAsString(queryTransProgressResponse));
                if (queryTransProgressResponse.getStatus().equals(314)) {
                    //下载格式转换后的文件
                    DownloadFileResponse response = downloadFile(queryTransProgressResponse.getTid(), dType);
                    //保存格式转换后得到的文件
                    bytesToFile(response.getBytes(), saveTransDirPath, saveTransFileName + response.getDocType());
                    return;
                }
                if (queryTransProgressResponse.getStatus().equals(313)) {
                    flag = true;
                } else {
                    flag = false;
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
                                    
文字翻译示例代码
package com.qingxun.javasdkapi.examples;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.TextTransOpenApiClient;
import com.qingxun.javasdkapi.request.TextTransRequest;
import com.qingxun.javasdkapi.response.TextTransResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 文字翻译
 */

public class TextTransOpenApiClientDemo {


    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String fromLan = "文字的原语言";
    private final static String toLan = "文字的目标语言";
    private final static String content="需要翻译的文字内容";

    private static TextTransOpenApiClient textTransOpenApiClient = new TextTransOpenApiClient(
            appId,privateKey);

    private static  final Logger log = LoggerFactory.getLogger(TextTransOpenApiClientDemo.class);
    private static  final ObjectMapper objectMapper = new ObjectMapper();

    public static TextTransResponse transText(String content){
        TextTransRequest transRequest = new TextTransRequest.Builder().setText(content)
                .setFrom(fromLan).setTo(toLan).builder();
        return textTransOpenApiClient.excute(transRequest);
    }


    public static void main(String[] args) throws JsonProcessingException {
        //文字翻译
        TextTransResponse response =  transText(content);
        log.info("文本翻译结果{}",objectMapper.writeValueAsString(response));
    }

}
                                    
格式转换示例代码
package com.qingxun.javasdkapi.examples;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.DocConvertOpenApiClient;
import com.qingxun.javasdkapi.request.ConvertRequest;
import com.qingxun.javasdkapi.request.DownloadFileRequest;
import com.qingxun.javasdkapi.request.QueryTransProgressRequest;
import com.qingxun.javasdkapi.response.ConvertResponse;
import com.qingxun.javasdkapi.response.DownloadFileResponse;
import com.qingxun.javasdkapi.response.QueryTransProgressResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * 格式转换
 */
public class DocConvertOpenApiClientDemo extends CommonDemo {

    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String convertFilePath = "需要格式转换的文件";
    private final static String saveConvertedDirPath = "保存转换后的文件目录名称";
    private final static String saveConvertedFileName = "保存转换后的文件名称";
    //转换的目标格式 -1:word;-3:excel;-6:pptx,-8:pdf,-9:ofd。
    private final static Integer conversionformat = -8;
    /**
     * 下载的文件类型(new):
     * 2:翻译后的pdf文件,支持格式:word、pdf、img。
     * 3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
     * 6:转换完成文档
     */
    private final static Integer dType =6;
    //源文件的语言(扫描件需设置语言)
    private final static  String fromLan="zh";
    private final static Logger log = LoggerFactory.getLogger(DocConvertOpenApiClientDemo.class);
    private final static ObjectMapper objectMapper = new ObjectMapper();

    private static DocConvertOpenApiClient docConvertOpenApiClient = new DocConvertOpenApiClient(appId, privateKey);

    public static ConvertResponse convertFile(String filePath) {
        ConvertRequest convertRequest = new ConvertRequest.Builder()
                .setFile(new File(filePath))
                .setFrom(fromLan)
                .setConversionFormat(conversionformat)
                .builder();
        return docConvertOpenApiClient.excute(convertRequest);
    }

    public static QueryTransProgressResponse queryTransProcess(Integer tid) {
        QueryTransProgressRequest queryTransProgressRequest = new QueryTransProgressRequest.Builder().setTid(tid).builder();
        return docConvertOpenApiClient.excute(queryTransProgressRequest);
    }

    public static DownloadFileResponse downloadFile(Integer tid, Integer dtype) {
        DownloadFileRequest downloadFileRequest = new DownloadFileRequest.Builder().setTid(tid).setDtype(dtype).builder();
        return docConvertOpenApiClient.excute(downloadFileRequest);

    }


    public static void main(String[] args) throws JsonProcessingException {
        ConvertResponse convertResponse = convertFile(convertFilePath);
        log.info("转换文件结果{}", objectMapper.writeValueAsString(convertResponse));
        QueryTransProgressResponse queryTransProgressResponse;
        boolean flag = true;
        while (flag) {
            //查询格式转换后的转换进度
            queryTransProgressResponse = queryTransProcess(convertResponse.getTid());
            log.info("查询转换文件进度结果{}", objectMapper.writeValueAsString(queryTransProgressResponse));
            if (queryTransProgressResponse == null) {
                return;
            }
            if (queryTransProgressResponse.getStatus().equals(314)) {
                //下载格式转换后的文件
                DownloadFileResponse response = downloadFile(convertResponse.getTid(), dType);
                //保存格式转换后得到的文件
                bytesToFile(response.getBytes(), saveConvertedDirPath, saveConvertedFileName + response.getDocType());
                return;
            }
            if (queryTransProgressResponse.getStatus().equals(313)) {
                flag = true;
            } else {
                flag = false;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
                                    
图片翻译示例代码
package com.qingxun.javasdkapi.examples;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.ImageTransOpenApiClient;
import com.qingxun.javasdkapi.request.DownloadImageRequest;
import com.qingxun.javasdkapi.request.QueryTransImageProgressRequest;
import com.qingxun.javasdkapi.request.UploadTransImageRequest;
import com.qingxun.javasdkapi.response.DownloadImageResponse;
import com.qingxun.javasdkapi.response.QueryTransImageProgressResponse;
import com.qingxun.javasdkapi.response.UploadTransImageResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * 图片翻译
 */
public class ImageTransOpenApiClientDemo extends CommonDemo {

    private final static String uploadFilePath = "需要翻译的图片路径";
    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String fromLan = "图片的原语言";
    private final static String toLan = "图片的目标语言";
    private final static String saveTransDirPath = "保存翻译后的文件目录名称";
    private final static String saveTransFileName = "保存翻译后的文件名称";
    /**
     * 下载的文件类型(new):
     * 2:翻译后的pdf文件,支持格式:word、pdf、img。
     * 3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
     * 6:转换完成文档
     */
    private final static Integer dType = 3;
    //private final static String saveTransFileName = "保存翻译后的文件名称";


    private final static Logger log = LoggerFactory.getLogger(ImageTransOpenApiClientDemo.class);

    private static ImageTransOpenApiClient imageTransOpenApiClient = new ImageTransOpenApiClient(
            appId,privateKey);

    public static DownloadImageResponse downloadFile(Integer tid) {
        DownloadImageRequest downloadFileRequest = new DownloadImageRequest.Builder()
                .setTid(tid).builder();

        return imageTransOpenApiClient.excute(downloadFileRequest);
    }

    public static  UploadTransImageResponse uploadImage(String filePath){
        File file = new File(filePath);
        UploadTransImageRequest uploadTransImageRequest = new UploadTransImageRequest.Builder()
                //md5参数会自动计算
                .setFile(file).setFrom(fromLan).setTo(toLan).builder();
        return imageTransOpenApiClient.excute(uploadTransImageRequest);
    }


    public static QueryTransImageProgressResponse queryTransImageProgress(Integer tid){
        QueryTransImageProgressRequest queryTransImageProgressRequest = new QueryTransImageProgressRequest.Builder().setTid(tid).builder();
        return imageTransOpenApiClient.excute(queryTransImageProgressRequest);
    }


    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        QueryTransImageProgressResponse queryTransProgressResponse;
        UploadTransImageResponse uploadTransResponse = uploadImage(uploadFilePath);
        log.info("图片翻译上传结果: {}",objectMapper.writeValueAsString(uploadTransResponse));
        if (uploadTransResponse != null && uploadTransResponse.getTid() > 0) {
            boolean flag = true;
            while (flag) {
                queryTransProgressResponse = queryTransImageProgress(uploadTransResponse.getTid());
                log.info("图片翻译查询进度: {}",objectMapper.writeValueAsString(queryTransProgressResponse));
                if (queryTransProgressResponse.getStatus().equals(0)) {
                    //下载图片翻译后的文件
                    DownloadImageResponse response = downloadFile(uploadTransResponse.getTid());
                    //保存图片翻译后得到的文件
                    bytesToFile(response.getBytes(), saveTransDirPath, saveTransFileName);
                    return;
                }
                if (queryTransProgressResponse.getStatus().equals(1)) {
                    flag = true;
                }
                if(queryTransProgressResponse.getStatus().equals(-1)) {
                    flag = false;
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }

    }
}
                                    
OCR(图像识别)示例代码
package com.qingxun.javasdkapi.examples;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.ImageOcrOpenApiClient;
import com.qingxun.javasdkapi.request.OcrUploadTransRequest;
import com.qingxun.javasdkapi.response.OcrImageUploadResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * OCR(图像识别)
 */
public class ImageOcrOpenApiClientDemo {


    private final static String uploadFilePath = "需要识别的图片路径";
    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String fromLan = "图片的原语言";

    private final static Logger log = LoggerFactory.getLogger(ImageOcrOpenApiClientDemo.class);

    private final static ObjectMapper objectMapper = new ObjectMapper();

    private static ImageOcrOpenApiClient imageTransOpenApiClient = new ImageOcrOpenApiClient(
            appId, privateKey);


    public static OcrImageUploadResponse upload(String filePath) {
        OcrUploadTransRequest ocrUploadTransRequest = new OcrUploadTransRequest.Builder()
                .setFile(new File(filePath))
                .setFrom(fromLan).builder();
        return imageTransOpenApiClient.excute(ocrUploadTransRequest);
    }


    public static void main(String[] args) throws JsonProcessingException {
        OcrImageUploadResponse ocrImageUploadResponse = upload(uploadFilePath);
        log.info(objectMapper.writeValueAsString(ocrImageUploadResponse));
    }

}
                                    
语音识别翻译示例代码
package com.qingxun.javasdkapi.examples;

import cn.hutool.core.util.ArrayUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.OnlineVoiceTransOpenApiClient;
import com.qingxun.javasdkapi.clients.OnlineVoiceTransWebSocketClient;
import com.qingxun.javasdkapi.request.OnlineVoiceGetConnecionIdRequest;
import com.qingxun.javasdkapi.request.OnlineVoiceGetDownloadUrlRequest;
import com.qingxun.javasdkapi.response.OnlineMsg;
import com.qingxun.javasdkapi.response.OnlineVoiceGetConnectionIdResponse;
import com.qingxun.javasdkapi.response.OnlineVoiceGetDownloadUrlResponse;
import org.apache.commons.lang3.StringUtils;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;

/**
 * 语音识别翻译
 */
public class OnlineVoiceTransOpenApiClientDemo {

    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String fromLan = "语音的原语言";
    private final static String toLan = "语音的目标语言";

    private final static OnlineVoiceTransOpenApiClient onlineVoiceTransOpenApiClient = new OnlineVoiceTransOpenApiClient(appId, privateKey);

    private final static Logger log = LoggerFactory.getLogger(OnlineVoiceTransOpenApiClientDemo.class);

    private final static ObjectMapper objectMapper = new ObjectMapper();

    public static OnlineVoiceGetConnectionIdResponse getConnectionId() {
        OnlineVoiceGetConnecionIdRequest onlineVoiceGetConnecionIdRequest = new OnlineVoiceGetConnecionIdRequest.Builder().setFrom(fromLan)
                .setTo(toLan).builder();
        return onlineVoiceTransOpenApiClient.excute(onlineVoiceGetConnecionIdRequest);
    }

    public static OnlineVoiceGetDownloadUrlResponse getDownloadUrl(Integer recordId) {
        OnlineVoiceGetDownloadUrlRequest onlineVoiceGetDownloadUrlRequest = new OnlineVoiceGetDownloadUrlRequest.Builder().setRecordId(recordId).builder();
        return onlineVoiceTransOpenApiClient.excute(onlineVoiceGetDownloadUrlRequest);
    }


    //自定义在线语音处理逻辑
    static class OnlineHandler extends OnlineVoiceTransWebSocketClient.AbstractOnlineVoiceHandler {

        private Integer recordId;

        private String websocketUrl;

        public OnlineHandler(Integer recordId,String websocketUrl) {
            this.recordId = recordId;
            this.websocketUrl = websocketUrl;
        }

        @Override
        public void handMessage(OnlineMsg onlineMsg) {
            try {
                log.info("接收到内容{}",objectMapper.writeValueAsString(onlineMsg));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            if (onlineMsg == null) {
                return;
            }
            if (onlineMsg.getState().equals("transing")) {
                if (onlineMsg.getMsgType() != null && onlineMsg.getMsgType() == 0) {
                    log.info("语音识别 原文:{}", onlineMsg.getTransMsg());
                }
                if (onlineMsg.getMsgType() != null && onlineMsg.getMsgType() == 1) {
                    log.info("语音识别 译文:{}", onlineMsg.getTransMsg());
                }
            }
            if (onlineMsg.getState().equals("receiveend")) {
                log.info("由于余额不足或者长时间未发送语音数据导致服务器拒绝接受在线语音数据");
            }
            if (onlineMsg.getState().equals("sucess")) {
                log.info("在线语音全部转写翻译成功");
                //下载译文音频
                OnlineVoiceGetDownloadUrlResponse onlineVoiceGetDownloadUrlResponse = getDownloadUrl(recordId);
                try {
                    log.info("译文音频的下载链接{}", objectMapper.writeValueAsString(onlineVoiceGetDownloadUrlResponse));
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                }

            }

        }

        @Override
        public void handleOpen(ServerHandshake serverHandshake) {
            log.info("{}连接成功",websocketUrl);

        }

        @Override
        public void handleClose(int i, String s, boolean b) {
            log.info("连接关闭{} {} {}",i,s,b);
        }

        @Override
        public void handleError(Exception e) {
            e.printStackTrace();

        }
    }

    public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {

        OnlineVoiceGetConnectionIdResponse response = getConnectionId();
        log.info("获取connectionId结果{}",objectMapper.writeValueAsString(response));
        if (null == response || response.getRecordId() == null || StringUtils.isEmpty(response.getConnectionId())) {
            log.error("获取connectionId失败");
        }
        String url = onlineVoiceTransOpenApiClient.getConnectionWebSocketUrl(response.getConnectionId());
        log.info("连接地址{}",url);
        OnlineHandler onlineHandler = new OnlineHandler(response.getRecordId(),url);
        //在线语音websocket连接
        OnlineVoiceTransWebSocketClient onlineVoiceTransWebSocketClient = new OnlineVoiceTransWebSocketClient(url, onlineHandler);
        onlineVoiceTransWebSocketClient.connect();
        //模拟发送在线语音
        FileInputStream inputStream = new FileInputStream("/Users/cedric/Downloads/test.wav");
        int bufferSize = 2560;
        byte[] b = new byte[bufferSize];
        int len;
        int all = 0;
        while (!onlineVoiceTransWebSocketClient.isOpen()) {
            Thread.sleep(1000);
        }
        try {
            while ((len = inputStream.read(b)) > 0) {
                all += 1;
                log.info("发送了{}字节,共发送{}次,需要发送{}次", len, all, (inputStream.available() / 2560));
                //发送语音数据
                onlineVoiceTransWebSocketClient.send(ArrayUtil.sub(b, 0, len));
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
        onlineVoiceTransWebSocketClient.send("{\"state\":\"recordend\",\"transMsg\":null,\"msgType\":null}");

        Thread.sleep(600000L);

    }


}
                                    
音频识别翻译示例代码
package com.qingxun.javasdkapi.examples;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.AudioTransOpenApiClient;
import com.qingxun.javasdkapi.request.AudioGetDownloadUrlRequest;
import com.qingxun.javasdkapi.request.AudioQueryProgressRequest;
import com.qingxun.javasdkapi.request.AudioUploadTransRequest;
import com.qingxun.javasdkapi.response.AudioGetDownloadUrlResponse;
import com.qingxun.javasdkapi.response.AudioQueryProcessResponse;
import com.qingxun.javasdkapi.response.AudioUploadTransResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * 音频识别翻译
 */
public class AudioTransOpenApiClientDemo {


    private final static String uploadFilePath = "需要上传的音频文件路径";
    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String fromLan = "音频文件的原语言";
    private final static String toLan = "音频文件的目标语言";

    private final static Logger log = LoggerFactory.getLogger(DocConvertOpenApiClientDemo.class);
    private final static ObjectMapper objectMapper = new ObjectMapper();


    private static AudioTransOpenApiClient audioTransOpenApiClient = new AudioTransOpenApiClient(appId, privateKey);


    public static AudioUploadTransResponse uploadAudio(String filePath) {
        AudioUploadTransRequest audioUploadTransRequest = new AudioUploadTransRequest.Builder().setFrom(fromLan).setTo(toLan).setFile(new File(filePath))
                .builder();
        return audioTransOpenApiClient.excute(audioUploadTransRequest);
    }


    public static AudioQueryProcessResponse getTransProgress(Integer recordId) {
        AudioQueryProgressRequest audioUploadTransRequest = new AudioQueryProgressRequest.Builder().setRecordId(recordId).builder();
        return audioTransOpenApiClient.excute(audioUploadTransRequest);
    }


    public static AudioGetDownloadUrlResponse getDownloadUrl(Integer recordId) {
        AudioGetDownloadUrlRequest audioGetDownloadUrlRequest = new AudioGetDownloadUrlRequest.Builder().setRecordId(recordId).builder();
        return audioTransOpenApiClient.excute(audioGetDownloadUrlRequest);
    }


    public static void main(String[] args) throws JsonProcessingException {
        //音频文件上传
        AudioUploadTransResponse audioUploadTransResponse = uploadAudio(uploadFilePath);
        if (audioUploadTransResponse != null && audioUploadTransResponse.getRecordId() > 0) {
            AudioQueryProcessResponse audioQueryProcessResponse = null;
            while (true) {
                //每三秒查询进度
                audioQueryProcessResponse = getTransProgress(audioUploadTransResponse.getRecordId());
                if (null == audioQueryProcessResponse) {
                    return;
                }
                log.info("查询进度结果{}", objectMapper.writeValueAsString(audioQueryProcessResponse));
                if (audioQueryProcessResponse.getStatus().equals("8")) {
                    AudioGetDownloadUrlResponse audioGetDownloadUrlResponse = getDownloadUrl(audioUploadTransResponse.getRecordId());
                    log.info("获取下载链接{}", objectMapper.writeValueAsString(audioGetDownloadUrlResponse));
                }
                try {
                    Thread.sleep(3000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
                                    
词典示例代码
package com.qingxun.javasdkapi.examples;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.DictSearchOpenApiClient;
import com.qingxun.javasdkapi.request.DictSearchRequest;
import com.qingxun.javasdkapi.response.DictSearchResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 词典
 */
public class DictSearchOpenApiClientDemo {


    private final static String appId = "您的appId";
    private final static String privateKey = "您的privateKey";
    private final static String content = "需要搜索的文字内容";


    private static DictSearchOpenApiClient dictSearchOpenApiClient = new DictSearchOpenApiClient(
            appId, privateKey);

    private static final Logger log = LoggerFactory.getLogger(DictSearchOpenApiClientDemo.class);
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static DictSearchResponse dictSearch(String word) {
        DictSearchRequest dictRequest = new DictSearchRequest.Builder().setWord(word).builder();
        return dictSearchOpenApiClient.excute(dictRequest);
    }


    public static void main(String[] args) throws JsonProcessingException {
        //词典-词库搜索
        DictSearchResponse response = dictSearch(content);
        log.info("词库搜索结果{}", objectMapper.writeValueAsString(response));
    }

}
                                    
获取账户信息示例代码
package com.qingxun.javasdkapi.examples;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingxun.javasdkapi.clients.AccountsOpenApiClient;
import com.qingxun.javasdkapi.request.GetAccountRequest;
import com.qingxun.javasdkapi.response.GetAccountResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 账户相关
 */
public class AccountsOpenApiClientDemo {

    private final static String appId = "您的appId";

    private final static String privateKey = "您的privateKey";

    /**
     * 资源包类型 1.文档翻译 2.文字翻译 3.图片翻译 4.格式转换
     */
    private final static Integer type=2;

    private final static Logger log = LoggerFactory.getLogger(DocConvertOpenApiClientDemo.class);

    private final static ObjectMapper objectMapper = new ObjectMapper();

    private static AccountsOpenApiClient accountsOpenApiClient = new AccountsOpenApiClient(appId, privateKey);

    public static GetAccountResponse getAccount(Integer type) {
        GetAccountRequest getAccountRequest = new GetAccountRequest.Builder()
                .setType(type)
                .builder();

        return accountsOpenApiClient.excute(getAccountRequest);
    }

    public static void main(String[] args) throws JsonProcessingException {
        //获取账户信息接口
        GetAccountResponse getAccountResponse = getAccount(type);
        log.info("获取账号信息{}",objectMapper.writeValueAsString(getAccountResponse));


    }
}
                                    

PHP-SDK调用说明

环境说明

PHP 7.1+

cURL extension

操作步骤

使用Composer来管理项目依赖项,请在项目的根目录中运行以下命令:

composer require fanyigou/api-sdk-php

在Composer依赖管理器安装完成后,在您的PHP代码中导入该依赖项:

require_once __DIR__ . '/vendor/autoload.php'
示例代码
文件上传
    <?php
    include_once __DIR__.'/vendor/autoload.php';
    
    use Fanyigou\ApiSdkPhp\Dispatch;
    use Fanyigou\ApiSdkPhp\DispatchException;
    
    $appKey = '您的应用ID';
    $secKey = '您的密钥';
    
    $dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);
    
    $filePath = '文档路径'; //文档路径
    
    $params = [
    'from' => 'en',
    'to' => 'zh',
    ];
    
    try {
        $result = $dispatch->uploadTranslate($params, $filePath);
        print_r($result);
    } catch (DispatchException $e) {
        print_r($e->getMessage());
    }
                                        
文档翻译示例代码
  • 1. 上传示例代码
  • 2. 上传文件检测页数示例代码
  • 3. 检测页数文件提交翻译示例代码
  • 4. 获取进度示例代码
  • 5. 下载示例代码
上传示例代码
<?php
/**
 * 上传 
1.上传格式:pdf、Microsoft Office(doc、docx、dot、dotx、dotm、docm、xml、odt)、WPSOffice(wps、wpt)、xls、xlsx、et、ett、ppt、pptx、dps、dpt、txt、rtf;

2.上传文件最大50M(如有更高需求请联系销售);

3. 不支持图纸、纯图片文档,加密文件请先去除密码;

4.翻译完成后按页从主账号里扣费;

5.目前普通账户支持一条翻译通道(即只能同时进行一个文件的上传翻译),(如有更高需求请联系销售);
 * uploadTranslate.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$filePath = __DIR__.'/file/1746-5354-8-1-53.pdf'; //文档路径

$params = [
    'from' => '文件的源语言',
    'to' => '文件的目标语言',
];

try {
    $result = $dispatch->uploadTranslate($params, $filePath);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}

                                    
上传文件检测页数示例代码
<?php
/**
 * 上传文件检测页数
1.上传格式:pdf、Microsoft Office(doc、docx、dot、dotx、dotm、docm、xml、odt)、WPS Office(wps、wpt)、xls、xlsx、et、ett、ppt、pptx、dps、dpt、txt、rtf

2.上传文件最大50M(如有更高需求请联系销售)

3.不支持图纸、纯图片文档,加密文件请先去除密码

4.该功能需联系客服开通

调用说明:请求方式:post, file参数请以 multipart/form-data 方式的表单 POST 提交
 * detectDocPage.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$filePath = __DIR__.'/file/1746-5354-8-1-53.pdf'; //文档路径

$params = [
    'excelMode' => 0, // 0:只翻译当前打开sheet(默认),1:翻译全部sheet(页数按全部sheet字符数来计算)
];

try {
    $result = $dispatch->detectDocPage($filePath);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}


                                    
检测页数文件提交翻译示例代码
<?php
/**
 * 检测页数文件提交翻译
 * 同一个tid提交一次翻译即可。
 * submitForDetectDoc.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'from' => '文件的源语言',
    'to' => '文件的目标语言',
    'tid' => '检测文档页数接口返回的tid', // 检测文档页数接口返回的tid
];

try {
    $result = $dispatch->submitForDetectDoc($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}


                                    
获取进度示例代码
<?php
/**
 * 获取进度
 * 提交任务完成后可调用此接口实时查询翻译、转换进度或检测页数进度
 * queryTransProgress.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'tid' => '查询状态结果Id', // 查询状态结果Id
];

try {
    $result = $dispatch->queryTransProgress($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
下载示例代码
<?php
/**
 * 下载
1.判断Response Headers 中 detectLanguage 的值,若存在且不为空即为自动检测出的语言(可能为多种语言),仅供参考
2.判断Response Headers 中Content-Type 的值,若包含"application/octet-stream" 则可直接进行下载,否则即为以下返回值
 * downloadFile.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'tid' => '查询状态结果Id', // 查询状态结果Id
    'dtype' => '下载的文件类型',
//     下载的文件类型(new):
//      2:翻译后的pdf文件,支持格式:word、pdf、img。
//      3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
//      6:转换完成文档
];

try {
    $result = $dispatch->downloadFile($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}



                                    
文字翻译示例代码
<?php
/**
    * 文字翻译
1.待翻译文本字符长度不能超过2000;
2.语言方向:英、日、俄、韩、德、法、意 到中;中、日、俄、韩、德、法、意 到英
    * text.php
    * Create on 2023/3/24 17:51
    * Create by lihailiang@fanyigou.com
    */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'from' => '文件的源语言',
    'to' => '文件的目标语言',
    'text' => '待翻译文本,需UTF-8编码'
];

try {
    $result = $dispatch->text($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                        
                                    
格式转换示例代码
  • 1. 文档转换示例代码
  • 2. 获取进度示例代码
  • 3. 下载示例代码
文档转换示例代码
<?php
/**
 * 文档转换
接口说明:用户调用接口进行 源文件上传,上传完成后会自动进行转换,通过tid可以查询转换的进度等数据。注意:

1.上传格式:pdf、doc、docx、ppt、pptx、xls、xlsx、hwp、caj、ofd

2.上传文件最大50M (如有更高需求请联系销售)

3.加密文件请先去除密码

4.转换完成后按页从主账号里扣费

调用说明:请求方式:post, file参数请以 multipart/form-data 方式的表单 POST 提交
 * convert.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$filePath = __DIR__.'/file/1746-5354-8-1-53.pdf'; //文档路径

$params = array(
    'from' => '扫描件需设置语言', // 扫描件需设置语言
    'conversionFormat' => -1 // 文档转换类型
//    转换的目标格式(目前支持pdf到其它格式的转换(excel,ppt,word,ofd),及其它格式(excel,ppt,word,hwp,caj,ofd)到pdf的转换) -1:word;-3:excel;-6:pptx,-8:pdf,-9:ofd。
);

try {
    $result = $dispatch->convert($params, $filePath);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
获取进度示例代码
<?php
/**
 * 获取进度
 * 提交任务完成后可调用此接口实时查询翻译、转换进度或检测页数进度
 * queryTransProgress.php
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'tid' => '查询状态结果Id', // 查询状态结果Id
];

try {
    $result = $dispatch->queryTransProgress($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
下载示例代码
<?php
/**
 * 下载
1.判断Response Headers 中 detectLanguage 的值,若存在且不为空即为自动检测出的语言(可能为多种语言),仅供参考
2.判断Response Headers 中Content-Type 的值,若包含"application/octet-stream" 则可直接进行下载,否则即为以下返回值
 * downloadFile.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'tid' => '查询状态结果Id', // 查询状态结果Id
    'dtype' => '下载的文件类型',
//     下载的文件类型(new):
//      2:翻译后的pdf文件,支持格式:word、pdf、img。
//      3:翻译后的word文件(支持格式:word、pdf);ppt文件(支持格式:img、ppt);excel文件(支持格式:excel)
//      6:转换完成文档
];

try {
    $result = $dispatch->downloadFile($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
图片翻译示例代码
  • 1. 上传示例代码
  • 2. 获取进度示例代码
  • 3. 下载示例代码
图片上传示例代码
<?php
/**
 * 图片上传
接口说明:用户调用接口进行 源文件上传,上传完成后会自动进行翻译,通过tid可以查询翻译的进度等数据。注意:
1.上传格式:jpg、jpeg、png、bmp
2.上传文件最大4M
3.支持15*15 - 2048*2048px尺寸内
4.翻译完成后按页从主账号里扣费
调用说明:请求方式:post, file参数请以 multipart/form-data 方式的表单 POST 提交
 * uploadTranslateImage.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$filePath = __DIR__.'/file/WechatIMG263.png'; //文档路径

$params = [
    'from' => '文件的源语言',
    'to' => '文件的目标语言',
];

try {
    $result = $dispatch->uploadTranslateImage($params, $filePath);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
图片翻译获取进度示例代码
<?php
/**
 * 图片翻译获取进度
 * queryImageTransProgress.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'tid' => '查询状态结果Id', // 查询状态结果Id
];

try {
    $result = $dispatch->queryImageTransProgress($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}

                                    
图片翻译下载示例代码
<?php
/**
 * 图片翻译下载
 * 1.判断Response Headers 中Content-Type 的值,若包含"application/octet-stream" 则可直接进行下载,否则即为以下返回值
 * downloadImage.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params = [
    'tid' => '查询状态结果Id', // 查询状态结果Id
];

try {
    $result = $dispatch->downloadImage($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
OCR(图像识别)示例代码
<?php
/**
 * OCR(图像识别)
接口说明:用户调用接口进行 源文件上传,上传完成后会自动进行识别并返回数据。注意:
1.上传格式:jpg、jpeg、png、bmp
2.上传文件最大4M
3.支持15*15 - 8192*8192px尺寸内
4.翻译完成后按次数从主账号里扣费
 * ocrUploadImage.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$filePath = __DIR__.'/file/WechatIMG263.png'; //文档路径

$params = [
    'from' => '文件的源语言',
];

try {
    $result = $dispatch->ocrUploadImage($params, $filePath);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
语音识别示例代码
  • 1. 语音识别获取链接标识接口示例代码
  • 2. 连接webscoket进行语音识别翻译示例代码
  • 3. 获取译文音频链接接口示例代码
语音识别获取链接标识接口示例代码
<?php
/**
 * 语音识别获取链接标识接口
 * getConnectionId.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'from' => '源语言(目前支持中文或者英文)',
    'to'   => '目标语言(目前支持英文或者中文)',
];

try {
    $result = $dispatch->getConnectionId($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
连接webscoket进行语音识别翻译示例代码
<?php
/**
 * 连接webscoket进行语音识别翻译
1.语音识别获取链接标识接口与当前的websocket传入的appid必须一致
2.connectionId的只有二十分钟有效期
3.connenctionId连接成功并发送音频数据后不能再使用当前connectionId进行二次连接
 * getTransAudioLink.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\WebSocket;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$connectionId = ''; // {connectionId}: 获取connectionId进行websocket连接,通过语音识别获取链接标识接口获取
$filePath = '音频路径';

// 初始化websocket连接
$socket = new WebSocket($appKey, $secKey);
$client = $socket->connection($connectionId);

// 模拟发送流式数据
send_data($client, $filePath, 6400);

function send_data($client, $path, $step)
{
    if (!file_exists($path)) {
        echo "file not exist";
        return;
    }
    $file = fopen($path, "r");
    // 发送消息的时间
    $pre_timestamp = return_mills_timestamp();
    while (!feof($file)) {
        $cur_timestamp = return_mills_timestamp();
        // 流式数据传输间隔推荐每6400bytes间隔200ms
        if ($cur_timestamp - $pre_timestamp < 200) {
            continue;
        }
        $pre_timestamp = $cur_timestamp;
        $buffer = fread($file, $step);
        send_binary_message($client, $buffer);
    }
    send_binary_message($client, "{\"end\": \"true\"}");
}

// 获取毫秒级时间戳
function return_mills_timestamp(): float
{
    $micrometer = microtime(true);
    return round($micrometer * 1000);
}


function send_binary_message($client, $message)
{
    $binary = pack("H*", bin2hex($message));
    $client->binary($binary);
    echo 'send binary message length: ' . strlen($binary) . "\n";
}
                                    
获取译文音频链接接口示例代码
<?php
/**
 * 获取译文音频链接接口
 * getTransAudioLink.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'recordId' => '音频文件翻译id',
];

try {
    $result = $dispatch->getTransAudioLink($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}


                                    
音频识别示例代码
  • 1. 音频文件上传接口示例代码
  • 2. 音频翻译任务查询接口示例代码
  • 3. 音频下载译文链接接口示例代码
音频文件上传接口示例代码
<?php
/**
 * 音频文件上传接口
请求方式:post(file参数请以 multipart/form-data 方式的表单 POST 提交)
语音识别翻译支持音频格式:
1.pcm(pcm_s16le)、wav音频格式文件;
2.文件大小仅支持10min、10M以内文件;
3.采样率为16000,比特率为16bit;
4.单声道;
 * voiceAudioUpload.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$voicePath = __DIR__.'/file/test.wav'; //文档路径

$params = [
    'from' => '源语言(目前支持中文或者英文)',
    'to' => '目标语言(目前支持英文或者中文)',
];

try {
    $result = $dispatch->voiceAudioUpload($params, $voicePath);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
音频翻译任务查询接口示例代码
<?php
/**
 * 音频翻译任务查询接口
 * voiceAudioQueryProgress.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'recordId' => '音频文件翻译id',
];

try {
    $result = $dispatch->voiceAudioQueryProgress($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
音频下载译文链接接口示例代码
<?php
/**
 * 音频下载译文链接接口
 * voiceAudioDownload.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'recordId' => '音频文件翻译id',
];

try {
    $result = $dispatch->voiceAudioDownload($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
词典示例代码
<?php
/**
 * 词典
 * dictSearch.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'word' => '搜索词', // 词语,小于等于15个字符
];

try {
    $result = $dispatch->dictSearch($params);
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    
获取账户信息示例代码
<?php
/**
 * 获取账户信息
 * getAccount.php
 * Create on 2023/3/24 17:51
 * Create by lihailiang@fanyigou.com
 */
include_once __DIR__.'/../vendor/autoload.php';

use Fanyigou\ApiSdkPhp\Dispatch;
use Fanyigou\ApiSdkPhp\DispatchException;

$appKey = '您的应用ID';
$secKey = '您的密钥';

$dispatch = new Dispatch(['app_key' => $appKey, 'sec_key' => $secKey]);

$params   = [
    'type' => 1, //资源包类型 1.文档翻译 2.文字翻译 3.图片翻译 4.格式转换
];

try {
    $result = $dispatch->getAccount();
    print_r($result);
} catch (DispatchException $e) {
    print_r($e->getMessage());
}
                                    

PYTHON-SDK调用说明

环境说明

1.运行环境 python3.x

2.调用前需安装第三方环境

pip install requests    
pip install websockets (语音识别翻译接口需要此环境,不用可不安装)
                                    
接口说明

1.account.py (获取账户信息)

2.audio_trans.py (音频识别翻译)

3.dict_search.py (词典)

4.doc_convert.py (文档转换)

5.doc_convert.py (文档翻译)

6.image_trans.py (图片翻译)

7.ocr.py (ocr识别)

8.text_trans.py (文字翻译)

9.voice_trans.py (语音识别翻译)

操作步骤
1.安装
pip install qingxun-openapi-python-sdk
2.引用
import TranslateApi

只引用文字翻译:

from TranslateApi.text_trans import trans
                                    
3.调用方式(参考下方示例代码)
示例代码
#引用api库
import TranslateApi

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
fromLang = "源语言"
toLang = "目标语言"
filepath = "本机上需要上传翻译的文件地址"
filename = "给上传的文件取一个名字吧"

#调用需要的方法(当前按方法是上传并翻译接口)
uploadTranslateres = TranslateApi.document_translation.uploadTranslate(ip, appid, privatekey, fromLang, toLang, filepath, filename)

#文档上传有四个追加参数
# industryId   行业代码   int    见行业列表  否
# transImg 文档内图片翻译    int    0:不翻译文档内图片(默认),1:翻译文档内图片。目前支持中、英、日、韩的文档内图片翻译。(如有需要请联系销售开通) 否
# excelMode    指定excel翻译模式    int    0:只翻译当前打开sheet(默认),1:翻译全部sheet(页数按全部sheet字符数来计算)   否
# bilingualControl 指定翻译模式 int    0:译文单独为一个文档(默认),1:双语对照(原文和译文在一个文档) 否
# 可以在参数后边用(industryId = 0 ,transImg=0 , excelMode = 0,bilingualControl=0)进行追加

# 追加示例(详情参数请查看开放平台)
res = TranslateApi.document_translation.uploadTranslate(fromLang,toLang,filepath,filename,industryId = 0 ,transImg=0 , excelMode = 0,bilingualControl=0)

#打印结果
print(res)

# 返回示例
# {'msg': '请求成功', 'code': 100, 'data': {'tid': tid}}
# 查询进度接口
# res = qxkjapi.queryTransProgress("tid")
# 文档下载接口
# res = qxkjapi.downloadFile("tid","3")

# 参数详情请查看开放平台文档
"http://open.qingxun.com/filecore.html"

                                    
文档翻译示例代码
  • 1. 文档翻译示例代码
  • 2. 文件上传示例代码
  • 3. 获取进度示例代码
  • 4. 下载示例代码
  • 5. 上传文件检测页数示例代码
  • 6. 检测页数文件提交翻译示例代码
文档翻译示例代码
ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
fromLang = "源语言"
toLang = "目标语言"
filepath = "本机上需要上传翻译的文件地址"
filename = "给上传的文件取一个名字吧"
                                    
文件上传示例代码
from TranslateApi.document_translation import uploadTranslate

uploadTranslateres = uploadTranslate(ip,appid,privatekey, fromLang, toLang, filepath, filename)
                                    
获取进度示例代码
from TranslateApi.document_translation import queryTransProgress

tid = "调用uploadTranslate获取的tid"
queryTransProgressres = queryTransProgress(ip,appid,privatekey, tid)
                                    
下载示例代码
from TranslateApi.document_translation import downloadFile

dtype = "下载的文件类型(new)"
Filecontent = downloadFile(ip,appid,privatekey,tid, dtype)
with open("保存文件地址","wb") as w:
    w.write(Filecontent)
                                    
上传文件检测页数示例代码
from TranslateApi.document_translation import detectDocPage

detectDocPageres = detectDocPage(ip,appid,privatekey,filepath,filename)
                                
检测页数文件提交翻译示例代码
from TranslateApi.document_translation import submitForDetectDoc

submitForDetectDocres = submitForDetectDoc(ip,appid,privatekey,tid,fromLang,toLang)
                                
文字翻译示例代码
from TranslateApi.text_trans import trans

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"

fromLang = "源语言"
toLang = "目标语言"
text = "要翻译的文字"
print(trans(ip,appid,privatekey,fromLang,toLang,text))
                                    
格式转换示例代码
  • 1. 文档转换示例代码
  • 2. 获取进度示例代码
  • 3. 下载示例代码
文档转换示例代码
from TranslateApi.doc_convert import convert

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
filepath = "本机上需要上传翻译的文件地址"
filename = "给上传的文件取一个名字吧"
conversionFormat = "转换的目标格式(int类型)"

convertres = convert(ip,appid,privatekey,filepath,filename,conversionFormat)
print(convertres.json())
                                    
获取进度示例代码
from TranslateApi.document_translation import queryTransProgress

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
tid = "调用convert获取的tid"

queryTransProgressres = queryTransProgress(ip,appid,privatekey, tid)
                                    
下载示例代码
from TranslateApi.document_translation import downloadFile
    
ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
#6:转换完成文档
dtype = 6 
Filecontent = downloadFile(ip,appid,privatekey,tid, dtype)
with open("保存文件地址","wb") as w:
w.write(Filecontent)
                                    
图片翻译上传示例代码
  • 1. 图片翻译上传示例代码
  • 2. 查询图片翻译进度示例代码
  • 3. 图片翻译下载示例代码
图片翻译上传示例代码
from TranslateApi.image_trans import uploadTranslateImage

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"

fromLang = "源语言"
toLang = "目标语言"
filepath = "本机上需要上传翻译的文件地址"
filename = "给上传的文件取一个名字吧"

uploadTranslateImageres = uploadTranslateImage(ip,appid,privatekey,fromLang,toLang,filepath,filename)
print(uploadTranslateImageres)
                                    
查询图片翻译进度示例代码
from TranslateApi.image_trans import queryImageTransProgress

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
tid =  "调用uploadTranslateImage获取的tid"

queryImageTransProgressres = queryImageTransProgress(ip,appid,privatekey,tid)
print(queryImageTransProgressres)
                                    
图片翻译下载示例代码
from TranslateApi.image_trans import downloadImage
ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
tid = "调用uploadTranslateImage获取的tid"
Imagecontent = downloadImage(ip,appid,privatekey,tid)

with open("保存文件地址","wb") as w:
w.write(Imagecontent)
                                    
OCR(图像识别)示例代码
from TranslateApi.ocr import ocrUploadImage

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
fromLang = "源语言"
filepath = "本机上需要上传翻译的文件地址"
filename = "给上传的文件取一个名字吧"

ocrUploadImageres = ocrUploadImage(ip, appid,privatekey, fromLang, filepath, filename)
print(ocrUploadImageres)
                                    
语音识别翻译示例代码
  • 1. "获取ConnectionId"示例代码
  • 2. "连接webscoket进行语音识别翻译"示例代码
  • 3. 获取译文音频链接接口示例代码
"获取ConnectionId"示例代码
from TranslateApi.voice_trans import getConnectionId

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
fromLang = "源语言"
toLang = "目标语言"

getConnectionIdres = getConnectionId(ip,appid,privatekey,fromLang,toLang)
print(getConnectionIdres)
                                    
"连接webscoket进行语音识别翻译"示例代码
from TranslateApi.voice_trans import up_webscoket

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
filepath = "本机上需要上传翻译的文件地址"
connectionId = "调用getConnectionId接口获取id"

up_webscoketres = up_webscoket(ip,appid,privatekey,filepath,connectionId)
print(up_webscoketres)
                                    
获取译文音频链接接口示例代码
from TranslateApi.voice_trans import up_webscoket

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
filepath = "本机上需要上传翻译的文件地址"
connectionId = "调用getConnectionId接口获取id"

up_webscoketres = up_webscoket(ip,appid,privatekey,filepath,connectionId)
print(up_webscoketres)
                                    
音频识别翻译示例代码
  • 1. 音频文件上传接口示例代码
  • 2. 音频进度接口示例代码
  • 3. 音频下载译文链接接口示例代码
音频文件上传接口示例代码
from TranslateApi.audio_trans import audio_upload

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
fromLang = "源语言"
toLang = "目标语言"
filepath = "本机上需要上传翻译的文件地址"

audio_uploadres = audio_upload(ip,appid,privatekey,fromLang,toLang,filepath)
print(audio_uploadres.json())
                                    
音频进度接口示例代码
from TranslateApi.audio_trans import audio_queryProgress
ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
recordId = "调用音频文件上传接口audio_upload获取"

audio_queryProgressres = audio_queryProgress(ip,appid,privatekey,recordId)
print(audio_queryProgressres.json())
                                    
音频下载译文链接接口示例代码
from TranslateApi.audio_trans import audio_download
ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
recordId = "调用音频文件上传接口audio_upload获取"
audio_downloadres = audio_download(ip,appid,privatekey,recordId)
print(audio_downloadres.json())
                                    
词典示例代码
from TranslateApi.dict_search import findDict

ip = "服务ip 如 www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
word = "搜索词"

findDictres = findDict(ip,appid,privatekey,word)
print(findDictres.json())
                                    
获取账户信息示例代码
from TranslateApi.account import getAccount

ip = "www.fanyigou.com"
appid = "应用ID"
privatekey = "密钥"
Accountres = getAccount(ip,appid,privatekey)
print(Accountres.json())
                                    
购买的企业版有效期到期,到期后如何延长文件储存时长?
到期后数据我们会自动免费为您保存10日(到期时间顺延10日),若您有复购需求,10日内完成复购即可延长文件在线存储时长;若您无复购需求,建议您尽早下载文件保存到本地,避免文件丢失。
企业版有页数,为何翻译需要收费?
请登录翻译狗企业版(网址:https://enterprise.fanyigou.com/),再次尝试。
文件翻译后出现乱码?
翻译文件乱码问题出现原因主要为原文件加密,上传翻译时未对文件解密,请解密文件后重试。
翻译狗企业版与个人版有何区别?
翻译狗企业版提供项目管理功能,可创建多个子账号共同使用,同时提供机器辅助翻译CAT功能,用户可在线校对译文,提高翻译准确性。
翻译狗企业套餐有效期如何计算?套餐内页数有效期如何计算?
购买的企业版套餐有效期,以不同套餐开通的具体日期为开始时间,在套餐有效期内,套餐内页数均可使用,直至套餐到期;若套餐到期后您有未使用完的页数,将会自动清零,请根据需要尽早使用套餐内页数。
我是海外用户,我想使用企业版,应该如何登录?
海外用户可以使用邮箱进行账号注册登录。
如何更换企业账号管理员?
提交工单,工作日时间24小时内立即受理。
企业版子账号收不到短信验证码相关,无法登录该如何处理?
您的账号可能注册了翻译狗个人版账号,现提供给您2种登录方式:①使用您翻译狗个人版账号密码登录翻译狗企业版,系统会自动为您跳转页面;②登录时选择输入手机号/邮箱登录方式,点击忘记密码,完成验证登录。
使用企业版翻译完成后,文件为空白页面怎么办?
请拨打4001-868-556 或 提交工单 联系客服,客服将为您优先处理。
企业套餐页数怎么分配使用?
您购买的企业套餐页数,可以登录企业主账号,根据需要手动分配给子账号用户使用。
文字翻译空格是否算字符?
文字翻译空格也会被计算为字符。
接口调用支持哪些方式?是否提供demo案例?
接口调用支持标准HTTP请求调用,也可以基于SDK调用,目前提供的SDK有JAVA、PHP和PYTHON。请参考文档中心-SDK调用示例
翻译文档出错怎么办?
请拨打4001-868-556 或 提交工单 联系客服,客服将为您优先处理。
翻译狗本地部署服务是否支持离线部署?
翻译狗本地部署服务支持离线部署,目前翻译狗在线的语言共120+种,全部支持离线部署。
翻译狗本地部署服务采用离线部署方式,如何进行收费?
请拨打电话15381069892联系翻译狗商务获取报价信息。
系统需要维护升级及时间相关。
请拨打电话15381069892联系翻译狗团队。
翻译狗开放平台技术交流群 项目

扫一扫群二维码,立刻加入该群

群号:21120026830

客服
帮助
工单