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

# 文本转语音

<Note>
  注：语音模型名称设置参考[系统支持语音模型列表](https://geekai.co/models)，请求/响应参数结构完全兼容 [OpenAI](https://platform.openai.com/docs/api-reference/audio/createSpeech)，切换模型时只需修改对应的模型名称即可，若模型请求/响应参数和OpenAI不一致，极客智坊底层会自动转换对齐。
</Note>

响应数据格式和 OpenAI 完全兼容，即返回音频文件的二进制数据。

关于文本转语音 API 调用示例，可以参考这里：[文本对话](https://docs.geekai.co/cn/docs/audio/tts)。

### 请求/响应参数明细


## OpenAPI

````yaml openapi.yaml POST /audio/speech
openapi: 3.1.0
info:
  title: 极客智坊 API文档
  description: 极客智坊 API 消息接口规范文档
  version: 1.0.0
servers:
  - url: https://geekai.co/api/v1
    description: 国内代理入口
  - url: https://geekai.dev/api/v1
    description: 海外代理入口
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /audio/speech:
    post:
      tags:
        - Audio
      summary: 语音合成接口
      description: 将文本转换为语音的接口，支持多种语音模型、声音角色和音频格式。
      operationId: createSpeech
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
              properties:
                model:
                  type: string
                  description: 语音模型
                  example: tts-1
                input:
                  type: string
                  description: 需要转换的文本内容
                  example: 你好, 很高兴见到你!
                voice:
                  type: string
                  description: >-
                    声音角色，不同平台支持的声音角色可能不一样，更多细节请查看[文本转语音示例](https://docs.geekai.co/cn/audio/tts)。
                  example: alloy
                response_format:
                  type: string
                  description: >-
                    音频格式，不同平台支持格式可能不一样，更多细节请查看[文本转语音示例](https://docs.geekai.co/cn/audio/tts)。
                  default: mp3
                stream_format:
                  type: string
                  description: 语音输出格式，支持 sse/audio 两种格式，sse表示流式输出，audio表示输出音频文件，默认为audio
                  enum:
                    - sse
                    - audio
                  default: audio
                speed:
                  type: number
                  description: 语速，取值范围[0.25, 1.0, 4.0]，默认1.0，其中豆包语音模型仅支持[0.5, 1, 2]三个档位
                  enum:
                    - 0.25
                    - 0.5
                    - 1
                    - 2
                    - 4
                  default: 1
                instructions:
                  type: string
                  description: 使用额外指令来控制生成的音频音调，仅 `gpt-4o-mini-tts` 模型支持该参数
                retries:
                  type: integer
                  description: 自动重试次数，默认0，表示失败不重试
                  default: 0
      responses:
        '200':
          description: 成功响应
          content:
            audio/mpeg:
              schema:
                type: string
                format: binary
                description: MP3格式音频
            audio/opus:
              schema:
                type: string
                format: binary
                description: Opus格式音频
            audio/aac:
              schema:
                type: string
                format: binary
                description: AAC格式音频
            audio/flac:
              schema:
                type: string
                format: binary
                description: FLAC格式音频
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '413':
          description: 输入文本过长
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          $ref: '#/components/responses/StandardError'
components:
  responses:
    ValidationError:
      description: 参数验证错误
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: validation_error
              message:
                type: string
                example: 参数验证失败
              details:
                type: object
                additionalProperties:
                  type: string
                example:
                  field: 错误描述
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: unauthorized
              message:
                type: string
                example: Invalid API key or token
    StandardError:
      description: 标准错误响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: 错误代码
          example: invalid_request
        message:
          type: string
          description: 错误信息描述
          example: 请求参数不合法
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: API认证token
    apiKeyAuth:
      type: apiKey
      in: header
      name: GeekAI-API-Key
      description: API密钥认证

````