# 文字转语音

**API:** Model API

**Endpoint:** `POST /api/v1/audio/speech`

**Tags:** Audio

Use model to select the speech generation model. Channel selection is unavailable for speech generation requests.

## Base URL

- `https://openapi.felo.ai` — 生产环境

## Authentication

- `FeloBearerAuth` (http bearer) — 以 `Authorization: Bearer <key>` 形式发送的 Felo API 密钥。
- `FeloApiKey` (apiKey in header `X-API-Key`) — 以 `X-API-Key: <key>` 形式发送的 Felo API 密钥。

## Request body

Required: **yes**

### application/json

Schema:

```json
{
  "type": "object",
  "required": [
    "model",
    "input"
  ],
  "additionalProperties": false,
  "properties": {
    "model": {
      "type": "string",
      "maxLength": 256
    },
    "input": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4096
    },
    "voice": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "description": "Optional non-blank voice ID. The upstream model determines whether a voice is required and which IDs it accepts. Catalog voices are examples."
    },
    "response_format": {
      "type": "string",
      "enum": [
        "pcm",
        "mp3"
      ],
      "default": "pcm"
    },
    "speed": {
      "type": "number",
      "default": 1,
      "description": "Currently only 1 is supported."
    }
  }
}
```

## Responses

### 200 — 成功返回原始音频：MP3 为 `audio/mpeg`，裸 PCM 为 `audio/pcm`，不是 WAV、JSON 或 SSE。播放前检查 HTTP 状态并确认传输完整；`--fail` 避免把 HTTP 错误正文写进音频文件。断连可能留下不完整文件，应丢弃。播放裸 PCM 需要渠道对应的音频参数，不要自行猜测。 计费以发布渠道为准：STT 可能按 `input_audio_second` 秒价或 token 计价；TTS 使用 `input_character`。检查 `speech_billing_unit`：`utf16_code_unit` 与 `unicode_code_point` 对 emoji 的计数不同。预占是估算，不是费用上限；最终结算可能异步完成，证据缺失不表示免费。两个接口都接受 `X-Felo-Channel`，仅向选定渠道派发一次。超时或断连后不要自动重试，包括 SDK 默认重试；保留 `X-Request-Id` 及可用的 `X-Generation-Id` 供核对。Console Playground 暂未支持这些语音调用。 `configured_rates` 按冻结费率和可信用量结算；`upstream_cost` 按可信上游成本及发布的加价、折扣结算。

**audio/mpeg**

Schema: string, (binary)

```json
{
  "type": "string",
  "format": "binary"
}
```

**audio/pcm**

Schema: string, (binary)

```json
{
  "type": "string",
  "format": "binary"
}
```
