88API88API
使用指南AI 應用API 文件幫助支援
音訊(Audio)

OpenAI 音訊格式

官方文件

📝 簡介

OpenAI 音訊 API 提供了三個主要功能:

  1. 文字轉語音(TTS) - 將文字轉換為自然的語音
  2. 語音轉文字(STT) - 將音訊轉錄為文字
  3. 音訊翻譯 - 將非英語音訊翻譯成英語文字

💡 請求示例

文字轉語音 ✅

curl https://88api.ai/v1/audio/speech \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "你好,世界!",
    "voice": "alloy"
  }' \
  --output speech.mp3

語音轉文字 ✅

curl https://88api.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F file="@/path/to/file/audio.mp3" \
  -F model="whisper-1"

響應示例:

{
  "text": "你好,世界!"
}

音訊翻譯 ✅

curl https://88api.ai/v1/audio/translations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F file="@/path/to/file/chinese.mp3" \
  -F model="whisper-1"

響應示例:

{
  "text": "Hello, world!"
}

📮 請求

端點

文字轉語音

POST /v1/audio/speech

將文字轉換為語音。

語音轉文字

POST /v1/audio/transcriptions

將音訊轉錄為輸入語言的文字。

音訊翻譯

POST /v1/audio/translations

將音訊翻譯為英語文字。

鑑權方法

在請求頭中包含以下內容進行 API 金鑰認證:

Authorization: Bearer $API_KEY

其中 $API_KEY 是您的 API 金鑰。

請求體引數

文字轉語音

model
  • 型別:字串
  • 必需:是
  • 可選值:tts-1, tts-1-hd
  • 說明:要使用的 TTS 模型
input
  • 型別:字串
  • 必需:是
  • 最大長度:4096 字元
  • 說明:要轉換為語音的文字
voice
  • 型別:字串
  • 必需:是
  • 可選值:alloy, echo, fable, onyx, nova, shimmer
  • 說明:生成語音時使用的聲音
response_format
  • 型別:字串
  • 必需:否
  • 預設值:mp3
  • 可選值:mp3, opus, aac, flac, wav, pcm
  • 說明:音訊輸出格式
speed
  • 型別:數字
  • 必需:否
  • 預設值:1.0
  • 範圍:0.25 - 4.0
  • 說明:生成語音的速度

語音轉文字

file
  • 型別:檔案
  • 必需:是
  • 支援格式:flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm
  • 說明:要轉錄的音訊檔案
model
  • 型別:字串
  • 必需:是
  • 當前僅支援:whisper-1
  • 說明:要使用的模型 ID
language
  • 型別:字串
  • 必需:否
  • 格式:ISO-639-1 (如 "en")
  • 說明:音訊的語言,提供可提高準確性
prompt
  • 型別:字串
  • 必需:否
  • 說明:用於指導模型風格或繼續前一段音訊的文字
response_format
  • 型別:字串
  • 必需:否
  • 預設值:json
  • 可選值:json, text, srt, verbose_json, vtt
  • 說明:輸出格式
temperature
  • 型別:數字
  • 必需:否
  • 預設值:0
  • 範圍:0 - 1
  • 說明:取樣溫度,較高的值使輸出更隨機
timestamp_granularities
  • 型別:陣列
  • 必需:否
  • 預設值:segment
  • 可選值:word, segment
  • 說明:轉錄的時間戳粒度

音訊翻譯

file
  • 型別:檔案
  • 必需:是
  • 支援格式:flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm
  • 說明:要翻譯的音訊檔案
model
  • 型別:字串
  • 必需:是
  • 當前僅支援:whisper-1
  • 說明:要使用的模型 ID
prompt
  • 型別:字串
  • 必需:否
  • 說明:用於指導模型風格的英文文字
response_format
  • 型別:字串
  • 必需:否
  • 預設值:json
  • 可選值:json, text, srt, verbose_json, vtt
  • 說明:輸出格式
temperature
  • 型別:數字
  • 必需:否
  • 預設值:0
  • 範圍:0 - 1
  • 說明:取樣溫度,較高的值使輸出更隨機

📥 響應

成功響應

文字轉語音

返回二進位制音訊檔案內容。

語音轉文字

基礎 JSON 格式
{
  "text": "轉錄的文字內容"
}
詳細 JSON 格式
{
  "task": "transcribe",
  "language": "english",
  "duration": 8.47,
  "text": "完整的轉錄文字",
  "segments": [
    {
      "id": 0,
      "seek": 0,
      "start": 0.0,
      "end": 3.32,
      "text": "分段的轉錄文字",
      "tokens": [50364, 440, 7534],
      "temperature": 0.0,
      "avg_logprob": -0.286,
      "compression_ratio": 1.236,
      "no_speech_prob": 0.009
    }
  ]
}

音訊翻譯

{
  "text": "翻譯後的英文文字"
}

錯誤響應

當請求出現問題時,API 將返回一個錯誤響應物件,HTTP 狀態碼在 4XX-5XX 範圍內。

常見錯誤狀態碼

  • 400 Bad Request: 請求引數無效
  • 401 Unauthorized: API 金鑰無效或未提供
  • 429 Too Many Requests: 超出 API 呼叫限制
  • 500 Internal Server Error: 伺服器內部錯誤

錯誤響應示例:

{
  "error": {
    "message": "檔案格式不支援",
    "type": "invalid_request_error",
    "param": "file",
    "code": "invalid_file_format"
  }
}