Gemini TTS Testo in voce
Usa l'endpoint da testo a voce per creare un Task asincrono.
Panoramica
Usa l'endpoint da testo a voce con un modello supportato. Utilizza il Task ID restituito per recuperarne lo stato, oppure fornisci callback_url per le consegne documentate di seguito.
Avvio rapido
- Crea una Chiave API e impostala come RUNAPI_API_KEY.
- Scegli un modello supportato e invia una richiesta POST il cui corpo corrisponda allo schema di quel modello.
- Conserva l'ID attività restituito, quindi esegui il polling fino a uno stato terminale o gestisci i callback documentati di seguito.
Endpoint
- URL di base
https://runapi.ai- Versione API
v1- Autenticazione
Authorization: Bearer YOUR_API_TOKEN
Modelli supportati
Apri la pagina di un modello per i prezzi correnti, i limiti di frequenza e i dettagli sull'uso commerciale.
Schema della richiesta
I campi e i valori consentiti dipendono dal modello selezionato. Se fornito, callback_url riceve le notifiche Task documentate di seguito.
gemini-2.5-pro-tts15 campi
callback_urlstringURL webhook per notifiche asincrone.
dialogue_turnsarrayTurni di dialogo ordinati non vuoti i cui ID dei parlanti fanno riferimento ai parlanti configurati.
Limite elementi:1
dialogue_turns[].speaker_idstringIdentificatore corrispondente a un speakers[].speaker_id configurato.
dialogue_turns[].textstringTesto parlato, fino a 10.000 caratteri.
Vincolo:10000
modelstringSlug del modello.
sample_contextstringContesto di consegna generale e tono.
scenestringScena e ambiente di registrazione.
speakersarrayConfigurazioni dei parlanti non vuote con identificatori Speaker N univoci.
Limite elementi:1
speakers[].accentstringAccento del parlante.
Valori consentiti:Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestringGuida opzionale al carattere della voce.
speakers[].pacestringRitmo del parlante.
Valori consentiti:Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstringIdentificatore univoco nel formato Speaker N.
speakers[].stylestringStile di erogazione del parlante.
Valori consentiti:Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestringNome della voce predefinita.
Valori consentiti: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
temperaturenumberTemperatura di campionamento.
Predefinito:1
Intervallo: 0 - 2
gemini-3.1-flash-tts15 campi
callback_urlstringURL webhook per notifiche asincrone.
dialogue_turnsarrayTurni di dialogo ordinati non vuoti i cui ID dei parlanti fanno riferimento ai parlanti configurati.
Limite elementi:1
dialogue_turns[].speaker_idstringIdentificatore corrispondente a un speakers[].speaker_id configurato.
dialogue_turns[].textstringTesto parlato, fino a 10.000 caratteri.
Vincolo:10000
modelstringSlug del modello.
sample_contextstringContesto di consegna generale e tono.
scenestringScena e ambiente di registrazione.
speakersarrayConfigurazioni dei parlanti non vuote con identificatori Speaker N univoci.
Limite elementi:1
speakers[].accentstringAccento del parlante.
Valori consentiti:Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestringGuida opzionale al carattere della voce.
speakers[].pacestringRitmo del parlante.
Valori consentiti:Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstringIdentificatore univoco nel formato Speaker N.
speakers[].stylestringStile di erogazione del parlante.
Valori consentiti:Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestringNome della voce predefinita.
Valori consentiti: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
temperaturenumberTemperatura di campionamento.
Predefinito:1
Intervallo: 0 - 2
Crea accettazione
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"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
}
Esempio di risposta
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
Polling in elaborazione
GET /api/v1/gemini_tts/text_to_speech/:id
Schema della risposta
{
"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
}
Esempio di risposta
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
Polling completato
GET /api/v1/gemini_tts/text_to_speech/:id
Schema della risposta
{
"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
}
Esempio di risposta
{
"audios": [
{
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "completed"
}
Polling non riuscito
GET /api/v1/gemini_tts/text_to_speech/:id
Schema della risposta
{
"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
}
Esempio di risposta
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
Callback cliente: completato
POST callback_url
Schema della risposta
{
"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
}
Esempio di risposta
{
"audios": [
{
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"id": "tsk_reference_demo",
"status": "completed"
}
Callback cliente: fallito
POST callback_url
Schema della risposta
{
"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
}
Esempio di risposta
{
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "Authentication required"
}
Errori
GET /api/v1/gemini_tts/text_to_speech/:id
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "Authentication required"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"oneOf": [
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
},
{
"properties": {
"error": {
"description": "Riepilogo di convalida leggibile dall'utente.",
"type": "string"
},
"errors": {
"additionalProperties": {
"items": {
"type": "string"
},
"type": "array"
},
"description": "Messaggi di convalida con chiave per campo della richiesta pubblica, con un array di stringhe leggibili dall'utente per ogni campo.",
"type": "object"
}
},
"required": [
"error",
"errors"
],
"type": "object",
"unevaluatedProperties": false
}
]
}
Esempio di risposta
{
"error": "model must be one of: gemini-2.5-pro-tts, gemini-3.1-flash-tts"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "Insufficient balance"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "API key credit limit exceeded"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "The request uses features that are not supported for the selected model"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "Rate limit reached. Please retry later."
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "Service under maintenance, please try again later"
}
Errori
POST /api/v1/gemini_tts/text_to_speech
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "The request timed out"
}
Errori
GET /api/v1/gemini_tts/text_to_speech/:id
Schema della risposta
{
"properties": {
"error": {
"description": "Messaggio di errore leggibile.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Esempio di risposta
{
"error": "Task with id 'tsk_reference_demo' not found"
}
Esempi di Codice Generati
Usa cURL direttamente, oppure installa un SDK per il tuo linguaggio. Ogni esempio invia la richiesta validata mostrata in questo riferimento.
Installa
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."}]
)