Saltar al contenido
Referencia de API
Referencia de API

Gemini TTS Texto a voz

Usa el endpoint de texto a voz para crear una tarea asíncrona.

01

Descripción general

Usa el endpoint de texto a voz con un modelo compatible. Usa el ID de tarea devuelto para recuperar su estado, o proporciona callback_url para las entregas documentadas a continuación.

Inicio rápido

  1. Cree una Clave de API y establézcala como RUNAPI_API_KEY.
  2. Elija un modelo compatible y envíe una solicitud POST cuyo cuerpo coincida con el esquema de ese modelo.
  3. Almacena el ID de tarea devuelto, luego sondea hasta alcanzar un estado terminal o gestiona las devoluciones de llamada documentadas a continuación.

Endpoint

POST /api/v1/gemini_tts/text_to_speech
URL base
https://runapi.ai
Versión de la API
v1
Autenticación
Authorization: Bearer YOUR_API_TOKEN
02

Modelos compatibles

Abra una página de modelo para conocer los precios actuales, los límites de velocidad y los detalles de uso comercial.

03

Esquema de solicitud

Cuerpo JSON

Los campos y los valores permitidos dependen del modelo seleccionado. Cuando se proporciona, callback_url recibe las entregas de tareas documentadas a continuación.

gemini-2.5-pro-tts15 campos
callback_urlstring
Opcional

URL de webhook para notificaciones asíncronas.

dialogue_turnsarray
Obligatorio

Turnos de diálogo ordenados no vacíos cuyos identificadores de locutor hacen referencia a locutores configurados.

Límite de elementos: 1
dialogue_turns[].speaker_idstring
Obligatorio

Identificador que coincide con un speakers[].speaker_id configurado.

dialogue_turns[].textstring
Obligatorio

Texto hablado, de hasta 10 000 caracteres.

Límite: 10000
modelstring
Obligatorio

Identificador del modelo.

sample_contextstring
Opcional

Contexto general de entrega y tono.

scenestring
Opcional

Escena y entorno de grabación.

speakersarray
Obligatorio

Configuraciones de locutor no vacías con identificadores únicos de Locutor N.

Límite de elementos: 1
speakers[].accentstring
Opcional

Acento del locutor.

Valores permitidos: Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestring
Opcional

Guía opcional de carácter de voz.

speakers[].pacestring
Opcional

Ritmo del locutor.

Valores permitidos: Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstring
Obligatorio

Identificador único en formato Speaker N.

speakers[].stylestring
Opcional

Estilo de locución del locutor.

Valores permitidos: Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestring
Obligatorio

Nombre de voz predefinida.

Valores permitidos: 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
Opcional

Temperatura de muestreo.

Valor predeterminado: 1 Rango: 0 - 2
gemini-3.1-flash-tts15 campos
callback_urlstring
Opcional

URL de webhook para notificaciones asíncronas.

dialogue_turnsarray
Obligatorio

Turnos de diálogo ordenados no vacíos cuyos identificadores de locutor hacen referencia a locutores configurados.

Límite de elementos: 1
dialogue_turns[].speaker_idstring
Obligatorio

Identificador que coincide con un speakers[].speaker_id configurado.

dialogue_turns[].textstring
Obligatorio

Texto hablado, de hasta 10 000 caracteres.

Límite: 10000
modelstring
Obligatorio

Identificador del modelo.

sample_contextstring
Opcional

Contexto general de entrega y tono.

scenestring
Opcional

Escena y entorno de grabación.

speakersarray
Obligatorio

Configuraciones de locutor no vacías con identificadores únicos de Locutor N.

Límite de elementos: 1
speakers[].accentstring
Opcional

Acento del locutor.

Valores permitidos: Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestring
Opcional

Guía opcional de carácter de voz.

speakers[].pacestring
Opcional

Ritmo del locutor.

Valores permitidos: Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstring
Obligatorio

Identificador único en formato Speaker N.

speakers[].stylestring
Opcional

Estilo de locución del locutor.

Valores permitidos: Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestring
Obligatorio

Nombre de voz predefinida.

Valores permitidos: 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
Opcional

Temperatura de muestreo.

Valor predeterminado: 1 Rango: 0 - 2
04

Crear aceptación

HTTP 202

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "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
}

Ejemplo de respuesta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "processing"
}
05

Consulta en proceso

HTTP 200

GET /api/v1/gemini_tts/text_to_speech/:id

Esquema de respuesta
JSON
{
  "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
}

Ejemplo de respuesta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "processing"
}
06

Consulta completada

HTTP 200

GET /api/v1/gemini_tts/text_to_speech/:id

Esquema de respuesta
JSON
{
  "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
}

Ejemplo de respuesta

JSON
{
  "audios": [
    {
      "url": "https://file.runapi.ai/reference-audio.mp3"
    }
  ],
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "completed"
}
07

Consulta fallida

HTTP 200

GET /api/v1/gemini_tts/text_to_speech/:id

Esquema de respuesta
JSON
{
  "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
}

Ejemplo de respuesta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "error": "Task processing failed.",
  "id": "tsk_reference_demo",
  "status": "failed"
}
08

Devolución de llamada del cliente: completado

HTTP 200

POST callback_url

Esquema de respuesta
JSON
{
  "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
}

Ejemplo de respuesta

JSON
{
  "audios": [
    {
      "url": "https://file.runapi.ai/reference-audio.mp3"
    }
  ],
  "id": "tsk_reference_demo",
  "status": "completed"
}
09

Devolución de llamada del cliente: fallido

HTTP 200

POST callback_url

Esquema de respuesta
JSON
{
  "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
}

Ejemplo de respuesta

JSON
{
  "error": {
    "code": "generation_failed",
    "message": "Task processing failed."
  },
  "id": "tsk_reference_demo",
  "status": "failed"
}
10

Errores

HTTP 401

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "Authentication required"
}
11

Errores

HTTP 401

GET /api/v1/gemini_tts/text_to_speech/:id

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "Authentication required"
}
12

Errores

HTTP 400

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "oneOf": [
    {
      "properties": {
        "error": {
          "description": "Mensaje de error legible por personas.",
          "type": "string"
        }
      },
      "required": [
        "error"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    {
      "properties": {
        "error": {
          "description": "Resumen de validación legible por personas.",
          "type": "string"
        },
        "errors": {
          "additionalProperties": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "description": "Mensajes de validación con clave por campo de solicitud público, con un array de cadenas legibles por personas para cada campo.",
          "type": "object"
        }
      },
      "required": [
        "error",
        "errors"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  ]
}

Ejemplo de respuesta

JSON
{
  "error": "model must be one of: gemini-2.5-pro-tts, gemini-3.1-flash-tts"
}
13

Errores

HTTP 402

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "Insufficient balance"
}
14

Errores

HTTP 429

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "API key credit limit exceeded"
}
15

Errores

HTTP 409

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "The request uses features that are not supported for the selected model"
}
16

Errores

HTTP 429

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "Rate limit reached. Please retry later."
}
17

Errores

HTTP 503

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "Service under maintenance, please try again later"
}
18

Errores

HTTP 504

POST /api/v1/gemini_tts/text_to_speech

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "The request timed out"
}
19

Errores

HTTP 404

GET /api/v1/gemini_tts/text_to_speech/:id

Esquema de respuesta
JSON
{
  "properties": {
    "error": {
      "description": "Mensaje de error legible por personas.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Ejemplo de respuesta

JSON
{
  "error": "Task with id 'tsk_reference_demo' not found"
}
20

Ejemplos de código generados

Usa cURL directamente o instala un SDK para tu lenguaje. Cada muestra envía la solicitud validada que se muestra en esta referencia.

Instalar

Shell
pip install runapi-gemini-tts
PYTHON
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."}]
)