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

# Text to Speech

> Convert text into streamed audio bytes.

Use `POST /v1/audio/speech` when you want audio output instead of generated text.

This endpoint returns streamed audio bytes, not a JSON text response.

## Required fields

| Field             | Required | Notes                                      |
| ----------------- | -------- | ------------------------------------------ |
| `model`           | Yes      | Text-to-speech model                       |
| `input`           | Yes      | Text to synthesize                         |
| `voice`           | Yes      | Voice preset                               |
| `response_format` | No       | Output audio format such as `mp3` or `wav` |

## Request Example

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

  client = OpenAI(
      base_url="https://api.naga.ac/v1",
      api_key="YOUR_API_KEY",
  )

  speech_file = Path("speech.mp3")

  with client.audio.speech.with_streaming_response.create(
      model="gpt-4o-mini-tts",
      input="Welcome to NagaAI. Your job finished successfully.",
      voice="alloy",
      response_format="mp3",
  ) as response:
      response.stream_to_file(speech_file)
  ```

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

  const client = new OpenAI({
    baseURL: 'https://api.naga.ac/v1',
    apiKey: 'YOUR_API_KEY',
  });

  const response = await client.audio.speech.create({
    model: 'gpt-4o-mini-tts',
    input: 'Welcome to NagaAI. Your job finished successfully.',
    voice: 'alloy',
    response_format: 'mp3',
  });

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

  ```bash cURL theme={null}
  curl https://api.naga.ac/v1/audio/speech \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o-mini-tts",
      "input": "Welcome to NagaAI. Your job finished successfully.",
      "voice": "alloy",
      "response_format": "mp3"
    }' \
    --output speech.mp3
  ```
</CodeGroup>

## Important Difference From Text APIs

This endpoint does not return generated text JSON. It returns streamed audio bytes with a media type such as `audio/mpeg`, `audio/opus`, or `audio/wav`.

## Response Formats

Supported output formats include:

* `mp3`
* `opus`
* `aac`
* `flac`
* `wav`
* `pcm`

## Common mistakes

* expecting a normal JSON response instead of binary audio
* forgetting to write the response to a file or audio buffer
* choosing a response format your playback pipeline does not handle

## Reference

* [Create speech](/api-reference/endpoints/audio/speech)
