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

# 音频 API — 语音转文字与文字转语音

> 通过 /v1/audio/* 端点转录语音、翻译音频为英文或合成语音。兼容 OpenAI Whisper 客户端。

Anyone 提供三个兼容 OpenAI Audio API 的音频端点：语音转文字、音频翻译（任意语言转英文）和文字转语音。请求会自动路由到最佳可用的音频模型。

***

## POST /v1/audio/transcriptions

将音频文件转录为原始语言的文字。兼容 OpenAI Whisper。

### 请求体

此端点使用 `multipart/form-data` 编码。

<ParamField body="model" type="string" required>
  转录模型，例如 `whisper-1`。可用值取决于你配置的渠道。
</ParamField>

<ParamField body="file" type="file" required>
  要转录的音频文件。支持格式：`mp3`、`mp4`、`mpeg`、`mpga`、`m4a`、`ogg`、`wav` 和 `webm`。最大 25 MB。
</ParamField>

<ParamField body="language" type="string">
  音频语言的 ISO-639-1 代码（如 `en`、`zh`、`fr`）。提供此提示可提高准确率和速度。省略时模型自动检测。
</ParamField>

<ParamField body="response_format" type="string">
  转录输出格式。可选 `json`、`text`、`srt`、`verbose_json` 或 `vtt`。默认 `json`。
</ParamField>

<ParamField body="instructions" type="string">
  可选指引文本，用于引导模型的转录风格或词汇。
</ParamField>

### 响应

`response_format: json` 时返回：

<ResponseField name="text" type="string">
  转录的文本。
</ResponseField>

`response_format: verbose_json` 时额外返回：

<ResponseField name="task" type="string">
  始终为 `"transcribe"`。
</ResponseField>

<ResponseField name="language" type="string">
  检测到或指定的语言。
</ResponseField>

<ResponseField name="duration" type="number">
  音频时长（秒）。
</ResponseField>

<ResponseField name="segments" type="object[]">
  按时间对齐的转录片段。

  <Expandable title="片段属性">
    <ResponseField name="id" type="integer">片段索引。</ResponseField>
    <ResponseField name="start" type="number">开始时间（秒）。</ResponseField>
    <ResponseField name="end" type="number">结束时间（秒）。</ResponseField>
    <ResponseField name="text" type="string">该片段的转录文本。</ResponseField>
    <ResponseField name="temperature" type="number">该片段使用的模型温度。</ResponseField>
    <ResponseField name="avg_logprob" type="number">该片段的平均对数概率。</ResponseField>
    <ResponseField name="compression_ratio" type="number">该片段文本的压缩比。</ResponseField>
    <ResponseField name="no_speech_prob" type="number">该片段不含语音的概率。</ResponseField>
  </Expandable>
</ResponseField>

### 示例

```bash curl theme={null}
curl https://api.anyone.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F model="whisper-1" \
  -F file="@recording.mp3" \
  -F language="en" \
  -F response_format="json"
```

***

## POST /v1/audio/translations

将音频文件转录并翻译为英文，不限源语言。

### 请求体

此端点使用 `multipart/form-data` 编码。

<ParamField body="model" type="string" required>
  翻译模型，例如 `whisper-1`。
</ParamField>

<ParamField body="file" type="file" required>
  要翻译的音频文件。格式限制同 `/v1/audio/transcriptions`。
</ParamField>

<ParamField body="response_format" type="string">
  输出格式：`json`、`text`、`srt`、`verbose_json` 或 `vtt`。默认 `json`。
</ParamField>

<ParamField body="instructions" type="string">
  可选指引文本，用于引导模型的翻译风格。
</ParamField>

### 响应

<ResponseField name="text" type="string">
  翻译后的英文文本。
</ResponseField>

### 示例

```bash curl theme={null}
curl https://api.anyone.ai/v1/audio/translations \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F model="whisper-1" \
  -F file="@french-audio.mp3" \
  -F response_format="json"
```

***

## POST /v1/audio/speech

从文本生成语音（文字转语音）。

### 请求体

<ParamField body="model" type="string" required>
  TTS 模型，例如 `tts-1` 或 `tts-1-hd`。`tts-1-hd` 音质更高但成本更高。
</ParamField>

<ParamField body="input" type="string" required>
  要转换为语音的文本。最大 4,096 个字符。
</ParamField>

<ParamField body="voice" type="string" required>
  合成使用的语音。OpenAI TTS 支持 `alloy`、`echo`、`fable`、`onyx`、`nova` 和 `shimmer`。可用语音取决于你配置的服务商。
</ParamField>

<ParamField body="response_format" type="string">
  音频输出格式。可选 `mp3`、`opus`、`aac` 或 `flac`。默认 `mp3`。
</ParamField>

<ParamField body="speed" type="number">
  生成音频的播放速度。取值 `0.25` 到 `4.0`。默认 `1.0`。
</ParamField>

<ParamField body="instructions" type="string">
  可选文本指令，控制语音的风格、语气或节奏。
</ParamField>

### 响应

响应体为指定 `response_format` 的原始音频二进制数据。将 HTTP 客户端设置为直接将响应保存到文件。

### 示例

<CodeGroup>
  ```bash curl theme={null}
  curl https://api.anyone.ai/v1/audio/speech \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "tts-1",
      "input": "Welcome to Anyone, your unified AI gateway.",
      "voice": "nova",
      "response_format": "mp3"
    }' \
    --output speech.mp3
  ```

  ```python python theme={null}
  from openai import OpenAI
  from pathlib import Path

  client = OpenAI(
      api_key="YOUR_TOKEN",
      base_url="https://api.anyone.ai/v1",
  )

  response = client.audio.speech.create(
      model="tts-1",
      voice="nova",
      input="Welcome to Anyone, your unified AI gateway.",
  )

  Path("speech.mp3").write_bytes(response.content)
  ```
</CodeGroup>
