接口描述
本接口服务采用 WebSocket 协议,对音视频能力提供接口。
音频属性要求
采样率:16000Hz或8000Hz
采样精度:16bits (s16le)
声道:单声道(mono)
音频格式: pcm
注意:
在识别过程中,客户端持续上传 binary message 到后台,内容为音频流二进制数据。建议每40ms 发送40ms 时长(即1:1实时率)的数据包,对应 PCM 大小为:8k 采样率640字节,16k 采样率1280字节。音频发送速率过快超过1:1实时率或者音频数据包之间发送间隔超过6秒,可能导致引擎出错,后台将返回错误并主动断开连接。
服务地址
现网正式地址:
ws://twetalk.iotcloud.tencentdevices.com
wss://twetalk.iotcloud.tencentdevices.com
体验测试地址:
ws://183.194.204.105:8080
token: XXXXXXXX, 请联系腾讯云产品经理提供,token 用于鉴权,获得 token 后请妥善保管。
appID: 单击 账号中心控制台 获取 APPID。
接口定义
同传翻译 V1(WebSocket) [token 鉴权]
地址:wss://twetalk.iotcloud.tencentdevices.com/ws-voice-translate
1. client 第一条消息:send 初始设置参数:
{"is_tts_stream": false, // TTS 流式输出"disable_tts": false, // 是否禁用TTS"lang_source": "zh", // 单向翻译,设置源语言,默认 zh"lang_target": "en", // 单向翻译,设置翻译的目标语言, 默认en"request_id": "7dd31c36-b3e9-4f6c-8c10-92f5f4793cdb","token": "XXXXXX" // 联系产品经理获取token}
2. client 后续上传音频数据:16K 单声道,16bit PCM 二进制流式数据。

3.
server 下行数据为16K 单声道
,16bit PCM 音频二进制流式数据,直接播放即可。返回原文示例:
{"code": 0,"msg": "success","original": "","original_detail": {"slice_type": 2,"index": 1,"voice_text_str": "Please tell a joke."}}
返回译文示例:
{"code": 0,"msg": "success","translation": "请讲个笑话。","index": 1}
说明:
V1 版本原文与译文分两次返回,返回结果的结构与 ASR result 结构一致。
返回结果参数说明:
参数 | 说明 |
code | 0:表示正常(正常情况会省略)。 非0:表示异常。 |
msg | 错误信息。 当 code 非0时,该字段输出 success。 当 code 非0时,该字段显示错误信息,方便 debug。 |
original_detail | ASR 识别的结果。 |
slice_type | 识别结果类型: 0:一段话开始识别。 1:一段话识别中,voice_text_str 为非稳态结果(该段识别结果还可能变化)。 2:一段话识别结束,voice_text_str 为稳态结果(该段识别结果不再变化)。 |
index | 当前一段话结果在整个音频流中的序号,从0开始逐句递增。示例值:0 |
voice_text_str | 当前一段话文本结果,编码为 UTF8。 |
translation | 译文。 |
同传翻译 V2(WebSocket) [token 鉴权]
地址:wss://twetalk.iotcloud.tencentdevices.com/v2/ws-voice-translate
1. client 第一条消息:send 初始设置参数:
{"is_tts_stream": false, // TTS 流式输出"enable_tts": false, // 是否启用TTS"lang_source": "zh", // 单向翻译,设置源语言,默认 zh"lang_target": "en", // 单向翻译,设置翻译的目标语言, 默认en"request_id": "7dd31c36-b3e9-4f6c-8c10-92f5f4793cdb","token": "XXXXXX" // 联系产品经理获取 token}
2. client 后续上传音频数据:16K 单声道,16bit PCM 二进制流式数据

返回的结果:
{"code": 0,"msg": "success","translation": "","original_detail": {"slice_type": 2,"index": 1,"voice_text_str": "Please tell a joke."}}
说明:
V2版本原文与译文在一起返回。
参数 | 说明 |
code | 0:表示正常(正常情况会省略)。 非0:表示异常。 |
msg | 错误信息。 当 code 非0时,该字段输出 success。 当 code 非0时,该字段显示错误信息,方便 debug。 |
translation | 翻译后的结果。 |
original_detail | ASR 识别的结果。 |
index | 当前一段话结果在整个音频流中的序号,从0开始逐句递增。示例值:0 |
slice_type | 识别结果类型: 0:一段话开始识别。 1:一段话识别中,voice_text_str 为非稳态结果(该段识别结果还可能变化)。 2:一段话识别结束,voice_text_str 为稳态结果(该段识别结果不再变化)。 |
voice_text_str | 当前一段话文本结果,编码为 UTF8。 |
TTS 译文语音 PCM 开启或禁用,灵活控制。
App Send 控制信令(发送方式类似 ws 连接建立时的第一条消息),server 无返回:
{"enable_tts": false, // 是否启用TTS. true:启用。false:禁用}
说明:
1. 音频 pcm 数据格式与V1接口相同,16K 单声道,16bit PCM 音频二进制。
2. 只有稳态的译文才会进行 TTS 返回。
3. 如果是弱网环境,建议按 ws 规范发送心跳 ping 包探测保活,主动重连。
心跳发送与接收
发送:{"ping":"xxxxx"}返回:{"pong":"xxxxx"}
说明:
心跳发送: xxxxx 为上报携带的数据,可以为时间戳或其他格式。示例如下:
发送:{"ping":"2025-07-07 15:33:49"}返回:{"pong":"2025-07-07 15:33:49"}
ASR 精转中文/英文 (WebSocket) [appid 白名单鉴权]
1. 握手阶段
地址: wss://twetalk.iotcloud.tencentdevices.com/asr/v2/<appid>?engine_model_type=iot_16k_zh&voice_format=1
参数 | 是否必填 | 说明 |
appid | 是 | |
voice_format | 否 | 语音编码方式。(选填) 默认值为1 。 1:pcm |
engine_model_type | 是 | 模型。 iot_16k_zh: 中文 iot_16k_en: 英文 iot_16k_it: 意大利语 iot_16k_ru: 俄语 iot_16K_ja: 日语 |
握手结果返回:客户端发起连接请求后,后台建立连接并进行签名校验,校验成功则返回 code 值为0的确认消息表示握手成功;如果校验失败,后台返回 code 为非0值的消息并断开连接。
{"code":0,"message":"success"} //校验成功{"code":-1,"message":"auth error"} //校验失败
2. 上传音频数据
在识别过程中,客户端持续上传 binary message 到后台,内容为音频流二进制数据,16K 单声道,16bit PCM 二进制流式数据。建议每40ms 发送40ms 时长(即1:1实时率)的数据包,对应 PCM 大小为:8k 采样率640字节,16k 采样率1280字节。音频发送速率过快超过1:1实时率或者音频数据包之间发送间隔超过6秒,可能导致引擎出错,后台将返回错误并主动断开连接。详细参见 同传翻译 PCM 发送。
server 下行数据JSON 格式:识别结果
{"code": 0,"message": "","final":0,"result": {"slice_type": 2,"index": 3,"voice_text_str": "可以讲个笑话吗","start_time": 7966,"end_time": 8666}}
参数 | 说明 |
code | 0:表示正常(正常情况会省略)。 非0:表示异常。 |
message | 错误信息(正常情况会省略)。 当 code 为0时,该字段为空。 当 code 非0时,该字段显示错误信息,方便 debug。 |
final | 该字段返回1时表示音频流全部识别结束。 0:表示正在识别中。 |
result | ASR 识别的结果。 |
index | 当前一段话结果在整个音频流中的序号,从0开始逐句递增。示例值:0 |
slice_type | 识别结果类型: 0:一段话开始识别 1:一段话识别中,voice_text_str 为非稳态结果(该段识别结果还可能变化) 2:一段话识别结束,voice_text_str 为稳态结果(该段识别结果不再变化) |
voice_text_str | 当前一段话文本结果,编码为 UTF-8。 |
start_time | 当前一段话结果在整个音频流中的起始时间(ms)。 |
end_time | 当前一段话结果在整个音频流中的结束时间(ms)。 |
摘要接口(HTTP) [token 鉴权]
curl --location 'https://twetalk.iotcloud.tencentdevices.com/api' \\--header 'Authorization: Bearer xxxxxx' \\--header 'Action: IotTextSummary' \\--header 'Content-Type: application/json' \\--data '{"prompt": """stream": false,"request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32","text":"这是一个测试摘要内容。"}'
请求 Header 参数说明:
参数 | 说明 |
Authorization | 认证信息。请联系腾讯云产品经理提供,获得认证信息后请妥善保管。 示例值:Bearer sk-xxxxx |
Action | 固定值: IotTextSummary ,必填。 |
Content-Type | 固定值: application/json |
请求 body 参数说明:
参数 | 说明 |
prompt | 提示词(流式返回场景该参数会生效,非流式场景使用预设的提示词)。 |
stream | 是否流式返回。 true false |
text | 摘要原始文本。 |
返回参数示例:
{"code":0, "err_msg":"", "summary":"这是一个测试","is_finish": false,"request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}{"code":0, "err_msg":"", "summary":"这是一个测试摘要内容。","is_finish": true,"request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}
异常返回示例:
{"code":-1,"err_msg":"Invalid Token"} //token 错误{"code":-1,"err_msg":"Invalid Action header"} //Action 错误
参数 | 说明 |
code | 0:表示正常返回。 非0:表示返回异常。 |
err_msg | 异常情况的错误说明,方便 debug。 |
summary | 摘要内容。 |
is_finish | SSE 流式返回时,摘要是否结束的标识。 true 表示摘要结束。 |
request_id | 请求 ID,方便 debug。 |
非流式示例
curl --location 'https://twetalk.iotcloud.tencentdevices.com/api' \\--header 'Authorization: Bearer xxxxxx' \\--header 'Action: IotTextSummary' \\--header 'Content-Type: text/plain' \\--data '{"stream": false,"request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32","text":"这是一个测试摘要内容。"}'
参数 | 说明 |
Authorization | 认证信息。请联系腾讯云产品经理提供,获得认证信息后请妥善保管。 示例值:Bearer sk-xxxxx |
Action | 固定值: IotTextSummary ,必填。 |
Content-Type | 固定值: text/plain |
stream | 是否流式返回。固定值: false |
request_id | 请求 ID,方便 debug。 |
text | 摘要原始文本。 |
返回示例:
{"code": 0,"err_msg": "","summary": "摘要内容","request_id": "4793e51c-b367-45cc-a992-18fd5dff7c32"}
参数 | 说明 |
code | 0:表示正常返回。 非0:表示返回异常。 |
err_msg | 异常情况的错误说明,方便 debug。 |
summary | 摘要内容。 |
request_id | 请求 ID,方便 debug。 |
SSE 流式示例
curl --location 'https://twetalk.iotcloud.tencentdevices.com/api' \\--header 'Authorization: Bearer xxxxxx' \\--header 'Action: IotTextSummary' \\--header 'Content-Type: text/plain' \\--data '{"prompt": "根据输入生成简单的一句话摘要,50字以内","stream": true,"request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32","text":"这是一个测试摘要内容。"}'
参数 | 说明 |
Authorization | 认证信息。请联系腾讯云产品经理提供,获得认证信息后请妥善保管。 示例值:Bearer sk-xxxxx |
Action | 固定值: IotTextSummary ,必填。 |
Content-Type | 固定值: text/plain |
stream | 是否流式返回。固定值: true |
request_id | 请求 ID,方便 debug。 |
text | 摘要原始文本。 |
返回示例:
data: {"code":0, "err_msg":"", "summary":"这是", "is_finish": false, "request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}data: {"code":0, "err_msg":"", "summary":"一个", "is_finish": false, "request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}data: {"code":0, "err_msg":"", "summary":"测试", "is_finish": false, "request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}data: {"code":0, "err_msg":"", "summary":"摘要", "is_finish": false, "request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}...data: {"code":0, "err_msg":"", "summary":"", "is_finish": true, "request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}\\n\\n
参数 | 说明 |
code | 0:表示正常返回。 非0:表示返回异常。 |
err_msg | 异常情况的错误说明,方便 debug。 |
summary | 摘要内容。 |
is_finish | SSE 流式返回时,摘要是否结束的标识。 true 表示摘要结束。 |
request_id | 请求 ID,方便 debug。 |
翻译接口(HTTP) [token 鉴权]
curl --location 'https://twetalk.iotcloud.tencentdevices.com/api' \\--header 'Authorization: Bearer xxxxxx' \\--header 'Action: IotTranslate' \\--header 'Content-Type: application/json' \\--data '{"source": "zh","target": "en","text":"这是一个待翻译的文本","request_id": "89971c46-79b2-44aa-bdc3-b4b944a48da3","stream": false}'
请求 Header 参数说明:
参数 | 说明 |
Authorization | 认证信息。请联系腾讯云产品经理提供,获得认证信息后请妥善保管。 示例值:Bearer sk-xxxxx |
Action | 固定值: IotTextSummary ,必填。 |
Content-Type | 固定值: application/json |
请求 body 参数说明:
参数 | 说明 |
source | 源语言。 |
target | 目标语言。 |
stream | 是否流式返回。 true false |
text | 待翻译的原始文本。 |
支持的语言列表:
代码 | 语言 | 代码 | 语言 |
zh | 简体中文 | ar | 阿拉伯语 |
yue | 粤语 | ko | 韩语 |
en | 英语 | th | 泰语 |
fr | 法语 | it | 意大利语 |
pt | 葡萄牙语 | de | 德语 |
es | 西班牙语 | vi | 越南语 |
ja | 日语 | ms | 马来语 |
tr | 土耳其语 | id | 印尼语 |
ru | 俄语 | - | - |
返回参数示例:
{"code":0, "err_msg":"", "data":"摘要内容","is_finish": true,"request_id":"4793e51c-b367-45cc-a992-18fd5dff7c32"}
异常返回示例:
{"code":-1,"err_msg":"Invalid Token"} //token 错误{"code":-1,"err_msg":"Invalid Action header"} //Action 错误
参数 | 类型 | 说明 |
code | int | 0:表示正常返回。 非0:表示返回异常。 |
err_msg | string | 异常情况的错误说明,方便 debug。 |
data | string | 摘要内容。 |
is_finish | bool | SSE 流式返回时,摘要是否结束的标识。 true 表示摘要结束。 |
request_id | string | 请求 ID,方便 debug。 |
非流式示例
请求示例:
curl --location 'https://twetalk.iotcloud.tencentdevices.com/api' \\--header 'Authorization: Bearer xxxxxxxx' \\--header 'Action: IotTranslate' \\--header 'Content-Type: application/json' \\--data '{"source": "zh","target": "en","text":"这是一个待翻译的文本","request_id": "89971c46-79b2-44aa-bdc3-b4b944a48da3","stream": false}'
请求 Header 参数说明:
参数 | 说明 |
Authorization | 认证信息。请联系腾讯云产品经理提供,获得认证信息后请妥善保管。 示例值:Bearer sk-xxxxx |
Action | 固定值: IotTextSummary ,必填。 |
Content-Type | 固定值: application/json |
请求 body 参数说明:
参数 | 说明 |
source | 源语言。 |
target | 目标语言。 |
text | 待翻译的原始文本。 |
request_id | 请求 ID,方便 debug。 |
stream | 是否流式返回。固定值:false |
返回示例:
{"code": 0,"err_msg": "success","data": "This is a text to be translated into English.","request_id": "89971c46-79b2-44aa-bdc3-b4b944a48da3"}
参数 | 类型 | 说明 |
code | int | 0:表示正常返回。 非0:表示返回异常。 |
err_msg | string | 异常情况的错误说明,方便 debug。 |
data | string | 摘要内容。 |
request_id | string | 请求 ID,方便 debug。 |
SSE 流式示例
curl --location 'https://twetalk.iotcloud.tencentdevices.com/api' \\--header 'Authorization: Bearer xxxxxxx' \\--header 'Action: IotTranslate' \\--header 'Content-Type: application/json' \\--data '{"source": "zh","target": "en","text":"这是一个待翻译的文本","request_id": "89971c46-79b2-44aa-bdc3-b4b944a48da3","stream": true}'
请求 Header 参数说明:
参数 | 说明 |
Authorization | 认证信息。请联系腾讯云产品经理提供,获得认证信息后请妥善保管。 示例值:Bearer sk-xxxxx |
Action | 固定值: IotTextSummary ,必填。 |
Content-Type | 固定值: application/json |
请求 body 参数说明:
参数 | 说明 |
source | 源语言。 |
target | 目标语言。 |
text | 待翻译的原始文本。 |
request_id | 请求 ID,方便 debug。 |
stream | 是否流式返回。固定值:true |
返回示例:
data: {"code":0, "err_msg":"", "data":"This", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" is", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" a", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" text", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" to", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" be", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" translated", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" into", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":" English", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}data: {"code":0, "err_msg":"", "data":".", "is_finish": false, "request_id":"89971c46-79b2-44aa-bdc3-b4b944a48da3"}
参数 | 说明 |
code | 0:表示正常返回。 非0:表示返回异常。 |
err_msg | 异常情况的错误说明,方便 debug。 |
data | 摘要内容。 |
is_finish | SSE 流式返回时,摘要是否结束的标识。 true 表示摘要结束。 |
request_id | 请求 ID,方便 debug。 |