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

# Text to Speech

**Text-to-Speech (TTS)** converts written text into natural-sounding audio, enabling applications such as voice assistants, audiobook generation, accessibility tools, and real-time speech synthesis. It supports multiple voices and providers, allowing flexible audio generation tailored to different use cases.

To explore available models, visit [cortecs.ai](https://cortecs.ai/serverlessModels?tags=Speech) and filter by the **Speech** tag.

### Example usage

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

```python
from openai import OpenAI 

client = OpenAI( 
    base_url="https://api.cortecs.ai/v1", 
    api_key="<API_KEY>", 
) 

response = client.audio.speech.create( 
    model="chatterbox-turbo", 
    input="Hello, this is a text-to-speech test.", 
    voice="<provider_voice>" 
) 

response.stream_to_file("speech.mp3")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
import OpenAI from "openai";
import fs from "fs";

const openai = new OpenAI({
    baseURL: 'https://api.cortecs.ai/v1',
    apiKey: '<API_KEY>'
});

const response = await openai.audio.speech.create({
  model: "chatterbox-turbo",
  input: "Hello, this is a text-to-speech test.",
  voice: "<provider_voice>"
});

const buffer = Buffer.from(await response.arrayBuffer());
await fs.promises.writeFile("speech.mp3", buffer);
```

{% endtab %}

{% tab title="Curl" %}

```bash
curl 'https://api.cortecs.ai/v1/audio/speech' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API_KEY>' \
  -d '{
    "model": "chatterbox-turbo",
    "input": "Hello, this is a text-to-speech test.",
    "voice": "<provider_voice>"
  }' \
  --output speech.mp3
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Text-to-Speech models are priced **per character** of input text.
{% endhint %}

### **Voice Support**

Each provider supports different voice styles. Available options depend on the selected provider.

| Provider | Example Voice         |
| -------- | --------------------- |
| Mistral  | `en_paul_neutral`     |
| Tensorix | `Emily.wav`           |
| OVH      | `English-US.Female-1` |

These are only example voices. Each provider may offer additional voice options depending on the model and configuration. Always check the provider documentation for the full list of available voices.

### Mistral zero-shot voice cloning

Mistral supports zero-shot voice cloning from a reference audio file. Base64-encode the reference audio and pass it in the `ref_audio` field of the request body.

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

```python
import base64
from pathlib import Path

from openai import OpenAI

client = OpenAI(
    base_url="https://api.cortecs.ai/v1",
    api_key="<API_KEY>",
)

ref_audio_b64 = base64.b64encode(Path("sample.mp3").read_bytes()).decode()
output_path = Path("speech.mp3")

with client.audio.speech.with_streaming_response.create(
    model="voxtral-mini-tts-2603",
    input="That's a test of zero-shot voice cloning!",
    voice="ignored",
    extra_body={
        "ref_audio": ref_audio_b64,
    },
) as response:
    response.stream_to_file(output_path)
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://api.cortecs.ai/v1",
  apiKey: "<API_KEY>"
});

const refAudioB64 = (await fs.promises.readFile("sample.mp3")).toString("base64");

const response = await openai.audio.speech.create({
  model: "voxtral-mini-tts-2603",
  input: "That's a test of zero-shot voice cloning!",
  voice: "ignored",
  ref_audio: refAudioB64
});

const buffer = Buffer.from(await response.arrayBuffer());
await fs.promises.writeFile("speech.mp3", buffer);
```

{% endtab %}
{% endtabs %}

The `voice` parameter is required by the OpenAI SDK but is ignored when `ref_audio` is provided. The generated speech is saved to `speech.mp3` using the voice characteristics from `sample.mp3`.
