> ## Documentation Index
> Fetch the complete documentation index at: https://quwan-b8010aef.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 开天非流式语音识别

> 在 ModelHub 中使用开天 ASR 识别音频文件

# 开天非流式语音识别

通过 `POST /v1/asr` 提交完整音频文件。识别完成后，接口一次性返回文本结果。

## 可用模型

| 模型 |
| - |
| `ktian-asr-file-onnx` |

## 请求地址

```text theme={null}
POST https://model-api.skyengine.com.cn/v1/asr
```

请求 Header：

```text theme={null}
Authorization: Bearer <API-KEY>
Content-Type: application/json
```

## 使用音频 URL

`audio_url` 必须是平台能够直接访问的音频文件地址。以下示例提交 WAV 文件：

```bash cURL theme={null}
curl --request POST \
  --url https://model-api.skyengine.com.cn/v1/asr \
  --header 'Authorization: Bearer <API-KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "ktian-asr-file-onnx",
    "audio_url": "https://example.com/audio.wav"
  }'
```

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://model-api.skyengine.com.cn/v1/asr",
    headers={"Authorization": f"Bearer {os.environ['MODELHUB_API_KEY']}"},
    json={
        "model": "ktian-asr-file-onnx",
        "audio_url": "https://example.com/audio.wav",
    },
    timeout=120,
)
response.raise_for_status()
print(response.json()["text"])
```

```javascript JavaScript/Node.js theme={null}
const response = await fetch("https://model-api.skyengine.com.cn/v1/asr", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.MODELHUB_API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "ktian-asr-file-onnx",
    audio_url: "https://example.com/audio.wav"
  })
});

if (!response.ok) throw new Error(await response.text());
const result = await response.json();
console.log(result.text);
```

## 使用 Base64 音频

`audio_b64` 是完整音频文件字节的 Base64 字符串。不要添加 `data:audio/...;base64,` 前缀。

```python Python theme={null}
import base64
import os
import requests

with open("audio.wav", "rb") as audio_file:
    audio_b64 = base64.b64encode(audio_file.read()).decode("ascii")

response = requests.post(
    "https://model-api.skyengine.com.cn/v1/asr",
    headers={"Authorization": f"Bearer {os.environ['MODELHUB_API_KEY']}"},
    json={
        "model": "ktian-asr-file-onnx",
        "audio_b64": audio_b64,
    },
    timeout=120,
)
response.raise_for_status()
print(response.json()["text"])
```

## 请求参数

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `model` | string | 是 | 固定为 `ktian-asr-file-onnx`。 |
| `audio_url` | string | 条件必填 | 可公开访问的音频文件 URL；与 `audio_b64` 选择一种。 |
| `audio_b64` | string | 条件必填 | 完整音频文件字节的 Base64 字符串；与 `audio_url` 选择一种。 |

## 响应

```json theme={null}
{
  "text": "甚至出现交易几乎停滞的情况",
  "time_cost": {
    "asr": 138,
    "audio_download": 254
  }
}
```

| 字段 | 类型 | 说明 |
| - | - | - |
| `text` | string | 完整识别文本。 |
| `sentences` | object\[] | 分句结果；模型返回分句信息时出现。 |
| `sentences[].text` | string | 当前分句文本。 |
| `sentences[].start` | integer | 当前分句在音频中的开始时间，单位为毫秒。 |
| `sentences[].end` | integer | 当前分句在音频中的结束时间，单位为毫秒。 |
| `time_cost` | object | 本次请求各处理阶段的耗时，单位为毫秒。 |

> [!NOTE]
>
> 当前已验证 WAV 文件可通过 `audio_url` 或 `audio_b64` 提交。使用其他音频格式前，请先转换为 WAV。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.