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

# Voice Changer

> Convert the voice from an audio file or URL to a different voice.

Convert the voice from an audio file or URL to a different voice using AI voice models.

The **VoiceChanger** endpoint provides real-time voice transformation by modifying the pitch, removing background noise, and converting the voice using a selected model. Ideal for creative content, dubbing, or personalized audio experiences.

***

## Endpoint

```http theme={null}
POST /VoiceChanger
```

This is the primary endpoint for initiating voice conversion tasks.

***

## Sample Output

Listen to a real sample output:
<audio controls="1" controlslist="nodownload nofullscreen noremoteplayback" src="https://lalals.s3.amazonaws.com/projects/67092f68-045d-4e3c-8006-532f144dd610.mp3">Your browser does not support the audio playback.</audio>

Output File:
<a href="https://lalals.s3.amazonaws.com/projects/67092f68-045d-4e3c-8006-532f144dd610.wav" target="_blank">Download Audio</a>

***

## Try it Yourself

Visit the [VoiceChanger Endpoint Explorer](/api-documentation/endpoint/voicetovoice) to test it live. Upload a sample, pick a voice, and experience real-time voice transformation.

***

## Request Parameters

| Parameter           | Type         | Required | Description                                                                            |
| ------------------- | ------------ | -------- | -------------------------------------------------------------------------------------- |
| `audio_url`         | `String`     | Optional | URL of the audio file to convert. Either `audio_url` or `audio_file` must be provided. |
| `audio_file`        | `UploadFile` | Optional | Upload the audio file directly. Either `audio_url` or `audio_file` must be provided.   |
| `voice_id`          | `String`     | ✅ Yes    | Voice model to convert the audio into.                                                 |
| `remove_background` | `Integer`    | Optional | Set to `1` to remove background noise. Default is `0`.                                 |
| `pitch`             | `Integer`    | Optional | Adjust pitch between -12 and 12 semitones. Default is `0`.                             |
| `webhook_url`       | `String`     | Optional | Callback URL for async response.                                                       |

> 💡**Note:** You must provide either `audio_url` or `audio_file` — not both as `None`.

> **content-type:** multipart/form-data

***

## Sample Request

### cURL

```bash theme={null}
curl -X POST "https://api.musicgpt.com/api/public/v1/VoiceChanger" \
-H "accept: multipart/form-data" \
-H "Authorization: <api_key>" \
-F "audio_url=https://www.youtube.com/watch?v=jGflUbPQfW8" \
-F "voice_id=Drake" \
-F "remove_background=0" \
-F "pitch=0" \
-F "webhook_url=http://webhook.musicgpt.com"
```

### Python

```python theme={null}
import requests

url = "https://api.musicgpt.com/api/public/v1/VoiceChanger"
headers = {
    "accept": "multipart/form-data",
    "Authorization": "<api_key>"
}

input_audio_file = open("{path_to_your_audio_file}", "rb")
payload = {
    "audio_url": "",
    "voice_id": "Drake",
    "pitch": 0,
    "remove_background": 0,
    "webhook_url": "http://abc.requestcatcher.com/test",
}

response = requests.post(url, headers=headers, data=payload, files={"audio_file": input_audio_file})
print(response.json())
```

> 🔐 Replace `{path_to_your_audio_file}`, `api_key`, and `webhook_url` before executing.

***

## Sample Response

### Success (200 OK)

```json theme={null}
{
  "success":true,
  "task_id": "fdcca59e-9788-43fc-9ee6-e9983064c432",  
  "conversion_id":"3b8dd3e8-104a-4a2f-86ba-3ed722f5190a",
  "eta":16,
  "credit_estimate":1.07,
  "message":"",
  "status":"IN_QUEUE"
}
```

***

## Webhook Response

### Success (200 OK)

```json theme={null}
{
  "success": true, 
  "conversion_type": "Voice Conversion", 
  "task_id": "fdcca59e-9788-43fc-9ee6-e9983064c432", 
  "conversion_id": "67092f68-045d-4e3c-8006-532f144dd610", 
  "audio_url": "https://lalals.s3.amazonaws.com/projects/67092f68-045d-4e3c-8006-532f144dd610.mp3", 
  "audio_url_wav": "https://lalals.s3.amazonaws.com/projects/67092f68-045d-4e3c-8006-532f144dd610.wav", 
  "conversion_cost": "0.78", 
  "conversion_duration": 272.44
}
```

***

## Common Errors

* **400 Bad Request**: Invalid or missing input file.
* **402 Payment Required**: Your credit balance is insufficient.
* **422 Unprocessable Entity**: No `audio_url` or `audio_file` provided.
* **500 Internal Server Error**: Something went wrong on our end.

You can download or stream the result directly from the `audio_url`.

***

## Payload and Request Formation


## OpenAPI

````yaml POST /v1/VoiceChanger
openapi: 3.1.0
info:
  title: Musicgpt API
  version: 1.0.0
  description: API for retrieving conversion details by ID.
servers:
  - url: https://api.musicgpt.com/api/public
    description: Production server
security: []
paths:
  /v1/VoiceChanger:
    post:
      summary: Convert voice from audio file or URL
      description: Convert the voice from an audio file or URL to a different voice.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                audio_url:
                  type: string
                  description: URL of audio file to process
                  example: https://example.com/audio.wav
                audio_file:
                  type: string
                  format: binary
                  description: Audio file to upload
                voice_id:
                  type: string
                  description: Voice model ID
                  example: demo-voice-id
                remove_background:
                  type: integer
                  description: 1 to remove background noise, 0 to keep
                  default: 0
                  enum:
                    - 0
                    - 1
                pitch:
                  type: integer
                  description: Pitch adjustment (-12 to +12)
                  default: 0
                  minimum: -12
                  maximum: 12
                webhook_url:
                  type: string
                  description: Callback URL
                  example: https://example.com/callback
              required:
                - voice_id
              anyOf:
                - required:
                    - audio_url
                - required:
                    - audio_file
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  task_id:
                    type: string
                  conversion_id:
                    type: string
                  eta:
                    type: integer
              example:
                success: true
                task_id: 84038e1e-3687-4f7a-9c55-692754b125ee
                conversion_id: e3631817-165d-4f17-a7e2-7008d200ff3e
                eta: 22
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                success: false
                error: The file could not be downloaded from the provided URL
        '402':
          description: Payment Required
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                success: false
                error: Insufficient credit balance
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                success: false
                error: Both audio_url and audio_file cannot be None
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                success: false
                error: Internal Server Error
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: Python
          source: >-
            import requests


            url = "https://api.musicgpt.com/api/public/v1/VoiceChanger"


            payload = {
                "audio_url": "<string>",
                "voice_id": "<string>",
                "remove_background": "<int>",
                "pitch": "<int>",
                "webhook_url": "<string>"
            }


            # For file upload instead of URL:

            # files = {'audio_file': open('filepath', 'rb')}


            headers = {
                "Authorization": "<API Key>"
            }


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

            # For file upload:

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


            print(response.text)
        - lang: PHP
          source: >-
            <?php

            $url = "https://api.musicgpt.com/api/public/v1/VoiceChanger";

            $apiKey = "<API_KEY>";


            // For URL-based processing

            $data = [
                "audio_url" => "<AUDIO_URL>",
                "voice_id" => "<VOICE_ID>",
                "remove_background" => 0, // 0 or 1
                "pitch" => 0, // -12 to +12
                "webhook_url" => "<WEBHOOK_URL>"
            ];


            // For file upload (uncomment and replace)

            // $data = ["voice_id" => "<VOICE_ID>"];

            // $file = new CURLFile('path/to/audio.wav', 'audio/wav',
            'audio_file');


            $headers = [
                "Authorization: " . $apiKey
            ];


            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $url);

            curl_setopt($ch, CURLOPT_POST, 1);

            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

            // For file upload:

            // curl_setopt($ch, CURLOPT_POSTFIELDS, array_merge($data,
            ['audio_file' => $file]));

            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


            $response = curl_exec($ch);

            curl_close($ch);


            echo $response;

            ?>
        - lang: Go
          source: "package main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\turl := \"https://api.musicgpt.com/api/public/v1/VoiceChanger\"\n\tapiKey := \"<API_KEY>\"\n\n\t// For URL-based processing\n\tpayload := map[string]string{\n\t\t\"audio_url\":        \"<AUDIO_URL>\",\n\t\t\"voice_id\":        \"<VOICE_ID>\",\n\t\t\"remove_background\": \"0\",\n\t\t\"pitch\":           \"0\",\n\t\t\"webhook_url\":     \"<WEBHOOK_URL>\",\n\t}\n\n\t// For file upload (uncomment and replace)\n\t// file, _ := os.Open(\"audio.wav\")\n\t// defer file.Close()\n\n\tbody := &bytes.Buffer{}\n\twriter := multipart.NewWriter(body)\n\n\tfor key, val := range payload {\n\t\t_ = writer.WriteField(key, val)\n\t}\n\n\t// For file upload:\n\t// part, _ := writer.CreateFormFile(\"audio_file\", \"audio.wav\")\n\t// io.Copy(part, file)\n\twriter.Close()\n\n\treq, _ := http.NewRequest(\"POST\", url, body)\n\treq.Header.Set(\"Authorization\", apiKey)\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n\tclient := &http.Client{}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\n\tresponse, _ := io.ReadAll(resp.Body)\n\tfmt.Println(string(response))\n}"
        - lang: Java
          source: |-
            import okhttp3.*;

            import java.io.File;
            import java.io.IOException;

            public class VoiceChanger {
                public static void main(String[] args) throws IOException {
                    String url = "https://api.musicgpt.com/api/public/v1/VoiceChanger";
                    String apiKey = "<API_KEY>";

                    // For URL-based processing
                    RequestBody requestBody = new FormBody.Builder()
                            .add("audio_url", "<AUDIO_URL>")
                            .add("voice_id", "<VOICE_ID>")
                            .add("remove_background", "0")
                            .add("pitch", "0")
                            .add("webhook_url", "<WEBHOOK_URL>")
                            .build();

                    // For file upload (uncomment and replace)
                    /*
                    File audioFile = new File("audio.wav");
                    RequestBody requestBody = new MultipartBody.Builder()
                            .setType(MultipartBody.FORM)
                            .addFormDataPart("voice_id", "<VOICE_ID>")
                            .addFormDataPart("audio_file", "audio.wav",
                                    RequestBody.create(audioFile, MediaType.parse("audio/wav")))
                            .build();
                    */

                    Request request = new Request.Builder()
                            .url(url)
                            .post(requestBody)
                            .header("Authorization", apiKey)
                            .build();

                    OkHttpClient client = new OkHttpClient();
                    try (Response response = client.newCall(request).execute()) {
                        System.out.println(response.body().string());
                    }
                }
            }
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````