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

# 上传参考音频

> Upload user-provided voice style, which can be in base64 encoding or file format. Refer to (https://docs.siliconflow.cn/capabilities/text-to-speech#2-2)




## OpenAPI

````yaml post /uploads/audio/voice
openapi: 3.0.0
info:
  title: SiliconFlow API
  description: The SiliconFlow REST API
  version: 1.0.0
  contact:
    name: SiliconFlow Support
    url: https://www.siliconflow.cn/
  license:
    name: MIT
    url: https://github.com/siliconflow/siliconcloud/blob/main/LICENSE
servers:
  - url: https://api.siliconflow.cn/v1
security:
  - bearerAuth: []
paths:
  /uploads/audio/voice:
    post:
      summary: Upload Voice
      description: >
        Upload user-provided voice style, which can be in base64 encoding or
        file format. Refer to
        (https://docs.siliconflow.cn/capabilities/text-to-speech#2-2)
      operationId: uploadAudioVoice
      parameters: []
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                model:
                  type: string
                  example: FunAudioLLM/CosyVoice2-0.5B
                  description: Predefined voice style model name
                customName:
                  type: string
                  example: your-voice-name
                  description: User-defined voice style name
                text:
                  type: string
                  example: 在一无所知中, 梦里的一天结束了，一个新的轮回便会开始
                  description: Corresponding text content for the audio
              required:
                - model
                - customName
                - text
              oneOf:
                - properties:
                    audio:
                      title: Base64 encoding of audio
                      type: string
                      example: data:audio/mpeg;base64,aGVsbG93b3JsZA==
                      description: >-
                        Audio file encoded in base64 with the header format of
                        `data:audio/mpeg;base64`
                - properties:
                    file:
                      title: File upload for audio
                      type: string
                      format: binary
                      example: /path/to/audio.mp3
                      description: File to upload
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  uri:
                    type: string
                    example: speech:your-voice-name:xxx:xxx
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimit'
        '503':
          $ref: '#/components/responses/Overloaded'
        '504':
          $ref: '#/components/responses/Timeout'
      deprecated: false
      x-codeSamples:
        - lang: python
          label: file
          source: >
            import requests


            url = "https://api.siliconflow.cn/v1/uploads/audio/voice"

            headers = {
                "Authorization": "Bearer YOUR_API_KEY" # 从https://cloud.siliconflow.cn/account/ak获取
            }

            files = {
                "file": open("test.mp3", "rb")  # 参考音频文件
            }

            data = {
                "model": "IndexTeam/IndexTTS-2",  # 模型名称
                "customName": "your-voice-name", # 参考音频名称
                "text": "慢工出细活，再给我两分钟，你马上就能见识到超梦分析的厉害了" # 参考音频的文字内容
            }


            response = requests.post(url, headers=headers, files=files,
            data=data)

            print(response.text)
        - lang: curl
          label: file
          source: |
            curl -X POST "https://api.siliconflow.cn/v1/uploads/audio/voice" \
              -H "Authorization: Bearer YOUR_API_KEY" \
              -F "file=@test.mp3" \
              -F "model=IndexTeam/IndexTTS-2" \
              -F "customName=your-voice-name" \
              -F "text=慢工出细活，再给我两分钟，你马上就能见识到超梦分析的厉害了"
        - lang: javaScript
          label: file
          source: |
            // 使用 FormData 处理文件上传
            const formData = new FormData();

            // 添加文件
            const fileInput = document.querySelector('input[type="file"]');
            const file = fileInput.files[0]; // 或者使用 File API 获取文件
            formData.append('file', file);

            // 添加其他字段
            formData.append('model', 'IndexTeam/IndexTTS-2');
            formData.append('customName', 'your-voice-name');
            formData.append('text', '慢工出细活，再给我两分钟，你马上就能见识到超梦分析的厉害了');

            // 发送请求
            const apiKey = 'YOUR_API_KEY'; // 替换为你的 API Key
            const url = 'https://api.siliconflow.cn/v1/uploads/audio/voice';

            fetch(url, {
                method: 'POST',
                headers: {
                    'Authorization': `Bearer ${apiKey}`
                },
                body: formData
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                return response.json();
            })
            .then(data => {
                console.log('Success:', data);
            })
            .catch(error => {
                console.error('Error:', error);
            });
        - lang: python
          label: audio
          source: >
            import requests

            import json

            import base64


            url = "https://api.siliconflow.cn/v1/uploads/audio/voice"

            headers = {
                "Authorization": "Bearer YOUR_API_KEY" , # 从https://cloud.siliconflow.cn/account/ak获取
                "Content-Type": "application/json"
            }

            data = {
                "model": "IndexTeam/IndexTTS-2", # 模型名称
                "customName": "your-voice-name", # 用户自定义的音频名称
                "audio": "data:audio/mpeg;base64," + base64.b64encode(open("x1.mp3", "rb").read()).decode("utf-8"), # 参考音频的 base64 编码
                "text": "慢工出细活，再给我两分钟，你马上就能见识到超梦分析的厉害了" # 参考音频的文字内容
            }


            response = requests.post(url, headers=headers,
            data=json.dumps(data))

            print(response.text)
        - lang: curl
          label: audio
          source: |
            curl -X POST "https://api.siliconflow.cn/v1/uploads/audio/voice" \
              -H "Authorization: Bearer YOUR_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "model": "IndexTeam/IndexTTS-2",
                "customName": "your-voice-name",
                "audio": "data:audio/mpeg;base64,'$(base64 -i x1.mp3 | tr -d '\n')'",
                "text": "慢工出细活，再给我两分钟，你马上就能见识到超梦分析的厉害了"
              }'
        - lang: javaScript
          label: audio
          source: |
            const fs = require('fs');
            const axios = require('axios'); // 需要先安装: npm install axios

            async function uploadAudio() {
                const url = "https://api.siliconflow.cn/v1/uploads/audio/voice";
                
                // 读取音频文件并转换为base64
                const audioBuffer = fs.readFileSync('x1.mp3');
                const base64Audio = audioBuffer.toString('base64');
                
                const headers = {
                    "Authorization": "Bearer YOUR_API_KEY", // 从https://cloud.siliconflow.cn/account/ak获取
                    "Content-Type": "application/json"
                };
                
                const data = {
                    "model": "IndexTeam/IndexTTS-2", // 模型名称
                    "customName": "your-voice-name", // 用户自定义的音频名称
                    "audio": "data:audio/mpeg;base64," + base64Audio, // 参考音频的 base64 编码
                    "text": "慢工出细活，再给我两分钟，你马上就能见识到超梦分析的厉害了" // 参考音频的文字内容
                };
                
                try {
                    const response = await axios.post(url, data, { headers });
                    console.log(response.data);
                } catch (error) {
                    console.error('Error:', error.response ? error.response.data : error.message);
                }
            }

            uploadAudio();
components:
  responses:
    BadRequest:
      description: BadRequest
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/BadRquestData'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UnauthorizedData'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ForbiddenData'
    NotFound:
      description: NotFound
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NotFoundData'
    RateLimit:
      description: RateLimit
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitData'
    Overloaded:
      description: Overloaded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OverloadedtData'
    Timeout:
      description: Timeout
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TimeoutData'
  schemas:
    BadRquestData:
      type: object
      required:
        - message
        - data
        - code
      properties:
        code:
          type: integer
          nullable: true
          default: false
          example: 20012
        message:
          type: string
          nullable: false
        data:
          type: string
          nullable: false
    UnauthorizedData:
      type: string
      default: false
      example: Invalid token
    ForbiddenData:
      type: string
      default: false
      example: Forbidden
    NotFoundData:
      type: string
      default: false
      example: 404 page not found
    RateLimitData:
      type: object
      required:
        - message
        - data
      properties:
        message:
          type: string
          example: >-
            Request was rejected due to rate limiting. If you want more, please
            contact contact@siliconflow.cn. Details:TPM limit reached.
        data:
          type: string
    OverloadedtData:
      type: object
      required:
        - code
        - message
        - data
      properties:
        code:
          type: integer
          example: 50505
        message:
          type: string
          example: Model service overloaded. Please try again later.
        data:
          type: string
          nullable: false
    TimeoutData:
      type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: your api key
      description: >-
        Use the following format for authentication: Bearer [<your api
        key>](https://cloud.siliconflow.cn/account/ak)

````