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

# 音频模型

> TTS/STT/STS

## 文本转语音

* 端点：/audio/speech
* 主要请求参数：
  * model：用于语音合成的模型，支持的模型列表。
  * input：待转换为音频的文本内容。
  * voice：参考音色，支持系统预置音色、用户预置音色、用户动态音色。

<CodeGroup>
  ```bash bash theme={null}
  curl https://BASE_URL/v1/audio/speech \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o-mini-tts",
      "input": "The quick brown fox jumped over the lazy dog.",
      "voice": "alloy"
    }' \
    --output speech.mp3
  ```

  ```python hello_world.py theme={null}
  from pathlib import Path
  from openai import OpenAI
  client = OpenAI(api_key="API_KEY", base_url="https://BASE_URL/v1")

  speech_file_path = Path(__file__).parent / "speech.mp3"
  with client.audio.speech.with_streaming_response.create(
    model="gpt-4o-mini-tts",
    voice="alloy",
    input="The quick brown fox jumped over the lazy dog."
  ) as response:
    response.stream_to_file(speech_file_path)
  ```
</CodeGroup>

## 语音转文本

* 端点：/audio/transcriptions
* Content-Type: multipart/form-data
* 主要请求参数：
  * model：用于语音转文本的模型，支持的模型列表。
  * file：待转换为文本的音频文件。

<CodeGroup>
  ```bash bash theme={null}
  curl https://BASE_URL/v1/audio/transcriptions \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: multipart/form-data" \
    -F file="@/path/to/file/audio.mp3" \
    -F model="gpt-4o-transcribe"
  ```

  ```python theme={null}
  from openai import OpenAI
  client = OpenAI(api_key="API_KEY", base_url="https://BASE_URL/v1")

  audio_file = open("speech.mp3", "rb")
  transcript = client.audio.transcriptions.create(
    model="gpt-4o-transcribe",
    file=audio_file
  )
  print(transcript.text)
  ```
</CodeGroup>

## 语音转语音

该场景目前仅 `Elevenlabs` 模型支持，请参考对应文档。

## 注意事项

<Warning>
  1. 使用时需要将 `OPENAI_BASE_URL` 设置为 `https://BASE_URL/v1`
  2. `OPENAI_API_KEY` 应设置为您的 API Key
  3. 大部分模型已适配OpenAI生图接口，个别模型未适配，请参考模型文档。
</Warning>
