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

# Text to Speech

> Convert text to lifelike audio using OpenAI TTS and other voice models.

## Endpoint

```http theme={null}
POST https://api.samuraiapi.in/v1/audio/speech
```

## Parameters

| Parameter         | Type   | Required | Description                                   |
| ----------------- | ------ | -------- | --------------------------------------------- |
| `model`           | string | ✅        | `tts-1` or `tts-1-hd`                         |
| `input`           | string | ✅        | Text to convert (max 4096 chars)              |
| `voice`           | string | ✅        | Voice preset (see below)                      |
| `response_format` | string | —        | `mp3` (default), `opus`, `aac`, `flac`, `wav` |
| `speed`           | number | —        | Speed: 0.25–4.0. Default: `1.0`               |

## Available Voices

| Voice     | Character             |
| --------- | --------------------- |
| `alloy`   | Neutral, versatile    |
| `echo`    | Male, authoritative   |
| `fable`   | British, storytelling |
| `onyx`    | Deep, powerful        |
| `nova`    | Female, friendly      |
| `shimmer` | Female, soft          |

## Code Examples

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI
  from pathlib import Path

  client = OpenAI(
      api_key="sk-samurai-YOUR_KEY",
      base_url="https://api.samuraiapi.in/v1"
  )

  response = client.audio.speech.create(
      model="tts-1-hd",
      voice="nova",
      input="The way of the samurai is found in death. Meditation on inevitable death...",
      speed=0.9
  )

  response.stream_to_file(Path("output.mp3"))
  print("Saved to output.mp3")
  ```

  ```javascript Node.js theme={null}
  import fs from 'fs';

  const response = await client.audio.speech.create({
    model: 'tts-1-hd',
    voice: 'onyx',
    input: 'The way of the samurai is found in death.',
    speed: 1.0
  });

  const buffer = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync('output.mp3', buffer);
  ```

  ```bash cURL theme={null}
  curl https://api.samuraiapi.in/v1/audio/speech \
    -H "Authorization: Bearer sk-samurai-YOUR_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "tts-1",
      "voice": "nova",
      "input": "Hello from Samurai AI!"
    }' \
    --output speech.mp3
  ```
</CodeGroup>

## Models

| Model      | Quality       | Latency | Price           |
| ---------- | ------------- | ------- | --------------- |
| `tts-1`    | Standard      | Lower   | \$7.50/1M chars |
| `tts-1-hd` | High fidelity | Higher  | \$15/1M chars   |

<Info>
  Samurai AI prices are 50% off. `tts-1` is **\$3.75/1M characters**.
</Info>
