API 目录

创建语音 gpt-4o-mini-tts

POST
/v1/audio/speech

创建语音:gpt-4o-mini-tts

使用 Vortap 的语音合成接口,可以将文本转换为音频文件。该接口兼容 OpenAI API 调用格式,适用于朗读、语音助手、有声内容生成等场景。

接口地址

POST https://www.vortapapi.com/v1/audio/speech

请求头

Header必填说明
Authorization使用 Bearer Token 进行鉴权,格式为 Bearer sk-***
Content-Type固定为 application/json

请求参数

参数类型必填说明
modelstring语音合成模型,例如 gpt-4o-mini-tts
inputstring需要转换为语音的文本内容
voicestring语音音色名称
response_formatstring返回音频格式,例如 mp3wavopusaacflacpcm
speednumber语速倍率,默认通常为 1.0

可用音色

常见可用音色包括:

  • alloy
  • ash
  • ballad
  • coral
  • echo
  • fable
  • nova
  • onyx
  • sage
  • shimmer

实际可用音色可能随模型版本更新而变化,请以接口返回和当前模型支持情况为准。

示例请求

curl https://www.vortapapi.com/v1/audio/speech \
  -H "Authorization: Bearer sk-***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "input": "你好,欢迎使用 Vortap 语音合成接口。",
    "voice": "alloy",
    "response_format": "mp3"
  }' \
  --output speech.mp3

Python 示例

import requests

url = "https://www.vortapapi.com/v1/audio/speech"

headers = {
    "Authorization": "Bearer sk-***",
    "Content-Type": "application/json",
}

payload = {
    "model": "gpt-4o-mini-tts",
    "input": "你好,欢迎使用 Vortap 语音合成接口。",
    "voice": "alloy",
    "response_format": "mp3",
}

response = requests.post(url, headers=headers, json=payload)

with open("speech.mp3", "wb") as f:
    f.write(response.content)

JavaScript 示例

const response = await fetch("https://www.vortapapi.com/v1/audio/speech", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sk-***",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-4o-mini-tts",
    input: "你好,欢迎使用 Vortap 语音合成接口。",
    voice: "alloy",
    response_format: "mp3"
  })
});

const arrayBuffer = await response.arrayBuffer();
await Bun.write("speech.mp3", arrayBuffer);

返回结果

接口成功时会直接返回音频二进制数据,而不是 JSON。请根据 response_format 参数将响应内容保存为对应格式的文件。

例如,当 response_formatmp3 时,可以将响应保存为:

speech.mp3

错误响应示例

当请求参数不正确、鉴权失败或模型不可用时,接口会返回 JSON 格式的错误信息。

{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

注意事项

  • input 应传入需要朗读的文本内容,文本过长时建议拆分后分别生成。
  • 返回内容是音频文件二进制流,客户端需要以二进制方式读取和保存。
  • 如果需要更高质量或不同风格的朗读效果,可以尝试切换 voice
  • speed 可用于调整语速,例如 0.8 表示更慢,1.2 表示更快。