> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Text-to-Speech

> The Prisma AIRS AI Gateway supports text-to-speech models on OpenAI, Azure OpenAI, and Google Vertex AI.

## Usage

We follow the OpenAI signature where you can send the input text and the voice option as a part of the API request. All the output formats `mp3`, `opus`, `aac`, `flac`, and `pcm` are supported. The AI Gateway also supports real time audio streaming for TTS models.

Here's an example:

> [tab] OpenAI NodeJS
>
> ```js theme={"system"}
> import fs from "fs";
> import path from "path";
> import OpenAI from "openai";
>
> const openai = new OpenAI({
>   apiKey: "PORTKEY_API_KEY",
>   baseURL: "https://aigw.portkey.ai/v1"
> });
>
> const speechFile = path.resolve("./speech.mp3");
>
> async function main() {
>   const mp3 = await openai.audio.speech.create({
>     model: "@openai/tts-1",
>     voice: "alloy",
>     input: "Today is a wonderful day to build something people love!",
>   });
>   const buffer = Buffer.from(await mp3.arrayBuffer());
>   await fs.promises.writeFile(speechFile, buffer);
> }
>
> main();
> ```

> [tab] OpenAI Python
>
> ```py theme={"system"}
> from pathlib import Path
> from openai import OpenAI
>
> client = OpenAI(
>     api_key="PORTKEY_API_KEY",
>     base_url="https://aigw.portkey.ai/v1"
> )
>
> speech_file_path = Path(__file__).parent / "speech.mp3"
>
> response = client.audio.speech.create(
>   model="@openai/tts-1",
>   voice="alloy",
>   input="Today is a wonderful day to build something people love!"
> )
>
> f = open(speech_file_path, "wb")
> f.write(response.content)
> f.close()
> ```

> [tab] cURL
>
> ```sh theme={"system"}
> curl "https://aigw.portkey.ai/v1/audio/speech" \
>   -H "Content-Type: application/json" \
>   -H "Authorization: Bearer $PORTKEY_API_KEY" \
>   -d '{
>     "model": "@openai/tts-1",
>     "input": "Today is a wonderful day to build something people love!",
>     "voice": "alloy"
>   }' \
>   --output speech.mp3
> ```

On completion, the request will get logged in the logs UI and show the cost and latency incurred.

## SSE Streaming

OpenAI and Azure OpenAI support Server-Sent Events (SSE) streaming for the speech endpoint. Set `stream_format` to `"sse"` to receive audio data as a stream of events:

> [tab] cURL
>
> ```sh theme={"system"}
> curl "https://aigw.portkey.ai/v1/audio/speech" \
>   -H "Content-Type: application/json" \
>   -H "Authorization: Bearer $PORTKEY_API_KEY" \
>   -d '{
>     "model": "@openai/tts-1",
>     "input": "Today is a wonderful day to build something people love!",
>     "voice": "alloy",
>     "stream_format": "sse"
>   }'
> ```

## Google Vertex AI TTS

Google Vertex AI offers Gemini TTS models with advanced features like multi-speaker synthesis and style control. The AI Gateway supports two methods:

1. **Chat Completions with `speech_config`** - Use Gemini TTS through the chat completions endpoint
2. **Audio Speech endpoint** - OpenAI-compatible `/audio/speech` endpoint

> [tab] Chat Completions
>
> ```sh theme={"system"}
> curl https://aigw.portkey.ai/v1/chat/completions \
>   -H "Content-Type: application/json" \
>   -H "Authorization: Bearer $PORTKEY_API_KEY" \
>   -d '{
>     "model": "@vertex-ai/gemini-2.5-flash-tts",
>     "messages": [{"role": "user", "content": "Say cheerfully: Hello!"}],
>     "speech_config": {
>       "voice_config": {"prebuilt_voice_config": {"voice_name": "Kore"}},
>       "language_code": "en-US"
>     }
>   }'
> ```

> [tab] Audio Speech
>
> ```sh theme={"system"}
> curl "https://aigw.portkey.ai/v1/audio/speech" \
>   -H "Content-Type: application/json" \
>   -H "Authorization: Bearer $PORTKEY_API_KEY" \
>   -d '{
>     "model": "@vertex-ai/gemini-2.5-flash-tts",
>     "input": "Hello! This is a test.",
>     "voice": "Kore",
>     "response_format": "mp3"
>   }' \
>   --output speech.mp3
> ```

For detailed documentation including multi-speaker synthesis, style prompts, and all available voices, see [Google Vertex AI Text-to-Speech](https://docs.portkey.ai/docs/aigw/integrations/llms/vertex-ai/text-to-speech.md).


## Related topics

- [Text-to-Speech](https://docs.portkey.ai/docs/aigw/integrations/llms/vertex-ai/text-to-speech.md)
- [Speech-to-Text](https://docs.portkey.ai/docs/aigw/product/ai-gateway/multimodal-capabilities/speech-to-text.md)
- [ElevenLabs](https://docs.portkey.ai/docs/aigw/integrations/llms/elevenlabs.md)
- [Groq](https://docs.portkey.ai/docs/aigw/integrations/llms/groq.md)
- [Lemonfox-AI](https://docs.portkey.ai/docs/aigw/integrations/llms/lemon-fox.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.