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

# Text-to-Speech

> Obiguard’s AI gateway offers text-to-speech support for both `OpenAI` and `Azure OpenAI` models.

## Usage

The API follows the OpenAI format, allowing you to send input text and specify a voice option in your request.
Supported output formats include `mp3`, `opus`, `aac`, `flac`, and `pcm`.
Obiguard also enables real-time audio streaming for TTS models.

Example:

<Tabs>
  <Tab title="Python SDK">
    ```python theme={null}
    from obiguard import Obiguard

    client = Obiguard(
      provider='openai',
      obiguard_api_key='vk-obg***',  # Your Obiguard virtual key here
    )

    speech_file_path = Path(__file__).parent / "speech.mp3"

    response = client.audio.speech.create(
      model="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>

  <Tab title="OpenAI Python">
    ```python theme={null}
    from openai import OpenAI
    from obiguard import createHeaders

    client = OpenAI(
      base_url='https://gateway.obiguard.ai/v1',
      api_key='sk-***',  # Your OpenAI API key here
      default_headers=createHeaders(
        provider="openai",
        api_key="vk-obg***",  # Your Obiguard virtual key here
      )
    )

    speech_file_path = Path(__file__).parent / "speech.mp3"

    response = client.audio.speech.create(
      model="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>

  <Tab title="cURL">
    ```
    curl https://gateway.obiguard.ai/v1/audio/speech \
    -H "Content-Type: application/json" \
    -H "x-obiguard-api-key: vk-obg***" \
    -d '{
      "model": "tts-1",
      "voice": "alloy",
      "input": "Today is a wonderful day to build something people love!"
    }' --output speech.mp3
    ```
  </Tab>
</Tabs>

After completion, the request will appear in the logs UI, displaying the associated cost and latency.

## Supported Providers and Models

The following providers currently support text-to-speech.
More providers will be added soon.

| Provider     | Models          |
| ------------ | --------------- |
| OpenAI       | tts-1, tts-1-hd |
| Azure OpenAI | tts-1, tts-1-hd |
| Deepgram     | Coming Soon     |
| ElevenLabs   | Coming Soon     |
