Skip to content

Qwen3 ASR 语音识别

qwen3-asr-flash 通过 OpenAI 兼容的 Chat Completions 接口把音频转换为文本。音频放在 messages[].content[] 中。

请求地址

http
POST /v1/chat/completions

完整地址:

text
https://cubicspaces.cloud/v1/chat/completions

支持模型

模型说明
qwen3-asr-flash短音频语音识别

实际可用模型以账户权限和平台配置为准。

快速开始

音频可以使用公网可访问的 URL:

bash
curl https://cubicspaces.cloud/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3-asr-flash",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_audio",
            "input_audio": {
              "data": "https://example.com/audio.mp3"
            }
          }
        ]
      }
    ],
    "asr_options": {
      "language": "zh",
      "enable_itn": true
    },
    "stream": false
  }'

请求字段

字段类型必填说明
modelstring固定为 qwen3-asr-flash
messagesarrayOpenAI Chat 消息数组
messages[].rolestring音频消息使用 user
messages[].contentarray多模态内容数组
content[].typestring固定为 input_audio
content[].input_audio.datastring公网音频 URL 或 Base64 Data URI
asr_options.languagestring已知音频语言时可指定语言代码
asr_options.enable_itnboolean是否把口语数字转换为阿拉伯数字,默认 false
streamboolean是否使用 SSE 流式输出,默认 false
stream_options.include_usageboolean流式请求是否在末尾返回用量

asr_options 位于请求体顶层,不要放入 messagesinput_audio

常用语言代码包括:

  • zh:中文(普通话、四川话、闽南语、吴语)
  • yue:粤语
  • en:英语
  • ja:日语
  • dekorufrptarites
  • hiidthtrukvicsdafilfiismsnoplsv

如果音频包含多种语言或无法确定语言,不要设置 language

Base64 音频

本地文件需要转换为 Data URI:

python
import base64
from pathlib import Path

audio = Path("audio.mp3").read_bytes()
audio_data = "data:audio/mpeg;base64," + base64.b64encode(audio).decode()

然后把 audio_data 放入 input_audio.data

响应示例

识别文本位于 choices[0].message.content

json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "model": "qwen3-asr-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "欢迎使用 Cubicspaces。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 45,
    "completion_tokens": 12,
    "total_tokens": 57,
    "seconds": 1
  }
}
响应字段说明
choices[0].message.content语音识别文本
usage.prompt_tokens输入用量
usage.completion_tokens输出文本用量
usage.total_tokens总 Token 用量
usage.seconds输入音频时长,单位为秒

SDK 示例

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://cubicspaces.cloud/v1"
)

response = client.chat.completions.create(
    model="qwen3-asr-flash",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_audio",
                    "input_audio": {
                        "data": "https://example.com/audio.mp3"
                    }
                }
            ]
        }
    ],
    extra_body={
        "asr_options": {
            "language": "zh",
            "enable_itn": True
        }
    }
)

print(response.choices[0].message.content)
print(response.usage)
js
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://cubicspaces.cloud/v1"
});

const response = await client.chat.completions.create({
  model: "qwen3-asr-flash",
  messages: [
    {
      role: "user",
      content: [
        {
          type: "input_audio",
          input_audio: {
            data: "https://example.com/audio.mp3"
          }
        }
      ]
    }
  ],
  asr_options: {
    language: "zh",
    enable_itn: true
  }
});

console.log(response.choices[0].message.content);
console.log(response.usage);

流式输出

设置 stream: true 后,响应使用 OpenAI SSE 格式。文本片段位于 choices[0].delta.content。如需在末尾获取 usage.seconds,同时设置:

json
{
  "stream": true,
  "stream_options": {
    "include_usage": true
  }
}

最后一个包含 usage 的事件可能没有 choices,客户端应先判断数组是否为空。

限制与注意事项

  • 单次音频最长 5 分钟,文件最大 10 MB。
  • 音频 URL 必须能从公网直接访问,不能要求登录或使用仅本机可见的地址。
  • Base64 输入必须包含正确的 Data URI 前缀,例如 data:audio/mpeg;base64,
  • 当前接口返回识别文本,不返回句子级或词级时间戳。
  • 请使用 /v1/chat/completions

常见错误

模型不可用

确认 modelqwen3-asr-flash,并联系平台管理员确认账户权限。

无法读取音频

检查 URL 是否可以匿名访问,或改用 Base64 Data URI。确认音频未超过时长和文件大小限制。

请求体无效

确认 content 是数组,音频对象使用 type: "input_audio",并且 asr_options 位于请求体顶层。