服务端 API/AI 能力/语音识别（ASR）/语音识别/流式语音识别
# 语音流式识别 (ASR)

语音流式接口，将整个音频文件分片进行传入模型。能够实时返回数据。建议每个音频分片的大小为 100-200ms

**注意事项**：单租户限流：20 路（一个 stream_id 称为一路会话），同租户下的应用没有限流，共享本租户的 20路限流。免费版不支持调用。

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/speech_to_text/v1/speech/stream_recognize
HTTP Method | POST
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用** | 语音识别(speech_to_text:speech)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer t-7f1bcd13fc57d46bac21793a18e560"<br>[了解更多：如何选择与获取 access token](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | 是 | **固定值**："application/json; charset=utf-8"

### 请求体

名称 | 类型 | 必填 | 描述
---|---|---|---
speech | speech | 是 | 语音资源
speech | string | 否 | pcm格式音频文件（文件识别）或音频分片（流式识别）经base64编码后的内容<br>**示例值**："PdmrfE267Cd/Z9KpmNFh71A2PSJZxSp7+8upCg=="
config | stream_config | 是 | 配置属性
stream_id | string | 是 | 仅包含字母数字和下划线的 16 位字符串作为同一数据流的标识，用户生成<br>**示例值**："asd1234567890ddd"
sequence_id | int | 是 | 数据流分片的序号，序号从 0 开始，每次请求递增 1<br>**示例值**：1
action | int | 是 | 数据流标记：1 首包，2 正常结束，等待结果返回，3 中断数据流不返回最终结果<br>**示例值**：1
format | string | 是 | 语音格式，目前仅支持：pcm<br>**示例值**："pcm"
engine_type | string | 是 | 引擎类型，目前仅支持：16k_auto 中英混合<br>**示例值**："16k_auto"

### 请求体示例
```json
{
    "speech": {
        "speech": "PdmrfE267Cd/Z9KpmNFh71A2PSJZxSp7+8upCg=="
    },
    "config": {
        "stream_id": "asd1234567890ddd",
        "sequence_id": 1,
        "action": 1,
        "format": "pcm",
        "engine_type": "16k_auto"
    }
}
```

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
stream_id | string | 16 位 String 随机串作为同一数据流的标识
sequence_id | int | 数据流分片的序号，序号从 0 开始，每次请求递增 1
recognition_text | string | 语音流识别后的文本信息

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "stream_id": "asd1234567890ddd",
        "sequence_id": 1,
        "recognition_text": "你好，尝试使用一下Lark吧"
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 1610101 | invalid param | 参数错误，参考文档检查输入参数
500 | 1610102 | network anomaly | 后端服务异常或网络异常，可重新请求

