Gemini TTS 文字轉語音
使用文字轉語音端點建立非同步 Task。
概覽
使用文字轉語音端點搭配支援的模型。使用回傳的 Task ID 擷取其狀態,或提供 callback_url 以接收下方說明的回呼通知。
快速入門
- 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
- 選擇支援的模型,並傳送本文符合該模型結構描述的 POST 請求。
- 儲存返回的任務 ID,然後輪詢直到終止狀態,或處理下方說明的回呼。
端點
- 基礎 URL
https://runapi.ai- API 版本
v1- 身分驗證
Authorization: Bearer YOUR_API_TOKEN
支援的模型
開啟模型頁面以查看目前的定價、速率限制及商業用途詳情。
請求綱要
欄位及允許值取決於所選模型。若提供 callback_url,其將接收下方記錄的 Task 交付內容。
gemini-2.5-pro-tts15 個欄位
callback_urlstring用於非同步通知的 Webhook URL。
dialogue_turnsarray非空的有序對話輪次,其說話者 id 須參照已設定的說話者。
項目數上限:1
dialogue_turns[].speaker_idstring與已設定的 speakers[].speaker_id 相符的識別碼。
dialogue_turns[].textstring口述文字,最多 10,000 個字元。
邊界:10000
modelstring模型 slug。
sample_contextstring整體傳遞情境與語氣。
scenestring場景與錄製環境。
speakersarray非空的說話者設定,具有唯一的 Speaker N 識別碼。
項目數上限:1
speakers[].accentstring說話者口音。
允許的值:Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestring選用的語音角色引導。
speakers[].pacestring說話者語速。
允許的值:Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstring以 Speaker N 格式表示的唯一識別碼。
speakers[].stylestring說話者表達風格。
允許的值:Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestring預設語音名稱。
允許的值:Achernar, Achird, Algenib, Algieba, Alnilam, Aoede, Autonoe, Callirrhoe, Charon, Despina, Enceladus, Erinome, Fenrir, Gacrux, Iapetus, Kore, Laomedeia, Leda, Orus, Puck, Pulcherrima, Rasalgethi, Sadachbia, Sadaltager, Schedar, Sulafat, Umbriel, Vindemiatrix, Zephyr, Zubenelgenubi
temperaturenumber取樣溫度。
預設值:1
範圍: 0 - 2
gemini-3.1-flash-tts15 個欄位
callback_urlstring用於非同步通知的 Webhook URL。
dialogue_turnsarray非空的有序對話輪次,其說話者 id 須參照已設定的說話者。
項目數上限:1
dialogue_turns[].speaker_idstring與已設定的 speakers[].speaker_id 相符的識別碼。
dialogue_turns[].textstring口述文字,最多 10,000 個字元。
邊界:10000
modelstring模型 slug。
sample_contextstring整體傳遞情境與語氣。
scenestring場景與錄製環境。
speakersarray非空的說話者設定,具有唯一的 Speaker N 識別碼。
項目數上限:1
speakers[].accentstring說話者口音。
允許的值:Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestring選用的語音角色引導。
speakers[].pacestring說話者語速。
允許的值:Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstring以 Speaker N 格式表示的唯一識別碼。
speakers[].stylestring說話者表達風格。
允許的值:Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestring預設語音名稱。
允許的值:Achernar, Achird, Algenib, Algieba, Alnilam, Aoede, Autonoe, Callirrhoe, Charon, Despina, Enceladus, Erinome, Fenrir, Gacrux, Iapetus, Kore, Laomedeia, Leda, Orus, Puck, Pulcherrima, Rasalgethi, Sadachbia, Sadaltager, Schedar, Sulafat, Umbriel, Vindemiatrix, Zephyr, Zubenelgenubi
temperaturenumber取樣溫度。
預設值:1
範圍: 0 - 2
建立接受記錄
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"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": [
"processing"
],
"type": "string"
},
"task_replayed": {
"type": "boolean"
}
},
"required": [
"id",
"status",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
輪詢處理中
GET /api/v1/gemini_tts/text_to_speech/:id
回應綱要
{
"properties": {
"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": [
"processing"
],
"type": "string"
}
},
"required": [
"id",
"status",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
輪詢已完成
GET /api/v1/gemini_tts/text_to_speech/:id
回應綱要
{
"properties": {
"audios": {
"items": {
"properties": {
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url"
],
"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
}
回應範例
{
"audios": [
{
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "completed"
}
輪詢失敗
GET /api/v1/gemini_tts/text_to_speech/:id
回應綱要
{
"properties": {
"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
},
"error": {
"type": "string"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
客戶回呼:已完成
POST callback_url
回應綱要
{
"properties": {
"audios": {
"items": {
"properties": {
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url"
],
"type": "object",
"unevaluatedProperties": false
},
"type": "array"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"completed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"audios"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"audios": [
{
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"id": "tsk_reference_demo",
"status": "completed"
}
客戶回呼:失敗
POST callback_url
回應綱要
{
"properties": {
"error": {
"oneOf": [
{
"type": "string"
},
{
"properties": {
"code": {
"type": "string"
},
"limit_cents": {
"type": "integer"
},
"message": {
"type": "string"
},
"reset_at": {
"format": "date-time",
"type": [
"string",
"null"
]
},
"used_cents": {
"type": "integer"
},
"window": {
"enum": [
"1h",
"1d",
"7d",
"daily",
"weekly",
"monthly",
"lifetime"
],
"type": "string"
}
},
"required": [
"code",
"message"
],
"type": "object",
"unevaluatedProperties": false
}
]
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Authentication required"
}
錯誤
GET /api/v1/gemini_tts/text_to_speech/:id
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Authentication required"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"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
}
]
}
回應範例
{
"error": "model must be one of: gemini-2.5-pro-tts, gemini-3.1-flash-tts"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Insufficient balance"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "API key credit limit exceeded"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "The request uses features that are not supported for the selected model"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Rate limit reached. Please retry later."
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Service under maintenance, please try again later"
}
錯誤
POST /api/v1/gemini_tts/text_to_speech
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "The request timed out"
}
錯誤
GET /api/v1/gemini_tts/text_to_speech/:id
回應綱要
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Task with id 'tsk_reference_demo' not found"
}
產生的程式碼範例
直接使用 cURL,或為您的程式語言安裝 SDK。每個範例均會提交本參考中所示的已驗證請求。
安裝
pip install runapi-gemini-tts
import os
from runapi.gemini_tts import GeminiTtsClient
client = GeminiTtsClient(api_key=os.environ["RUNAPI_API_KEY"])
task = client.text_to_speech.create(
model="gemini-2.5-pro-tts",
temperature=0.8,
scene="A quiet recording studio",
sample_context="Natural conversational delivery",
speakers=[{"speaker_id": "Speaker 1", "voice_name": "Fenrir", "audio_profile": "A calm host", "accent": "British (RP)", "style": "Newscaster", "pace": "Natural"}, {"speaker_id": "Speaker 2", "voice_name": "Puck", "accent": "American (Gen)", "style": "Empathetic", "pace": "Staccato"}],
dialogue_turns=[{"speaker_id": "Speaker 1", "text": "Welcome to the show."}, {"speaker_id": "Speaker 2", "text": "Thanks for having me."}]
)