# Text-to-speech (streaming and non-streaming)

> Audio Generation

text is the verbatim text to speak. Put style instructions in speech_metadata.style; transient tags include <short pause> and <sigh>. Each part's speech_metadata.speaker must match a speaker in speakerVoiceConfigs. Do not set single-speaker voiceConfig and multiSpeakerVoiceConfig together. Voice names are examples; this document does not claim platform support for a voice-list or voice-cloning endpoint.

**Streaming requests**: the path documented here is the non-streaming endpoint. To receive a streaming response, you must replace `generateContent` in the request path with `streamGenerateContent`, i.e. `/v1beta/models/gemini-3.8-flash-lite-tts:streamGenerateContent`. Headers and request body are identical to the non-streaming call; do not add a stream field.

## Endpoint

`POST https://api.modelverse.cn/v1beta/models/gemini-3.8-flash-lite-tts:generateContent`

## Request Body

## Responses

- **200** — Non-streaming responses contain the complete audio: inlineData.mimeType is usually audio/wav and data is the Base64 encoding of a full WAV file with a RIFF header, which can be decoded and saved directly as a .wav file.
Streaming requests return text/event-stream, where each data payload is a JSON chunk of this structure; audio chunks are headerless raw PCM (24 kHz, mono, signed 16-bit little-endian), so Base64-decode each chunk and concatenate the bytes.
The short Base64 below illustrates structure only; it is not complete playable audio.
- **default** — Error response.

## OpenAPI Definition

```json
{
  "openapi": "3.1.0",
  "x-language": "en-US",
  "info": {
    "title": "gemini-3.8-flash-lite-tts Streaming and Non-streaming Speech API",
    "version": "1.0.0",
    "description": "ModelVerse Gemini-compatible text-to-speech (TTS) API that turns plain text into single- or multi-speaker audio. Delivery is steered with turn-level `speech_metadata.style` and inline tags in the text, covering emotion, prosody, pace, and volume.\n\ngemini-3.8-flash-lite-tts supports more than 100 languages, and the input language is detected automatically. Non-streaming calls return a complete WAV file with a RIFF header; streaming calls (`:streamGenerateContent`) return an SSE event stream whose `data` payloads are `GenerateContentResponse` JSON chunks, with audio chunks as headerless raw signed 16-bit little-endian PCM (24 kHz, mono). Both modes use the same request body."
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "Mainland China"
    },
    {
      "url": "https://api.umodelverse.ai",
      "description": "Global"
    },
    {
      "url": "https://api-us-ca.umodelverse.ai",
      "description": "Los Angeles, US"
    },
    {
      "url": "https://api-sg.umodelverse.ai",
      "description": "Singapore"
    },
    {
      "url": "https://api-ge-fra.umodelverse.ai",
      "description": "Frankfurt"
    }
  ],
  "tags": [
    {
      "name": "gemini-3.8-flash-lite-tts",
      "description": "Text-to-speech with single-speaker and multi-speaker support; combine speech_metadata and inline tags to control delivery."
    }
  ],
  "security": [
    {
      "geminiApiKeyAuth": []
    }
  ],
  "externalDocs": {
    "description": "Speech generation source documentation.",
    "url": "https://www.gemini-china-guide.com/docs/speech-generation?generate-content=true#streaming"
  },
  "paths": {
    "/v1beta/models/gemini-3.8-flash-lite-tts:generateContent": {
      "post": {
        "tags": [
          "gemini-3.8-flash-lite-tts"
        ],
        "operationId": "generateContentGemini38FlashLiteTtsEnUS",
        "summary": "Text-to-speech (streaming and non-streaming)",
        "description": "text is the verbatim text to speak. Put style instructions in speech_metadata.style; transient tags include <short pause> and <sigh>. Each part's speech_metadata.speaker must match a speaker in speakerVoiceConfigs. Do not set single-speaker voiceConfig and multiSpeakerVoiceConfig together. Voice names are examples; this document does not claim platform support for a voice-list or voice-cloning endpoint.\n\n**Streaming requests**: the path documented here is the non-streaming endpoint. To receive a streaming response, you must replace `generateContent` in the request path with `streamGenerateContent`, i.e. `/v1beta/models/gemini-3.8-flash-lite-tts:streamGenerateContent`. Headers and request body are identical to the non-streaming call; do not add a stream field.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateContentRequest"
              },
              "examples": {
                "singleSpeaker": {
                  "summary": "single-speaker speech",
                  "description": "Request path: `/v1beta/models/gemini-3.8-flash-lite-tts:generateContent`.\n\nSet the MODELVERSE_API_KEY environment variable to your Modelverse API key, then run:\n\n```bash\ncurl --request POST \\\n  'https://api.modelverse.cn/v1beta/models/gemini-3.8-flash-lite-tts:generateContent' \\\n  --header \"x-goog-api-key: ${MODELVERSE_API_KEY}\" \\\n  --header 'Content-Type: application/json' \\\n  --data-raw '{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"Have a wonderful day!\",\n          \"speech_metadata\": {\n            \"style\": \"cheerful and friendly\"\n          }\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"responseModalities\": [\n      \"AUDIO\"\n    ],\n    \"speechConfig\": {\n      \"voiceConfig\": {\n        \"voice\": \"Kore\"\n      }\n    }\n  }\n}'\n```",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "text": "Have a wonderful day!",
                            "speech_metadata": {
                              "style": "cheerful and friendly"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "responseModalities": [
                        "AUDIO"
                      ],
                      "speechConfig": {
                        "voiceConfig": {
                          "voice": "Kore"
                        }
                      }
                    }
                  }
                },
                "twoSpeakers": {
                  "summary": "Two-speaker dialogue",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "text": "Hello, Jane!",
                            "speech_metadata": {
                              "speaker": "Joe"
                            }
                          },
                          {
                            "text": "Hi, Joe! <short pause> How are you?",
                            "speech_metadata": {
                              "speaker": "Jane",
                              "style": "warm and friendly"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "responseModalities": [
                        "AUDIO"
                      ],
                      "speechConfig": {
                        "multiSpeakerVoiceConfig": {
                          "speakerVoiceConfigs": [
                            {
                              "speaker": "Joe",
                              "voiceConfig": {
                                "voice": "Puck"
                              }
                            },
                            {
                              "speaker": "Jane",
                              "voiceConfig": {
                                "voice": "Kore"
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Non-streaming responses contain the complete audio: inlineData.mimeType is usually audio/wav and data is the Base64 encoding of a full WAV file with a RIFF header, which can be decoded and saved directly as a .wav file.\nStreaming requests return text/event-stream, where each data payload is a JSON chunk of this structure; audio chunks are headerless raw PCM (24 kHz, mono, signed 16-bit little-endian), so Base64-decode each chunk and concatenate the bytes.\nThe short Base64 below illustrates structure only; it is not complete playable audio.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerateContentResponse"
                },
                "examples": {
                  "audio": {
                    "summary": "The short Base64 below illustrates structure only; it is not complete playable audio.",
                    "value": {
                      "candidates": [
                        {
                          "content": {
                            "role": "model",
                            "parts": [
                              {
                                "inlineData": {
                                  "mimeType": "audio/wav",
                                  "data": "AAAAAA=="
                                }
                              }
                            ]
                          },
                          "finishReason": "STOP"
                        }
                      ],
                      "usageMetadata": {
                        "promptTokenCount": 12,
                        "candidatesTokenCount": 20,
                        "totalTokenCount": 32
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": 400,
                    "message": "Invalid request",
                    "status": "INVALID_ARGUMENT"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "geminiApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-goog-api-key",
        "description": "Use your Modelverse API key."
      }
    },
    "schemas": {
      "GenerateContentRequest": {
        "type": "object",
        "description": "TTS request body. Put the text to speak in contents and select the audio output and voice in generationConfig.",
        "properties": {
          "contents": {
            "type": "array",
            "minItems": 1,
            "description": "Input content array. TTS accepts plain text only; usually send a single content item with role=user, whose parts are synthesized into one continuous audio track in order.",
            "items": {
              "$ref": "#/components/schemas/RequestContent"
            }
          },
          "generationConfig": {
            "description": "Generation settings. Must declare AUDIO as the response modality and select a single-speaker or multi-speaker voice configuration.",
            "$ref": "#/components/schemas/GenerationConfig"
          }
        },
        "required": [
          "contents",
          "generationConfig"
        ]
      },
      "RequestContent": {
        "type": "object",
        "description": "A single conversation content item.",
        "properties": {
          "role": {
            "type": "string",
            "const": "user",
            "description": "Content role; fixed to user for TTS."
          },
          "parts": {
            "type": "array",
            "minItems": 1,
            "description": "Text segments synthesized in order. Each part is treated as one turn, and its speech_metadata.style applies to that segment as a whole; for multi-speaker audio, each part is one speaker's line.",
            "items": {
              "$ref": "#/components/schemas/RequestPart"
            }
          }
        },
        "required": [
          "role",
          "parts"
        ]
      },
      "RequestPart": {
        "type": "object",
        "description": "A text segment to speak, with its speech metadata.",
        "properties": {
          "text": {
            "type": "string",
            "description": "Verbatim text to speak; the model reads exactly what is written. Put style requests such as emotion or pace in speech_metadata.style instead of here. Transient non-speech events can be inserted with inline angle-bracket tags, for example `Wait... <short pause> did you hear that? <sigh>` or `Excuse me <cough> as I was saying...`."
          },
          "speech_metadata": {
            "description": "Turn-level speech metadata that controls the delivery of this segment; for multi-speaker audio it also selects the speaker.",
            "$ref": "#/components/schemas/SpeechMetadata"
          }
        },
        "required": [
          "text"
        ]
      },
      "SpeechMetadata": {
        "type": "object",
        "description": "Segment-level (turn-level) speech control metadata.",
        "properties": {
          "style": {
            "type": "string",
            "description": "Turn-level style instruction applied to the whole segment, shaping emotion, expressiveness, prosody, pace, and volume. Use natural language, for example `cheerful and friendly`, `whispered urgently`, `out of breath`, or `warm and enthusiastic`."
          },
          "speaker": {
            "type": "string",
            "description": "Speaker identifier for this segment in multi-speaker audio. It must exactly match a speaker in generationConfig.speechConfig.multiSpeakerVoiceConfig.speakerVoiceConfigs[].speaker; omit it for single-speaker audio."
          }
        }
      },
      "GenerationConfig": {
        "type": "object",
        "description": "Generation settings.",
        "properties": {
          "responseModalities": {
            "type": "array",
            "description": "Response modalities. TTS models return audio only, so set this to [\"AUDIO\"].",
            "items": {
              "type": "string",
              "const": "AUDIO"
            },
            "minItems": 1,
            "maxItems": 1
          },
          "speechConfig": {
            "description": "Voice configuration. Choose one of single-speaker voiceConfig or multi-speaker multiSpeakerVoiceConfig.",
            "$ref": "#/components/schemas/SpeechConfig"
          }
        },
        "required": [
          "responseModalities",
          "speechConfig"
        ]
      },
      "SpeechConfig": {
        "type": "object",
        "description": "Voice configuration. Exactly one of voiceConfig or multiSpeakerVoiceConfig must be set: use voiceConfig for single-speaker speech and multiSpeakerVoiceConfig for two-speaker or multi-speaker dialogue.",
        "properties": {
          "voiceConfig": {
            "description": "Voice configuration for single-speaker speech.",
            "$ref": "#/components/schemas/SingleVoiceConfig"
          },
          "multiSpeakerVoiceConfig": {
            "description": "Per-speaker voice configuration for multi-speaker dialogue.",
            "$ref": "#/components/schemas/MultiSpeakerVoiceConfig"
          }
        },
        "oneOf": [
          {
            "required": [
              "voiceConfig"
            ],
            "not": {
              "required": [
                "multiSpeakerVoiceConfig"
              ]
            }
          },
          {
            "required": [
              "multiSpeakerVoiceConfig"
            ],
            "not": {
              "required": [
                "voiceConfig"
              ]
            }
          }
        ]
      },
      "SingleVoiceConfig": {
        "type": "object",
        "description": "Voice for single- and multi-speaker speech.",
        "properties": {
          "voice": {
            "type": "string",
            "description": "Voice name or voice ID, for example the prebuilt voices `Kore` or `Puck`. The official lineup includes 30 prebuilt voices and also supports extended-library IDs and custom voices (`voice_...` / `voicekey_...`); the voices actually available on the platform are subject to the console.",
            "examples": [
              "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"
            ]
          }
        },
        "required": [
          "voice"
        ]
      },
      "MultiSpeakerVoiceConfig": {
        "type": "object",
        "description": "Voice configuration for multi-speaker dialogue.",
        "properties": {
          "speakerVoiceConfigs": {
            "type": "array",
            "minItems": 1,
            "description": "Speaker-to-voice mapping, one entry per speaker; a two-speaker dialogue needs two entries. The speaker label is user-defined and maps parts[].speech_metadata.speaker to a voice.",
            "items": {
              "$ref": "#/components/schemas/SpeakerVoiceConfig"
            }
          }
        },
        "required": [
          "speakerVoiceConfigs"
        ]
      },
      "SpeakerVoiceConfig": {
        "type": "object",
        "description": "Voice configuration for one speaker.",
        "properties": {
          "speaker": {
            "type": "string",
            "description": "Speaker label that must match parts[].speech_metadata.speaker; any name can be used, for example Joe or Jane."
          },
          "voiceConfig": {
            "description": "Voice used by this speaker; the structure is the same as the single-speaker voiceConfig.",
            "$ref": "#/components/schemas/SingleVoiceConfig"
          }
        },
        "required": [
          "speaker",
          "voiceConfig"
        ]
      },
      "GenerateContentResponse": {
        "type": "object",
        "description": "TTS response. Non-streaming calls return the complete audio; in streaming (SSE) mode each event's data payload is a JSON chunk of this structure.",
        "properties": {
          "candidates": {
            "type": "array",
            "description": "List of candidate results.",
            "items": {
              "$ref": "#/components/schemas/Candidate"
            }
          },
          "usageMetadata": {
            "description": "Token usage statistics.",
            "$ref": "#/components/schemas/UsageMetadata"
          },
          "modelVersion": {
            "type": "string",
            "description": "Model version actually used."
          },
          "responseId": {
            "type": "string",
            "description": "Unique identifier of this response."
          }
        },
        "additionalProperties": true
      },
      "Candidate": {
        "type": "object",
        "description": "A single candidate result.",
        "properties": {
          "content": {
            "description": "Model output content; audio is in parts[].inlineData.",
            "$ref": "#/components/schemas/ResponseContent"
          },
          "finishReason": {
            "type": "string",
            "description": "Finish reason. Normal completion is STOP; other values are not restricted."
          },
          "index": {
            "type": "integer",
            "description": "Candidate index, starting at 0."
          }
        },
        "additionalProperties": true
      },
      "ResponseContent": {
        "type": "object",
        "description": "Response content.",
        "properties": {
          "role": {
            "type": "string",
            "description": "Content role, usually model."
          },
          "parts": {
            "type": "array",
            "description": "Content parts; audio data is in inlineData.",
            "items": {
              "$ref": "#/components/schemas/ResponsePart"
            }
          }
        },
        "additionalProperties": true
      },
      "ResponsePart": {
        "type": "object",
        "description": "A response part.",
        "properties": {
          "inlineData": {
            "description": "Inline audio data.",
            "$ref": "#/components/schemas/InlineData"
          },
          "text": {
            "type": "string",
            "description": "Text content; normally empty for TTS."
          }
        },
        "additionalProperties": true
      },
      "InlineData": {
        "type": "object",
        "description": "Inline audio data.",
        "properties": {
          "mimeType": {
            "type": "string",
            "description": "Audio media type. Non-streaming responses return a complete WAV with a RIFF header (`audio/wav`, 16-bit PCM, 24 kHz, mono); streaming responses return headerless raw signed 16-bit little-endian PCM (`audio/l16; rate=24000; channels=1`, 24 kHz, mono). Always handle the actual returned value instead of assuming a fixed type."
          },
          "data": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "Base64-encoded audio bytes. In streaming mode, Base64-decode each chunk and concatenate the decoded bytes in order, then add a WAV header if needed; never concatenate Base64 strings directly."
          }
        },
        "additionalProperties": true,
        "required": [
          "mimeType",
          "data"
        ]
      },
      "UsageMetadata": {
        "type": "object",
        "description": "Token usage.",
        "properties": {
          "promptTokenCount": {
            "type": "integer",
            "description": "Number of input (text) tokens."
          },
          "candidatesTokenCount": {
            "type": "integer",
            "description": "Number of output (audio) tokens."
          },
          "totalTokenCount": {
            "type": "integer",
            "description": "Total number of tokens."
          }
        },
        "additionalProperties": true
      },
      "ErrorResponse": {
        "type": "object",
        "description": "Error response.",
        "properties": {
          "error": {
            "description": "Error details.",
            "$ref": "#/components/schemas/Error"
          }
        },
        "additionalProperties": true,
        "required": [
          "error"
        ]
      },
      "Error": {
        "type": "object",
        "description": "Standard Google API error structure.",
        "properties": {
          "code": {
            "type": "integer",
            "description": "HTTP status code, for example 400."
          },
          "message": {
            "type": "string",
            "description": "Human-readable error message."
          },
          "status": {
            "type": "string",
            "description": "Canonical error status, for example INVALID_ARGUMENT, PERMISSION_DENIED, or RESOURCE_EXHAUSTED."
          },
          "details": {
            "type": "array",
            "description": "Additional error details for diagnosis.",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      }
    }
  }
}
```
