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

# Text to Speech

> <ul><li>Convert text to audio</li></ul>

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url 'https://api.elkapi.com/v1/audio/speech' \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "tts-1",
    "input": "The weather is great today, perfect for a walk.",
    "voice": "alloy",
    "response_format": "mp3"
  }'
  ```

  ```python Python theme={null} theme={null}
  import requests

  url = "https://api.elkapi.com/v1/audio/speech"
  headers = {
      "Authorization": "Bearer <token>"
  }
  headers["Content-Type"] = "application/json"
  payload = {
      "model": "tts-1",
      "input": "The weather is great today, perfect for a walk.",
      "voice": "alloy",
      "response_format": "mp3"
  }

  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null} theme={null}
  const url = "https://api.elkapi.com/v1/audio/speech";

  const headers = {
    "Authorization": "Bearer <token>"
  };
  headers["Content-Type"] = "application/json";
  const payload = {
    "model": "tts-1",
    "input": "The weather is great today, perfect for a walk.",
    "voice": "alloy",
    "response_format": "mp3"
  };

  const response = await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(payload)
  });

  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={null}
  "string"
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication.

  Add it to the request headers:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required default="tts-1">
  Example: `tts-1`
</ParamField>

<ParamField body="input" type="string" required>
  Text to convert
</ParamField>

<ParamField body="voice" type="string" required>
  Allowed values: `alloy`, `echo`, `fable`, `onyx`, `nova`, `shimmer`
</ParamField>

<ParamField body="response_format" type="string" default="mp3">
  Allowed values: `mp3`, `opus`, `aac`, `flac`, `wav`, `pcm`
</ParamField>

<ParamField body="speed" type="number" default="1" />
