Gemini 原生语音合成
▼
Authorization
在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
官方文档:https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn#gemini-image-editing
请求参数
Query 参数
key
string
必需
示例: YOUR_API_KEY
Header 参数
Content-Type
string
必需
示例: application/json
Body 参数 application/json
contents
array [object]
必需
parts
array [object]
可选
generationConfig
object
必需
responseModalities
array[string]
必需
imageConfig
object
必需
{ "contents": [ { "parts": [ { "text": "说出,我是谁,谁是我" } ] } ], "generationConfig": { "responseModalities": [ "AUDIO" ], "speechConfig": { "voiceConfig": { "prebuiltVoiceConfig": { "voiceName": "Kore" } } } }, "model": "gemini-2.5-flash-preview-tts" } 请求
示例
{
"contents": [
{
"parts": [
{
"text": "说出,我是谁,谁是我"
}
]
}
],
"generationConfig": {
"responseModalities": [
"AUDIO"
],
"speechConfig": {
"voiceConfig": {
"prebuiltVoiceConfig": {
"voiceName": "Kore"
}
}
}
},
"model": "gemini-2.5-flash-preview-tts"
}
请求示例代码
curl --location -g --request POST 'https://api.quickrouter.ai/v1beta/models/gemini-2.5-flash-preview-tts:generateContent?key=' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"contents": [
{
"parts": [
{
"text": "说出,我是谁,谁是我"
}
]
}
],
"generationConfig": {
"responseModalities": [
"AUDIO"
],
"speechConfig": {
"voiceConfig": {
"prebuiltVoiceConfig": {
"voiceName": "Kore"
}
}
}
},
"model": "gemini-2.5-flash-preview-tts"
}'
"var myHeaders = new Headers();\nmyHeaders.append(\"Authorization\", \"Bearer YOUR_API_KEY\");\nmyHeaders.append(\"Content-Type\", \"application/json\");\n\nvar raw = JSON.stringify({\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"说出,我是谁,谁是我\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"responseModalities\": [\n \"AUDIO\"\n ],\n \"speechConfig\": {\n \"voiceConfig\": {\n \"prebuiltVoiceConfig\": {\n \"voiceName\": \"Kore\"\n }\n }\n }\n },\n \"model\": \"gemini-2.5-flash-preview-tts\"\n});\n\nvar requestOptions = {\n method: 'POST',\n headers: myHeaders,\n body: raw,\n redirect: 'follow'\n};\n\nfetch(\"https://api.quickrouter.ai/v1beta/models/gemini-2.5-flash-preview-tts:generateContent\", requestOptions)\n .then(response => response.text())\n .then(result => console.log(result))\n .catch(error => console.log('error', error));"
"import http.client\nimport json\n\nconn = http.client.HTTPSConnection(\"api.quickrouter.ai\")\npayload = json.dumps({\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"说出,我是谁,谁是我\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"responseModalities\": [\n \"AUDIO\"\n ],\n \"speechConfig\": {\n \"voiceConfig\": {\n \"prebuiltVoiceConfig\": {\n \"voiceName\": \"Kore\"\n }\n }\n }\n },\n \"model\": \"gemini-2.5-flash-preview-tts\"\n})\nheaders = {\n 'Authorization': 'Bearer YOUR_API_KEY',\n 'Content-Type': 'application/json'\n}\nconn.request(\"POST\", \"/v1beta/models/gemini-2.5-flash-preview-tts:generateContent%7B%7BYOUR_API_KEY%7D%7D\", payload, headers)\nres = conn.getresponse()\ndata = res.read()\nprint(data.decode(\"utf-8\"))"
返回响应
响应参数 🟢 200 OK · application/json
object
可选
{}
示例
{}