# Text to Speech

## API Overview <a href="#api-overview" id="api-overview"></a>

To simplify the integration of different **text-to-speech-creation models (tts)**, Infron AI provides a unified image API.

## **API Specification**

Generates audio from the input text.

{% tabs %}
{% tab title="Curl" %}

<pre class="language-sh"><code class="lang-sh">curl https://audio.onerouter.pro/v1/audio/speech \
<strong>    -H "Content-Type: application/json" \
</strong>    -H "Authorization: &#x3C;API_KEY>" \
    -d '{
    "model": "gpt-4o-mini-tts",
    "input": "A cute baby sea otter",
    "voice": "alloy"
  }' \
  --output speech.mp3
</code></pre>

{% endtab %}

{% tab title="Python" %}

```python
import os
import json
import requests

API_URL = "https://audio.onerouter.pro/v1/audio/speech"
API_KEY = os.getenv("ONEROUTER_API_KEY")

if not API_KEY:
    raise RuntimeError("Please set the ONEROUTER_API_KEY")

payload = {
    "model": "gpt-4o-mini-tts",
    "input": "A cute baby sea otter.",
    "voice": "alloy",
    "response_format": "mp3"
}

headers = {
    "Authorization": API_KEY,
    "Content-Type": "application/json"
}

response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
response.raise_for_status()

out_path = os.path.join(os.path.dirname(__file__), "tts-output.mp3")
with open(out_path, "wb") as f:
    f.write(response.content)

print(f"Saved to: {out_path}")
```

{% endtab %}
{% endtabs %}

* `<API_KEY>` is your API Key generated in [API page](https://app.onerouter.pro/apiKeys).
* `model` is the model name, such as `gpt-4o-mini-tts`, available model list can be access in [Model page](https://app.onerouter.pro/models).
* The `voice` to use when generating the audio. Supported voices are `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`, `shimmer`, and `verse`.&#x20;

**Example response**

{% hint style="info" %}
The audio file content.
{% endhint %}

{% file src="<https://3822312837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ9C9AjT7j46HAcQrOVWw%2Fuploads%2FkT96iXtkx4j0ElyGLGXj%2Fresponse.mpga?alt=media&token=22ac8d72-7e25-4d3a-b6dc-2907252844f0>" %}
