Skip to content

Gemini Speech Synthesis (Native Format)

Besides the OpenAI-compatible text-to-speech endpoint, YouQi AI also supports Gemini's native speech generation models (e.g. gemini-2.5-flash-preview-tts), reusing Gemini's generateContent endpoint with responseModalities and speechConfig to request audio output.

Endpoint

POST /v1beta/models/{model}:generateContent

Base URL and auth are the same as Gemini Text Chat: https://ai.youqi.tech/v1beta, authenticated via the ?key= query parameter or the x-goog-api-key header.

Request parameters

ParameterTypeRequiredDescription
contents[].parts[].textstringYesText to synthesize
generationConfig.responseModalitiesarrayYesFixed to ["AUDIO"]
generationConfig.speechConfig.voiceConfig.prebuiltVoiceConfig.voiceNamestringYesPrebuilt voice name

Request example

bash
curl "https://ai.youqi.tech/v1beta/models/gemini-2.5-flash-preview-tts:generateContent?key=sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      { "parts": [{ "text": "Hello, welcome to YouQi AI." }] }
    ],
    "generationConfig": {
      "responseModalities": ["AUDIO"],
      "speechConfig": {
        "voiceConfig": {
          "prebuiltVoiceConfig": { "voiceName": "Kore" }
        }
      }
    }
  }'

Response example

The audio is returned as inline Base64 data inside parts (inlineData.data, with a MIME type such as audio/L16;codec=pcm;rate=24000):

json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "audio/L16;codec=pcm;rate=24000",
              "data": "BASE64_ENCODED_AUDIO_DATA"
            }
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 12,
    "candidatesTokenCount": 0,
    "totalTokenCount": 12
  }
}

TIP

Available voice names and supported TTS models depend on the selected model's actual capabilities. For generic text-to-speech, /v1/audio/speech (OpenAI-compatible format) is simpler.