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

# Create Speech

> Generate audio from text using the Nineninesix TTS API.

## POST /tts/bytes

Generates audio from the input transcript. The response body is the raw audio in the requested format, streamed as it's generated.

### Request Body

| Parameter       | Type   | Required | Description                                              |
| --------------- | ------ | -------- | -------------------------------------------------------- |
| `model_id`      | string | Yes      | The TTS model. Currently `gepard-1.0`.                   |
| `transcript`    | string | Yes      | The text to synthesize.                                  |
| `voice`         | object | Yes      | Voice specifier: `{ "mode": "id", "id": "<voice-id>" }`. |
| `output_format` | object | Yes      | Output format (see below).                               |
| `language`      | string | No       | Language code (e.g. `en`).                               |

### Output Format

`output_format` has three fields, each validated against a fixed set. Anything outside these values returns `400` — the API does not silently fall back.

| Field         | Allowed values                       |
| ------------- | ------------------------------------ |
| `container`   | `raw`, `wav`                         |
| `encoding`    | `pcm_s16le`, `pcm_mulaw`, `pcm_alaw` |
| `sample_rate` | `8000`, `16000`, `22050`             |

* The model is natively **22050 Hz** — use it to skip resampling; `8000`/`16000` are resampled server-side.
* **Container by endpoint:** `wav` is available **only on `/tts/bytes`**. Streaming endpoints (`/tts/sse`, `/tts/websocket`) are **`raw`-only** — there's no place to put a RIFF/WAV header in a chunked stream.
* **`pcm_mulaw` / `pcm_alaw`** are 8-bit G.711 telephony codecs. Browsers can't play them directly; decode to linear PCM first (or hand them straight to your telephony stack).

```json theme={null}
// WAV (PCM) — /tts/bytes only
{ "container": "wav", "encoding": "pcm_s16le", "sample_rate": 22050 }
// Raw PCM — lowest latency for streaming pipelines
{ "container": "raw", "encoding": "pcm_s16le", "sample_rate": 22050 }
```

#### Telephony (G.711)

For Twilio / SIP media streams, request 8 kHz μ-law or A-law raw:

```json theme={null}
// μ-law @ 8 kHz (US/telephony)
{ "container": "raw", "encoding": "pcm_mulaw", "sample_rate": 8000 }
// A-law @ 8 kHz (EU/telephony)
{ "container": "raw", "encoding": "pcm_alaw", "sample_rate": 8000 }
```

<Warning>
  **Removed formats.** `mp3` (container) and `pcm_f32le` (encoding), plus sample
  rates `24000` / `44100` / `48000`, are **not supported** and now return `400`.
  Request `wav` + `pcm_s16le` and transcode client-side if you need another format.
</Warning>

### Models

| Model        | Description                                                                       |
| ------------ | --------------------------------------------------------------------------------- |
| `gepard-1.0` | Dialogue-native model, tuned for conversational speech and low-latency streaming. |

### Billing

1 credit = 1 character of `transcript` (Unicode code points). The charge is taken before generation and refunded automatically on failure.

### Examples

<CodeGroup>
  ```bash curl theme={null}
  curl -N https://api.nineninesix.ai/tts/bytes \
    -H "Authorization: Bearer sk_996_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "model_id": "gepard-1.0",
      "transcript": "Today is a wonderful day to build something people love!",
      "voice": { "mode": "id", "id": "<voice-id>" },
      "output_format": { "container": "wav", "encoding": "pcm_s16le", "sample_rate": 22050 }
    }' --output speech.wav
  ```

  ```python Python theme={null}
  from cartesia import Cartesia

  client = Cartesia(api_key="sk_996_your_api_key", base_url="https://api.nineninesix.ai")

  audio = client.tts.bytes(
      model_id="gepard-1.0",
      transcript="Today is a wonderful day to build something people love!",
      voice={"mode": "id", "id": "<voice-id>"},
      output_format={"container": "wav", "encoding": "pcm_s16le", "sample_rate": 22050},
  )

  with open("speech.wav", "wb") as f:
      f.write(audio)
  ```

  ```typescript Node.js theme={null}
  import { Cartesia } from "@cartesia/cartesia-js";

  const client = new Cartesia({ apiKey: "sk_996_your_api_key", baseURL: "https://api.nineninesix.ai" });

  const res = await client.tts.generate({
    model_id: "gepard-1.0",
    transcript: "Today is a wonderful day to build something people love!",
    voice: { mode: "id", id: "<voice-id>" },
    output_format: { container: "wav", encoding: "pcm_s16le", sample_rate: 22050 },
  });

  const buffer = Buffer.from(await res.arrayBuffer());
  fs.writeFileSync("speech.wav", buffer);
  ```
</CodeGroup>

## POST /tts/sse

Streams audio over Server-Sent Events for low time-to-first-audio without opening a WebSocket. The request body is identical to `/tts/bytes`, except the container must be `raw` (SSE can't wrap a WAV/RIFF header):

```json theme={null}
{ "container": "raw", "encoding": "pcm_s16le", "sample_rate": 22050 }
```

Each event's `data` is a JSON object. `chunk` events carry a base64-encoded slice of raw PCM; a final `done` event closes the stream:

```
data: {"type":"chunk","data":"<base64 pcm>","context_id":"..."}
data: {"type":"chunk","data":"<base64 pcm>","context_id":"..."}
data: {"type":"done","context_id":"..."}
```

Billing is identical to `/tts/bytes` — one pre-charge on the full transcript, confirmed when the stream completes.

<CodeGroup>
  ```typescript Node.js theme={null}
  import { Cartesia } from "@cartesia/cartesia-js";

  const client = new Cartesia({ apiKey: "sk_996_your_api_key", baseURL: "https://api.nineninesix.ai" });

  const stream = await client.tts.generateSSE({
    model_id: "gepard-1.0",
    transcript: "Streaming speech, chunk by chunk.",
    voice: { mode: "id", id: "<voice-id>" },
    output_format: { container: "raw", encoding: "pcm_s16le", sample_rate: 22050 },
  });

  for await (const message of stream) {
    if (message.type === "chunk") {
      const pcm = Buffer.from(message.data, "base64"); // feed into your audio sink
    }
  }
  ```

  ```python Python theme={null}
  import base64
  from cartesia import Cartesia

  client = Cartesia(api_key="sk_996_your_api_key", base_url="https://api.nineninesix.ai")

  for message in client.tts.sse(
      model_id="gepard-1.0",
      transcript="Streaming speech, chunk by chunk.",
      voice={"mode": "id", "id": "<voice-id>"},
      output_format={"container": "raw", "encoding": "pcm_s16le", "sample_rate": 22050},
  ):
      if message.type == "chunk":
          pcm = base64.b64decode(message.data)  # feed into your audio sink
  ```
</CodeGroup>

## WebSocket Streaming

For real-time, low-latency generation over a persistent connection —
`wss://api.nineninesix.ai/tts/websocket` — see the
[WebSocket Streaming](/api-reference/tts/websocket) page, which includes the
send/receive message schemas and an interactive **Connect** playground.
