> ## Documentation Index
> Fetch the complete documentation index at: https://www.qhaigc.net/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 音频转文本

> 将语音文件识别并转换为文本内容

## 功能说明

使用启航 AI 的语音识别（ASR）模型，快速准确地将音频文件转换为文本。

## 请求参数

| 名称                | 类型       | 必选 | 说明                             |
| :---------------- | :------- | :- | :----------------------------- |
| `model`           | `string` | 否  | 模型名称，默认为 `qhai-asr-lite`       |
| `file`            | `file`   | 是  | 待识别的音频文件（支持 mp3, wav, m4a 等格式） |
| `response_format` | `string` | 否  | 响应格式，默认为 `json`                |

## 调用示例

<CodeGroup>
  ```python Python theme={null}
  import openai

  client = openai.OpenAI(
      api_key="sk-your-api-key-here",
      base_url="https://api.qhaigc.net/v1"
  )

  audio_file = open("path/to/file.mp3", "rb")
  transcription = client.audio.transcriptions.create(
      model="qhai-asr-lite",
      file=audio_file
  )

  print(transcription.text)
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from 'openai';
  import fs from 'fs';

  const openai = new OpenAI({
    apiKey: 'sk-your-api-key-here',
    baseURL: 'https://api.qhaigc.net/v1'
  });

  async function main() {
    const transcription = await openai.audio.transcriptions.create({
      model: 'qhai-asr-lite',
      file: fs.createReadStream("path/to/file.mp3"),
    });

    console.log(transcription.text);
  }
  main();
  ```

  ```bash cURL theme={null}
  curl https://api.qhaigc.net/v1/audio/transcriptions \
    -H "Authorization: Bearer sk-your-api-key-here" \
    -F "model=qhai-asr-lite" \
    -F "file=@/path/to/file.mp3"
  ```
</CodeGroup>

## 返回结果

成功返回识别后的文本。

<CodeGroup>
  ```json 响应示例 theme={null}
  {
    "text": "你好，这是启航 AI 的语音识别服务测试。"
  }
  ```
</CodeGroup>

## 相关内容

* [文本转音频](/docs/api-reference/audio/speech)
* [模型列表](/docs/models#语音模型)


## OpenAPI

````yaml POST /v1/audio/transcriptions
openapi: 3.1.0
info:
  title: 启航 AI API
  version: 1.0.0
  description: 启航 AI API 文档，支持绘图、语音生成、视频生成、音乐生成等多种 AIGC 接口。
servers:
  - url: https://api.qhaigc.net
    description: 生产服务器
security:
  - bearerAuth: []
paths:
  /v1/audio/transcriptions:
    post:
      tags:
        - 语音识别
      summary: 音频转文本
      description: 将语音文件识别并转换为文本内容
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                model:
                  type: string
                file:
                  type: string
                  format: binary
                response_format:
                  type: string
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                type: object
                properties:
                  text:
                    type: string
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````