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

# 克隆音色

> 使用已上传音频的 `file_id` 克隆音色并返回 `voice_id`。启动会话时，将该 ID 传给 `pipeline_config.tts_config.tts_voice_id`。

参考音频必须是最长 15 秒的连续清晰语音，并且能够被转录。请先通过上传音频接口上传。克隆的音色会计入工作区的 `max_voices` 配额。

> [accordion] 参考音频要求
>
> 样本必须是**最长 15 秒**的连续清晰语音，格式为 16 位 WAV、MP3 或 M4A，采样率至少为 16 kHz。支持单声道或立体声；立体声只使用第一个声道。
>
> 需要避免两种失败情况：
>
> * **时间过长。** 超过 15 秒的音频会在创建音色前被拒绝；API 返回 HTTP 400 和 `20004`。
> * **时间过短或不包含语音。** 极短的音频（约半秒以下）以及不包含真实语音的音频会被拒绝，因为服务必须先转录样本，并且要求存在转录文本。建议提供至少几秒钟的正常语音。该情况同样返回 HTTP 400 和 `20004`。

> [accordion] 创建会话时使用音色
>
> ```json theme={null}
> {
>   "pipeline_config": {
>     "tts_config": {
>       "tts_voice_id": "voice_9f1c2a7b"
>     }
>   }
> }
> ```
>
> 将 `tts_voice_id` 设置为返回的音色 ID。该配置无需提供 `provider` 或 `model` 字段。

> [accordion] 错误
>
> 错误响应使用相同的 `{code, message, data}` 封装；非零 `code` 表示具体错误。
>
> | 情况 | 错误码 |
> | - | - |
> | 缺少 `name` 或 `file_id` | `20003 missing required parameter` |
> | `language` 或 `name` 无效 | `20004 invalid parameter` |
> | `file_id` 不存在或不属于当前工作区 | `20005 not found` |
> | `file_id` 不是音频文件 | `20004 invalid parameter` |
> | 样本超过 15 秒 | `20004 invalid parameter` |
> | 样本不包含可转写语音 | `20004 invalid parameter` |
> | 克隆服务商调用失败（HTTP 502） | `30007 voice clone provider failed` |
> | 达到音色配额 `max_voices`（HTTP 403） | `30010 voice clone quota exceeded` |
> | API 密钥缺失或无效 | `10001 missing api key` 或 `10003 invalid api key` |


## OpenAPI

````yaml cn/streaming-avatar/api-references/openapi.json POST /v1/voices
openapi: 3.1.0
info:
  title: Vivix Streaming Avatar API 中文参考
  version: 1.0.0
  description: Streaming Avatar 会话、音色和角色的 REST 接口。
servers:
  - url: https://api.vivix.ai
security:
  - bearerAuth: []
paths:
  /v1/voices:
    post:
      summary: 克隆音色
      description: >-
        使用已上传音频的 `file_id` 克隆音色并返回 `voice_id`。启动会话时，将该 ID 传给
        `pipeline_config.tts_config.tts_voice_id`。


        参考音频必须是最长 15 秒的连续清晰语音，并且能够被转录。请先通过上传音频接口上传。克隆的音色会计入工作区的 `max_voices` 配额。
      operationId: cloneVoice
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: 显示名称，最多 128 个字符。
                file_id:
                  type: string
                  description: 当前工作区中的音频文件 ID（请先调用上传音频接口）。音频最多包含 15 秒连续、清晰的语音。
                language:
                  type: string
                  description: >-
                    示例文本的
                    `language`：`zh`（中文）、`en`（英语）、`fr`（法语）、`de`（德语）、`ja`（日语）、`ko`（韩语）、`ru`（俄语）、`pt`（葡萄牙语）、`th`（泰语）、`id`（印度尼西亚语）、`vi`（越南语）、`it`（意大利语）、`es`（西班牙语）、`ms`（马来语）、`fil`（菲律宾语）、`ar`（阿拉伯语）。
              required:
                - name
                - file_id
            example:
              name: Studio Host
              file_id: file_aud_a1b2c3d4e5f6
              language: zh
      responses:
        '200':
          description: 成功
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                    description: 成功时为 `0`；其他值均为错误码。
                  message:
                    type: string
                    description: '`success`，或英文错误说明。'
                  data:
                    type: object
                    properties:
                      voice_id:
                        type: string
                        description: 音色 ID（格式类似 `voice_…`）。请原样作为 `tts_voice_id` 传入。
                      name:
                        type: string
                        description: 显示名称。
                      language:
                        type: string
                        description: 创建时传入的语言；省略时为空字符串。
                    required:
                      - voice_id
                      - name
                      - language
              example:
                code: 0
                message: success
                data:
                  voice_id: voice_9f1c2a7b
                  name: Studio Host
                  language: zh
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 你的 Vivix API 密钥。请仅保存在服务端。

````

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