API 參考
OpenAI TTS 文字轉語音
使用文字轉語音端點,在同一回應中接收結果。
01
概覽
使用文字轉語音端點,並從同一回應中讀取結果。
快速入門
- 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
- 傳送主體符合請求 Schema 的 POST 請求。
- 從成功的回應主體中讀取結果。
端點
- 基礎 URL
https://runapi.ai- API 版本
v1- 身份驗證
Authorization: Bearer YOUR_API_TOKEN
02
支援的模型
開啟模型頁面以查看當前定價、速率限制及商業用途詳情。
03
JSON 內容請求結構
僅傳送此端點宣告的欄位。
tts-12 個欄位
modelstring
必填
模型標識符。
textstring
必填
邊界值:
4096
tts-1-hd2 個欄位
modelstring
必填
模型標識符。
textstring
必填
邊界值:
4096
04
HTTP 200成功回應
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"audios": {
"items": {
"properties": {
"format": {
"type": "string"
},
"mime_type": {
"type": "string"
},
"size_bytes": {
"type": "integer"
},
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url",
"format",
"mime_type",
"size_bytes"
],
"type": "object",
"unevaluatedProperties": false
},
"type": "array"
},
"billing": {
"properties": {
"refund": {
"oneOf": [
{
"properties": {
"refunded_at": {
"type": "string"
}
},
"required": [
"refunded_at"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"reservation": {
"oneOf": [
{
"properties": {
"amount_cents": {
"type": "integer"
}
},
"required": [
"amount_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"settlement": {
"oneOf": [
{
"properties": {
"amount_micro_cents": {
"type": "integer"
},
"charged_amount_cents": {
"type": "integer"
}
},
"required": [
"charged_amount_cents",
"amount_micro_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
}
},
"required": [
"reservation",
"settlement",
"refund"
],
"type": "object",
"unevaluatedProperties": false
},
"id": {
"type": "string"
},
"status": {
"enum": [
"completed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"audios",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"audios": [
{
"format": "mp3",
"mime_type": "audio/mpeg",
"size_bytes": 128,
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "completed"
}
05
HTTP 401錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "Authentication required"
}
06
HTTP 400錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"oneOf": [
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
},
{
"properties": {
"error": {
"description": "人類可讀的驗證摘要。",
"type": "string"
},
"errors": {
"additionalProperties": {
"items": {
"type": "string"
},
"type": "array"
},
"description": "以公開請求欄位為鍵的驗證訊息,每個欄位對應一組人類可讀的字串陣列。",
"type": "object"
}
},
"required": [
"error",
"errors"
],
"type": "object",
"unevaluatedProperties": false
}
]
}
回應範例
JSON
{
"error": "model must be one of: tts-1, tts-1-hd"
}
07
HTTP 402錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "Insufficient balance"
}
08
HTTP 429錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "API key credit limit exceeded"
}
09
HTTP 409錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "The request uses features that are not supported for the selected model"
}
10
HTTP 429錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "Rate limit reached. Please retry later."
}
11
HTTP 503錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "Service under maintenance, please try again later"
}
12
HTTP 504錯誤
POST /api/v1/openai_tts/text_to_speech
回應結構
JSON
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
JSON
{
"error": "The request timed out"
}
13
已生成的程式碼範例
直接使用 cURL,或為您的語言安裝 SDK。每個範例均提交本參考中所示的已驗證請求。
安裝
Shell
pip install runapi-openai-tts
PYTHON
import os
from runapi.openai_tts import OpenaiTtsClient
client = OpenaiTtsClient(api_key=os.environ["RUNAPI_API_KEY"])
result = client.text_to_speech.run(
model="tts-1",
text="Welcome to RunAPI."
)