# Text to Speech
Source: https://docs.mserve.ai/docs/voice/text-to-speech
Summary: Generate speech from text with the OpenAI audio endpoint or the ElevenLabs text-to-speech routes. Billed per character.
Availability: available
Last reviewed: 2026-08-25

## OpenAI shape

`POST /openai/v1/audio/speech`. `voice` is an OpenAI name, an ElevenLabs premade id, or an mserve voice id.

**Python**

```python
from openai import OpenAI

client = OpenAI(base_url="https://api.mserve.ai/openai/v1", api_key="ms_live_your_key")

with client.audio.speech.with_streaming_response.create(
    model="kokoro-82m",
    voice="coral",
    input="Every model. One API.",
    response_format="mp3",
) as response:
    response.stream_to_file("speech.mp3")
```

**JavaScript**

```ts
import OpenAI from "openai";
import { writeFile } from "node:fs/promises";

const client = new OpenAI({ baseURL: "https://api.mserve.ai/openai/v1", apiKey: "ms_live_your_key" });

const audio = await client.audio.speech.create({ model: "kokoro-82m", voice: "coral", input: "Every model. One API." });
await writeFile("speech.mp3", Buffer.from(await audio.arrayBuffer()));
```

**cURL**

```bash
curl https://api.mserve.ai/openai/v1/audio/speech \
  -H "Authorization: Bearer $MSERVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "kokoro-82m", "input": "Every model. One API.", "voice": "coral", "response_format": "mp3"}' \
  --output speech.mp3
```

| Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model` | `string` | yes |  | kokoro-82m for preset voices, chatterbox for cloned voices. tts-1 and tts-1-hd resolve too. |
| `input` | `string` | yes |  | The text to speak. Billed per character. |
| `voice` | `string` | yes |  | OpenAI name, ElevenLabs premade id, or mserve voice id. |
| `response_format` | `"mp3" | "opus" | "aac" | "flac" | "wav" | "pcm"` | no | `"mp3"` | See output formats on the Voice overview. |
| `speed` | `number` | no | `1.0` | Playback speed multiplier. |
| `stream_format` | `"audio" | "sse"` | no | `"audio"` | sse emits speech.audio.delta events with base64 audio instead of raw bytes. |

## ElevenLabs shape

`POST /elevenlabs/v1/text-to-speech/{voice_id}` returns audio bytes. `/stream` streams them. `output_format` is a query parameter.

**Python**

```python
from elevenlabs.client import ElevenLabs

client = ElevenLabs(base_url="https://api.mserve.ai/elevenlabs", api_key="ms_live_your_key")

audio = client.text_to_speech.convert(
    voice_id="21m00Tcm4TlvDq8ikWAM",
    text="Every model. One API.",
    model_id="eleven_multilingual_v2",
    output_format="mp3_44100_128",
)
with open("speech.mp3", "wb") as f:
    for chunk in audio:
        f.write(chunk)
```

**JavaScript**

```ts
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";

const client = new ElevenLabsClient({ baseUrl: "https://api.mserve.ai/elevenlabs", apiKey: "ms_live_your_key" });

const audio = await client.textToSpeech.convert("21m00Tcm4TlvDq8ikWAM", {
  text: "Every model. One API.",
  modelId: "eleven_multilingual_v2",
  outputFormat: "mp3_44100_128",
});
```

**cURL**

```bash
curl "https://api.mserve.ai/elevenlabs/v1/text-to-speech/21m00Tcm4TlvDq8ikWAM/stream?output_format=mp3_44100_128" \
  -H "Authorization: Bearer $MSERVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Every model. One API.", "model_id": "eleven_multilingual_v2"}' \
  --output speech.mp3
```

## Timestamps

`/with-timestamps` returns JSON with base64 audio and character-level alignment. `/stream/with-timestamps` emits one JSON line per chunk.

```json title="Response shape"
{
  "audio_base64": "SUQzBAAAAAAA…",
  "alignment": { "characters": ["E", "v", "e"], "character_start_times_seconds": [0.0, 0.05, 0.11], "character_end_times_seconds": [0.05, 0.11, 0.18] },
  "normalized_alignment": { "characters": ["E", "v", "e"], "character_start_times_seconds": [0.0, 0.05, 0.11], "character_end_times_seconds": [0.05, 0.11, 0.18] }
}
```

> **History**
> Every generation is recorded and re-downloadable for 30 days. See [History](/docs/voice/history).

## Pricing

| Model | Model id | Price | Unit |
| --- | --- | --- | --- |
| Kokoro 82M | `kokoro-82m` | $3.00 per 1M characters | Input characters |
| Chatterbox | `chatterbox` | $6.00 per 1M characters | Input characters |
| Chatterbox Voice Conversion | `chatterbox-vc` | $0.060 per minute | Input audio, billed per second |
