> For the complete documentation index, see [llms.txt](https://synapse-labs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://synapse-labs.gitbook.io/docs/services/text-to-speech.md).

# Text To Speech

OpenAI's realistic text to speech model

## TTS Models

<mark style="color:green;">`GET`</mark> `/tts/list`

List available TTS Models

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |

**Response**

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

```json
["tts-1", "tts-1-hd", ...]
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

## TTS Voices

<mark style="color:green;">`GET`</mark> `/tts/voices`

List available TTS Voices

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |

**Response**

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

```json
["alloy", "echo", "fable", ...]
```

{% endtab %}
{% endtabs %}

## Create Speech

<mark style="color:blue;">`POST`</mark> `/tts/:model`

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

<table><thead><tr><th>Name</th><th width="139">Type</th><th width="225">Description</th><th>Default</th></tr></thead><tbody><tr><td><code>input</code></td><td>string</td><td>Input text</td><td><code>none</code></td></tr><tr><td><code>voice</code></td><td>string</td><td>Voice</td><td>alloy</td></tr><tr><td><code>speed</code></td><td>number</td><td>Voice speed (0.25 - 4.0)</td><td>1.0</td></tr></tbody></table>

**Response**

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

```json
{
  "data": "d2VsbF9oZWxsb190aGVyZV90Lm1lL3N5bmFwc2VfbGFicw....."
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}

{% tab title="500" %}

```json
{
  "error": "Error during generation (TTS)"
}
```

{% endtab %}
{% endtabs %}

**Example**

```javascript
const res = await fetch('https://synapselabs.onrender.com/tts/tts-1-hd', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <your_api_key>'
  },
  body: JSON.stringify({
    input: 'hello',
    speed: 1.0,
    voice: 'alloy',
  }),
});

const data = await res.json();
const buf = Buffer.from(data.data, 'base64');
fs.writeFileSync('test.mp3', buf);
```
