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

# 生成语音

> 使用指定的语音和格式将文本转换为 TTS 音频。

## 语音映射

`voice` 会根据供应商通过内部别名映射进行规范化：

* `openai`: 常用语音（例如 `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`, `shimmer`, `verse`, `cedar`, `marin`).
* `google` (AI Studio / Gemini TTS): 规范的预置语音：
  `Zephyr`, `Puck`, `Charon`, `Kore`, `Fenrir`, `Leda`, `Orus`, `Aoede`, `Callirrhoe`, `Autonoe`, `Enceladus`, `Iapetus`, `Umbriel`, `Algieba`, `Despina`, `Erinome`, `Algenib`, `Rasalgethi`, `Laomedeia`, `Achernar`, `Alnilam`, `Schedar`, `Gacrux`, `Pulcherrima`, `Achird`, `Zubenelgenubi`, `Vindemiatrix`, `Sadachbia`, `Sadaltager`, `Sulafat`.
* `elevenlabs`: 常见的公开入门语音会进行映射（例如 `rachel`, `domi`, `bella`, `antoni`, `elli`, `josh`, `arnold`, `adam`, `sam`).

对于 `eleven-labs/eleven-v4` 和 `eleven-labs/eleven-v4-turbo`，可传入任意 20 字符的 ElevenLabs 音色库 ID，包括自定义克隆音色。按需设置 `config.elevenlabs.voice_settings.stability` 和 `similarity_boost`。Eleven v4 不支持 `speed` 或 `voice_settings.style`。

如果提供的 `voice` 对路由对应的供应商/模型无效，请求会返回 `400 invalid_request_error`，并附带 `param: "voice"`。

## 供应商覆盖项

你仍可以传入供应商原生语音设置：

* ElevenLabs: `config.elevenlabs.voice_id` / `config.elevenlabs.voice` / `config.elevenlabs.voiceName`
* Google: `config.google.voice_name` / `config.google.voiceName`

为便于移植，建议将顶层 `voice` 作为默认值。

## 语音示例

* OpenAI: [openai.fm](https://www.openai.fm/)
* Google TTS 语音示例： [Gemini 文字转语音文档](https://ai.google.dev/gemini-api/docs/speech-generation#voices)
* ElevenLabs 语音库: [ElevenLabs Voice Library](https://elevenlabs.io/voice-library)


## OpenAPI

````yaml zh-Hans/openapi/v1/openapi.localized.yaml POST /audio/speech
openapi: 3.0.3
info:
  title: Phaseo Gateway API
  description: 通过兼容 OpenAI 的端点访问各种 AI 模型的网关 API。
  version: 1.0.0
  contact:
    name: Phaseo
    url: https://phaseo.app
    email: danielbutler500@gmail.com
servers:
  - url: https://api.phaseo.app/v1
    description: 全球路由
security:
  - BearerAuth: []
tags:
  - name: Gateway
    description: Core Phaseo Gateway operations.
paths:
  /audio/speech:
    post:
      tags:
        - Gateway
      summary: 生成语音
      description: 根据输入文本生成音频。
      operationId: createSpeech
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AudioSpeechRequest'
      responses:
        '200':
          description: 音频文件
          content:
            audio/mpeg:
              schema:
                type: string
                format: binary
components:
  schemas:
    AudioSpeechRequest:
      type: object
      required:
        - model
        - input
      properties:
        model:
          type: string
        input:
          type: string
        voice:
          type: string
        speed:
          type: number
          minimum: 0.25
          maximum: 4
        format:
          type: string
          enum:
            - mp3
            - wav
            - ogg
            - aac
        provider:
          $ref: '#/components/schemas/ProviderRoutingOptions'
        config:
          type: object
          additionalProperties: true
          properties:
            elevenlabs:
              type: object
              additionalProperties: true
              properties:
                voice_id:
                  type: string
                language_code:
                  type: string
                output_format:
                  type: string
                voice_settings:
                  type: object
                  additionalProperties: true
                  properties:
                    stability:
                      type: number
                    similarity_boost:
                      type: number
    ProviderRoutingOptions:
      type: object
      description: 用于网关选择的提供商路由偏好设置。
      properties:
        order:
          type: array
          items:
            type: string
        only:
          type: array
          items:
            type: string
        ignore:
          type: array
          items:
            type: string
        include_alpha:
          type: boolean
          description: 在路由中包含 alpha 提供商（默认关闭）。
        allow_fallbacks:
          type: boolean
          nullable: true
          description: 失败后允许回退到其他符合条件的提供商。
        require_parameters:
          type: boolean
          nullable: true
          description: 路由前要求提供商支持所请求的参数。
        required_execution_region:
          type: string
          nullable: true
          description: 将路由限制为具有所需执行区域的提供商。
        required_data_region:
          type: string
          nullable: true
          description: 将路由限制为具有所需数据区域的提供商。
        require_zero_data_retention:
          type: boolean
          nullable: true
          description: 将路由限制为支持零数据保留的提供商。
        data_collection:
          type: string
          nullable: true
          enum:
            - allow
            - deny
        zdr:
          type: boolean
          nullable: true
        enforce_distillable_text:
          type: boolean
          nullable: true
        quantizations:
          type: array
          nullable: true
          items:
            type: string
        sort:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          description: 为此请求排列提供商，例如按价格、延迟或吞吐量排序。
        max_price:
          type: object
          properties:
            prompt:
              oneOf:
                - type: number
                - type: string
            completion:
              oneOf:
                - type: number
                - type: string
            image:
              oneOf:
                - type: number
                - type: string
            audio:
              oneOf:
                - type: number
                - type: string
            request:
              oneOf:
                - type: number
                - type: string
        preferred_min_throughput:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
        preferred_max_latency:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Bearer 令牌身份验证

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.