跳到正文
RunAPI 开发者文档
API 参考
API 参考

Gemini TTS Text-to-Speech

以异步 Task 提交Text to Speech请求。

01

概览

使用支持的模型提交Text to Speech请求。使用返回的 Task ID 查询状态,或提供 callback_url 接收下方列出的投递。

快速开始

  1. 创建 API Key,并将其设置为 RUNAPI_API_KEY。
  2. 选择一个支持的模型,并发送与该模型 Schema 匹配的 POST 请求。
  3. 保存返回的任务 ID,随后轮询到终态,或处理下方列出的回调。

端点

POST /api/v1/gemini_tts/text_to_speech
基础 URL
https://runapi.ai
API 版本
v1
身份验证
Authorization: Bearer YOUR_API_TOKEN
02

支持的模型

打开模型页可查看当前价格、限流和商业使用详情。

03

请求 Schema

JSON 请求体

字段和允许的取值取决于所选模型。提供 callback_url 后,它会收到下方列出的 Task 投递。

gemini-2.5-pro-tts15 个字段
callback_urlstring
可选

Webhook URL for async notifications.

dialogue_turnsarray
必填

Non-empty ordered dialogue turns whose speaker ids reference configured speakers.

项数限制: 1
dialogue_turns[].speaker_idstring
必填

Identifier matching a configured speakers[].speaker_id.

dialogue_turns[].textstring
必填

Spoken text, up to 10,000 characters.

边界: 10000
modelstring
必填

Model slug.

sample_contextstring
可选

Overall delivery context and tone.

scenestring
可选

Scene and recording environment.

speakersarray
必填

Non-empty speaker configurations with unique Speaker N identifiers.

项数限制: 1
speakers[].accentstring
必填

Speaker accent.

可选值: Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestring
可选

Optional voice character guidance.

speakers[].pacestring
必填

Speaker pace.

可选值: Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstring
必填

Unique identifier in Speaker N format.

speakers[].stylestring
必填

Speaker delivery style.

可选值: Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestring
必填

Preset voice name.

可选值: 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
可选

Sampling temperature.

默认值: 1 范围: 0 - 2
gemini-3.1-flash-tts15 个字段
callback_urlstring
可选

Webhook URL for async notifications.

dialogue_turnsarray
必填

Non-empty ordered dialogue turns whose speaker ids reference configured speakers.

项数限制: 1
dialogue_turns[].speaker_idstring
必填

Identifier matching a configured speakers[].speaker_id.

dialogue_turns[].textstring
必填

Spoken text, up to 10,000 characters.

边界: 10000
modelstring
必填

Model slug.

sample_contextstring
可选

Overall delivery context and tone.

scenestring
可选

Scene and recording environment.

speakersarray
必填

Non-empty speaker configurations with unique Speaker N identifiers.

项数限制: 1
speakers[].accentstring
必填

Speaker accent.

可选值: Neutral, American (Gen), American (Valley), American (South), British (RP), British (Brixton), Transatlantic, Australian
speakers[].audio_profilestring
可选

Optional voice character guidance.

speakers[].pacestring
必填

Speaker pace.

可选值: Natural, Rapid Fire, The Drift, Staccato
speakers[].speaker_idstring
必填

Unique identifier in Speaker N format.

speakers[].stylestring
必填

Speaker delivery style.

可选值: Vocal Smile, Newscaster, Whisper, Empathetic, Promo/Hype, Deadpan
speakers[].voice_namestring
必填

Preset voice name.

可选值: 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
可选

Sampling temperature.

默认值: 1 范围: 0 - 2
04

创建已接受

HTTP 202

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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
}

响应示例

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

轮询处理中

HTTP 200

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

响应 Schema
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
}

响应示例

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

轮询已完成

HTTP 200

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

响应 Schema
JSON
{
  "properties": {
    "audios": {
      "items": {
        "properties": {
          "url": {
            "type": "string"
          }
        },
        "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
}

响应示例

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

轮询失败

HTTP 200

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

响应 Schema
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
}

响应示例

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

客户回调:已完成

HTTP 200

POST callback_url

响应 Schema
JSON
{
  "properties": {
    "audios": {
      "items": {
        "properties": {
          "url": {
            "type": "string"
          }
        },
        "required": [
          "url"
        ],
        "type": "object",
        "unevaluatedProperties": false
      },
      "type": "array"
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "audios"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

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

客户回调:失败

HTTP 200

POST callback_url

响应 Schema
JSON
{
  "properties": {
    "error": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "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
}

响应示例

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

错误

HTTP 401

POST /api/v1/gemini_tts/text_to_speech

此响应不包含正文。

11

错误

HTTP 401

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

此响应不包含正文。

12

错误

HTTP 400

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": {
    "code": "model_must_be_one_of_gemini-2_5-pro-tts_gemini-3_1-flash-tts",
    "message": "model must be one of: gemini-2.5-pro-tts, gemini-3.1-flash-tts"
  }
}
13

错误

HTTP 402

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": {
    "code": "insufficient_balance",
    "message": "Insufficient balance"
  }
}
14

错误

HTTP 403

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": {
    "code": "api_token_credit_limit_exceeded",
    "message": "API key credit limit exceeded"
  }
}
15

错误

HTTP 409

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

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

错误

HTTP 429

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": {
    "code": "rate_limited",
    "message": "Rate limit reached. Please retry later."
  }
}
17

错误

HTTP 503

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

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

错误

HTTP 504

POST /api/v1/gemini_tts/text_to_speech

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "error": {
    "code": "timeout_error",
    "message": "The request timed out"
  }
}
19

错误

HTTP 404

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

响应 Schema
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": {
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

响应示例

JSON
{
  "error": {
    "code": "not_found",
    "message": "Task with id 'tsk_reference_demo' not found"
  }
}
20

生成的代码示例

直接使用 cURL,或安装所用语言的 SDK。每个示例都会提交本参考中经过验证的请求。

CURL
curl -X POST https://runapi.ai/api/v1/gemini_tts/text_to_speech \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"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."}]}'

安装

BASH
npm install @runapi.ai/gemini-tts
JAVASCRIPT
import { GeminiTtsClient } from "@runapi.ai/gemini-tts";

const client = new GeminiTtsClient({ apiKey: process.env.RUNAPI_API_KEY });
const task = await client.textToSpeech.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."
    }
  ]
});

安装

BASH
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."}]
)

安装

BASH
go get github.com/runapi-ai/gemini-tts-sdk/go@latest
GO
package main

import (
  "context"
  "log"
  "os"

  "github.com/runapi-ai/core-sdk/go/option"
  geminitts "github.com/runapi-ai/gemini-tts-sdk/go/geminitts"
)

func main() {
  client, err := geminitts.NewClient(option.WithAPIKey(os.Getenv("RUNAPI_API_KEY")))
  if err != nil {
    log.Fatal(err)
  }

  task, err := client.TextToSpeech.Create(context.Background(), geminitts.TextToSpeechParams{
    Model: geminitts.Model("gemini-2.5-pro-tts"),
    Temperature: func(value float64) *float64 { return &value }(0.8),
    Scene: "A quiet recording studio",
    SampleContext: "Natural conversational delivery",
    Speakers: []geminitts.Speaker{geminitts.Speaker{SpeakerID: "Speaker 1", VoiceName: "Fenrir", AudioProfile: "A calm host", Accent: "British (RP)", Style: "Newscaster", Pace: "Natural"}, geminitts.Speaker{SpeakerID: "Speaker 2", VoiceName: "Puck", Accent: "American (Gen)", Style: "Empathetic", Pace: "Staccato"}},
    DialogueTurns: []geminitts.DialogueTurn{geminitts.DialogueTurn{SpeakerID: "Speaker 1", Text: "Welcome to the show."}, geminitts.DialogueTurn{SpeakerID: "Speaker 2", Text: "Thanks for having me."}},
  })
  if err != nil {
    log.Fatal(err)
  }
  _ = task
}

安装

BASH
gem install runapi-gemini-tts
RUBY
require "runapi/gemini_tts"

client = RunApi::GeminiTts::Client.new(api_key: ENV.fetch("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."}]
)

安装

KOTLIN
implementation("ai.runapi:runapi-gemini-tts")
JAVA
import ai.runapi.geminitts.GeminiTtsClient;
import ai.runapi.geminitts.types.TextToSpeechParams;
import ai.runapi.core.polling.TaskCreateResponse;

public final class Example {
  public static void main(String[] args) {
    GeminiTtsClient client = GeminiTtsClient.builder()
        .apiKey(System.getenv("RUNAPI_API_KEY"))
        .build();
    TaskCreateResponse task = client.textToSpeech().create(
        TextToSpeechParams.builder()
        .model("gemini-2.5-pro-tts")
        .temperature(0.8)
        .scene("A quiet recording studio")
        .sampleContext("Natural conversational delivery")
        .speakers(java.util.Arrays.asList(ai.runapi.geminitts.types.Speaker.builder().speakerId("Speaker 1").voiceName("Fenrir").audioProfile("A calm host").accent("British (RP)").style("Newscaster").pace("Natural").build(), ai.runapi.geminitts.types.Speaker.builder().speakerId("Speaker 2").voiceName("Puck").accent("American (Gen)").style("Empathetic").pace("Staccato").build()))
        .dialogueTurns(java.util.Arrays.asList(ai.runapi.geminitts.types.DialogueTurn.builder().speakerId("Speaker 1").text("Welcome to the show.").build(), ai.runapi.geminitts.types.DialogueTurn.builder().speakerId("Speaker 2").text("Thanks for having me.").build()))
            .build()
    );
  }
}

安装

BASH
composer require runapi-ai/gemini-tts
PHP
<?php

require __DIR__ . '/vendor/autoload.php';

use RunApi\Core\ClientOptions;
use RunApi\GeminiTts\GeminiTtsClient;

$client = new GeminiTtsClient(new ClientOptions(apiKey: getenv('RUNAPI_API_KEY')));
$task = $client->textToSpeech->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."]]
]);
21

相关指南