控制台

音频转写

将音频转换为文本,适合会议、访谈、语音消息和媒体内容处理。

Endpoint
POST/v1/audio/transcriptions
模型名称
moss-transcribe-1.0
  1. 创建 API Key

    进入 API Key 管理平台,创建 API Key,并保存为环境变量。不要把 API Key 写进客户端代码或提交到仓库。

    环境变量
    MOSS_API_KEY=<your_api_key_here>
  2. 准备请求输入

    准备一个本地音频文件,通过 multipart/form-data 将文件和转写参数一起提交;无需先调用文件上传接口。

    字段类型要求说明
    model: string必填

    当前填写 moss-transcribe-1.0。

    file: file必填

    通过 multipart/form-data 上传的本地音频文件。

    response_format: string可选

    转写结果格式,可选 json、text,默认 json。

    请求体
    model=moss-transcribe-1.0
    file=@./audio.mp3
    response_format=json

    对应的完整 cURL:

    curl -X POST "https://api.mosi.cn/v1/audio/transcriptions" \
      -H "Authorization: Bearer $MOSS_API_KEY" \
      -F "model=moss-transcribe-1.0" \
      -F "file=@./audio.mp3" \
      -F "response_format=json"
  3. 发起第一次请求

    向当前场景的 endpoint 发起请求。同步请求返回转写文本或说话人分段;异步请求会返回任务对象。

    请求示例
    curl https://api.mosi.cn/v1/audio/transcriptions \
      -H "Authorization: Bearer $MOSS_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "model": "moss-transcribe-1.0",
      "file_id": "<file_id>",
      "response_format": "json"
    }'
  4. 获取任务结果

    同步调用时,直接从响应中读取 text。传入 async=true 时会返回 task_id,可通过 GET /v1/audio/tasks/{task_id} 查询任务结果。

    查询转写任务
    curl https://api.mosi.cn/v1/audio/tasks/$TASK_ID \
      -H "Authorization: Bearer $MOSS_API_KEY"
  5. 验证成功

    成功标志:拿到转写文本。

下一步