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

# Voice Clone

> MiniMax’s speech models provide robust voice cloning capabilities, allowing you to synthesize preview audio using cloned voices.

## Workflow

The quick cloning feature follows these steps:

1. **Upload the source audio** Use the [File Upload API](/api-reference/file-management-upload) to upload the audio you want to clone and obtain a `file_id`.

* Requirements for uploaded files:
  * Supported formats: mp3, m4a, wav
  * Duration: minimum 10 seconds, maximum 5 minutes
  * File size: up to 20 MB

2. **Upload example audio (optional)** To enhance cloning quality, you can upload an example audio file via the [File Upload API](/api-reference/file-management-upload) and obtain a `file_id`. Include this in `clone_prompt` under `prompt_audio`.

* Requirements for example files:
  * Supported formats: mp3, m4a, wav
  * Duration: less than 8 seconds
  * File size: up to 20 MB

3. **Call the cloning API** Use the obtained `file_id` and a custom `voice_id` as input parameters to call the [Voice Clone API](/guides/speech-voice-clone) to clone the voice.
4. **Use the cloned voice** With the generated `voice_id`, you can call the speech synthesis API as needed, for example:
   * [T2A API](/api-reference/speech-t2a-intro)
   * [T2A Async API](/api-reference/speech-t2a-async-intro)

## Process Examples

### 1. Upload Source Audio

<CodeGroup>
  ```python theme={null}
  """
  Example for obtaining the file_id of the source audio.
  Note: Make sure your API Key is set in the environment variable `MINIMAX_API_KEY`.
  """
  import requests
  import os

  api_key = os.getenv("MINIMAX_API_KEY")
  url = "https://api.minimax.io/v1/files/upload"

  payload = {"purpose": "voice_clone"}
  files = [
    ("file", ("clone_input.mp3", open("/path/to/clone_input.mp3", "rb")))
  ]
  headers = {"Authorization": f"Bearer {api_key}"}

  response = requests.post(url, headers=headers, data=payload, files=files)
  response.raise_for_status()
  file_id = response.json().get("file", {}).get("file_id")
  print(file_id)
  ```

  ```bash theme={null}
  curl --location 'https://api.minimax.io/v1/files/upload' \
    --header 'Authorization: Bearer ${MINIMAX_API_KEY}' \
    --form 'purpose="voice_clone"' \
    --form 'file=@"/path/to/clone_input.mp3"'
  ```
</CodeGroup>

### 2. Upload Example Audio

<CodeGroup>
  ```python theme={null}
  """
  Example for obtaining the file_id of the example audio.
  Note: Ensure `MINIMAX_API_KEY` is set.
  """
  import requests
  import os

  api_key = os.getenv("MINIMAX_API_KEY")
  url = "https://api.minimax.io/v1/files/upload"

  payload = {"purpose": "prompt_audio"}
  files = [
    ("file", ("clone_prompt.mp3", open("/path/to/clone_prompt.mp3", "rb")))
  ]
  headers = {"Authorization": f"Bearer {api_key}"}

  response = requests.post(url, headers=headers, data=payload, files=files)
  response.raise_for_status()
  prompt_file_id = response.json().get("file", {}).get("file_id")
  print(prompt_file_id)
  ```

  ```bash curl theme={null}
  curl --location 'https://api.minimax.io/v1/files/upload' \
  --header 'Authorization: Bearer ${MINIMAX_API_KEY}' \
  --form 'purpose="prompt_audio"' \
  --form 'file=@"/path/to/clone_prompt.mp3"'
  ```
</CodeGroup>

### 3. Clone the Voice

<CodeGroup>
  ```python theme={null}
  """
  Example for voice cloning.
  Note: Set `MINIMAX_API_KEY` in environment variables,
  and replace "<voice_id>", <file_id_of_cloned_voice>, <file_id_of_prompt_audio> with actual values.
  """
  import requests
  import os

  api_key = os.getenv("MINIMAX_API_KEY")
  url = "https://api.minimax.io/v1/voice_clone"

  payload = {
      "file_id": <file_id_of_cloned_voice>,
      "voice_id": "<your_custom_voice_id>",
      "clone_prompt": {
          "prompt_audio": <file_id_of_prompt_audio>,
          "prompt_text": "This voice sounds natural and pleasant."
      },
      "text": "A gentle breeze passes over the soft grass, accompanied by the fresh scent and birdsong.",
      "model": "speech-2.8-hd"
  }

  headers = {
      "Authorization": f"Bearer {api_key}",
      "Content-Type": "application/json"
  }

  response = requests.post(url, headers=headers, json=payload)
  response.raise_for_status()
  print(response.text)
  ```

  ```bash theme={null}
  curl --location 'https://api.minimax.io/v1/voice_clone' \
    --header 'Authorization: Bearer ${MINIMAX_API_KEY}' \
    --header 'Content-Type: application/json' \
    --data '{
        "file_id": <file_id_of_cloned_voice>,
        "voice_id": "<your_custom_voice_id>",
        "clone_prompt": {
          "prompt_audio": <file_id_of_prompt_audio>,
          "prompt_text": "This voice sounds natural and pleasant."
        },
        "text": "A gentle breeze passes over the soft grass, accompanied by the fresh scent and birdsong.",
        "model": "speech-2.8-hd"
    }'
  ```
</CodeGroup>

## Full Example

<CodeGroup>
  ```python theme={null}
  """
  Example demonstrating full voice cloning workflow and obtaining preview audio.
  Note: Set `MINIMAX_API_KEY` in environment variables,
  and replace "<your_custom_voice_id>" with your defined voice ID.
  """
  import requests
  import os

  api_key = os.getenv("MINIMAX_API_KEY")
  upload_url = "https://api.minimax.io/v1/files/upload"
  clone_url = "https://api.minimax.io/v1/voice_clone"
  headers = {"Authorization": f"Bearer {api_key}"}

  # 1. Upload source audio
  with open("/path/to/clone_input.mp3", "rb") as f:
      files = {"file": ("clone_input.mp3", f)}
      data = {"purpose": "voice_clone"}
      response = requests.post(upload_url, headers=headers, data=data, files=files)
      file_id = response.json()["file"]["file_id"]
      print(f"File ID of the cloned audio: {file_id}")

  # 2. Upload example audio
  with open("/path/to/clone_prompt.mp3", "rb") as f:
      files = {"file": ("clone_prompt.mp3", f)}
      data = {"purpose": "prompt_audio"}
      response = requests.post(upload_url, headers=headers, data=data, files=files)
      prompt_file_id = response.json()["file"]["file_id"]
      print(f"File ID of the prompt audio: {prompt_file_id}")

  # 3. Clone the voice
  clone_payload = {
      "file_id": file_id,
      "voice_id": "<your_custom_voice_id>",
      "clone_prompt": {
          "prompt_audio": prompt_file_id,
          "prompt_text": "Humans are creatures of habits, it can be tough"
      },
      "text": "These three nighttime habits will transform your life. First, 15 minutes of prep to set up your first morning tasks. Write them down, pull them up on your screen, whatever it takes to make it easy to hit the ground running the next morning. Second, turn your phone on grayscale mode for the entire evening. It makes your phone 90% less addicting. You will not be inclined to look at it. You won't look at the notifications, and it'll pull you away from that addictive piece of technology sitting in your pocket. And No.3, use my 1-1-1 journaling method.",

      "model": "speech-2.8-hd"
  }
  clone_headers = {
      "Authorization": f"Bearer {api_key}",
      "Content-Type": "application/json"
  }
  clone_headers = {
      "Authorization": f"Bearer {api_key}",
      "Content-Type": "application/json"
  }
  response = requests.post(clone_url, headers=clone_headers, json=clone_payload)
  print(response.text)
  ```
</CodeGroup>

## Example Results

* **Cloned Audio**

<video controls src="https://filecdn.minimax.chat/public/e33ee48c-8b06-4d42-81da-7ee83fbc08c3.m4a" className="audio-container" />

* **Example Audio**

<video controls src="https://filecdn.minimax.chat/public/d87e618c-7e6e-4715-980e-6df872a209d8.m4a" className="audio-container" />

* **Resulting Audio**

<video controls src="https://filecdn.minimax.chat/public/8b3e0782-629e-4169-83a4-87357387f077.mp3" className="audio-container" />

## Recommended Reading

<Columns cols={2}>
  <Card title="Voice Cloning" icon="book-open" href="/api-reference/voice-cloning-clone" cta="Click here">
    Use this API for rapid voice cloning.
  </Card>

  <Card title="Synchronous Text-to-Speech Guide (WebSocket)" icon="book-open" href="/guides/speech-t2a-websocket" cta="Click here">
    Synchronous TTS allows real-time text-to-speech synthesis, handling up to 10,000 characters per request.
  </Card>

  <Card title="Pricing" icon="book-open" href="/guides/pricing-paygo#audio" cta="Click here">
    Detailed information on model pricing and API packages.
  </Card>

  <Card title="Rate Limits" icon="book-open" href="/guides/rate-limits#3-rate-limits-for-our-api#3-rate-limits-for-our-api" cta="Click here">
    Rate limits are restrictions that our API imposes on the number of times a user or client can access our services within a specified period of time.
  </Card>
</Columns>
