> ## 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.

# 文本转语音

> <ul><li>将文本转换为音频</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": "今天天气真好，适合出去散步。",
    "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": "今天天气真好，适合出去散步。",
      "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": "今天天气真好，适合出去散步。",
    "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>
  所有接口均需要使用 Bearer Token 进行认证。

  在请求头中添加：

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

## Body

<ParamField body="model" type="string" required default="tts-1">
  示例：`tts-1`
</ParamField>

<ParamField body="input" type="string" required>
  要转换的文本
</ParamField>

<ParamField body="voice" type="string" required>
  可选值：`alloy`、`echo`、`fable`、`onyx`、`nova`、`shimmer`
</ParamField>

<ParamField body="response_format" type="string" default="mp3">
  可选值：`mp3`、`opus`、`aac`、`flac`、`wav`、`pcm`
</ParamField>

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