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

# Audio to MIDI

> Processes an audio file and converts it into a MIDI file. Optionally generates a sonified .wav and/or a CSV of note events. This request is handled asynchronously.

Convert an audio file into a MIDI file using AI-driven audio analysis and transcription.

The **Audio to MIDI** endpoint processes audio files to generate MIDI sequences. It can optionally create a sonified `.wav` file of the MIDI output and export note events into a `.csv` file for further analysis or editing.
Ideal for music production, remixing, and advanced audio content creation.

***

## Endpoint

```http theme={null}
POST /v1/audio_to_midi
```

This is the primary endpoint for initiating audio-to-MIDI conversion tasks.

***

## Sample Output

Generated MIDI and optional outputs from a sample audio file:

<a href="https://cdn1.wav.com/AudioToMidi/f5b563e5-e414-47ec-989b-255c74d90119.mid" target="_blank">Download MIDI(.mid)</a>

<a href="https://cdn1.wav.com/AudioToMidi/f5b563e5-e414-47ec-989b-255c74d90119.wav" target="_blank">Download Sonified MIDI(.wav)</a>

***

## Try it Yourself

Visit the [Audio to MIDI Endpoint Explorer](/api-documentation/endpoint/audio_to_midi) to test it live. Upload an audio file, and get back the MIDI version!

***

## 🛠️ Request Parameters

| Parameter          | Type      | Required | Default                                                                  | Description                                                    |
| ------------------ | --------- | -------- | ------------------------------------------------------------------------ | -------------------------------------------------------------- |
| `audio_file`       | `File`    | Optional | Upload the audio file directly. Required if `audio_url` is not provided. |                                                                |
| `audio_url`        | `String`  | Optional | URL to the audio file.                                                   |                                                                |
| `sonify_midi`      | `Boolean` | Optional | `true`                                                                   | If `true`, generates a `.wav` file that plays the MIDI output. |
| `save_note_events` | `Boolean` | Optional | `true`                                                                   | If `true`, saves predicted note events as a `.csv` file.       |
| `webhook_url`      | `String`  | Optional | `""`                                                                     | Callback URL for asynchronous result delivery.                 |

> **Note:** Either audio\_file or audio\_url must be provided.

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

***

## Sample Request

### cURL

```bash theme={null}
curl -X POST "https://api.wav.com/api/public/v1/audio_to_midi" \
  -H "Authorization: <API_KEY>" \
  -F "audio_url=<YOUR_AUDIO_URL>" \
  -F "sonify_midi=true" \
  -F "save_note_events=true" \
  -F "webhook_url=https://your-webhook-url.com/callback"
```

### Python

```python theme={null}
import requests

url = "https://api.wav.com/api/public/v1/audio_to_midi"
headers = {"Authorization": "<API_KEY>"}

payload = {
    "sonify_midi": True,
    "save_note_events": True,
    "webhook_url": "https://your-webhook-url.com/callback"
}

# Option 1: audio_url
payload["audio_url"] = "<YOUR_AUDIO_URL>"
response = requests.post(url, headers=headers, data=payload)

# Option 2: File Upload
# with open("audio.wav", "rb") as f:
#     files = {"audio_file": f}
#     response = requests.post(url, headers=headers, data=payload, files=files)

print(response.json())
```

***

## Sample Response

### Success (200 OK)

```json theme={null}
{
 "success": true,
  "task_id": "cf34f4e0-3273-41e4-95e5-05dc745b9852",
  "conversion_id": "0b0b59e5-4c71-49ec-8ca5-5cd05142d5ab",
  "eta": 37,
  "credit_estimate": 0.016,
  "message": "Message published to queue",
  "status": "IN_QUEUE"
}
```

***

### Webhook Response

```json theme={null}
{
  "success": true,
  "conversion_type": "Audio To MIDI",
  "task_id": "cf34f4e0-3273-41e4-95e5-05dc745b9852",
  "conversion_id": "0b0b59e5-4c71-49ec-8ca5-5cd05142d5ab",
  "midi_file_path": "",
  "sonify_file_path": "",
  "notes_file_path": "",
  "message": "Audio To MIDI Completed",
}
```

***

## Common Errors

* **400 Bad Request**: Invalid `audio_path` or missing required parameters.
* **404 Not Found**: Provided audio file not found in S3.
* **422 Unprocessable Entity**: Unsupported audio format.
* **500 Internal Server Error**: An unexpected error occurred while processing.

***

## Payload and Request Formation


## OpenAPI

````yaml POST /v1/audio_to_midi
openapi: 3.1.0
info:
  title: WAV API
  version: 1.0.0
  description: API for retrieving conversion details by ID.
servers:
  - url: https://api.wav.com/api/public
    description: Production server
security: []
paths:
  /v1/audio_to_midi:
    post:
      summary: Convert Audio to MIDI
      description: >-
        Processes an audio file and converts it into a MIDI file. Optionally
        generates a sonified .wav and/or a CSV of note events. This request is
        handled asynchronously.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                audio_url:
                  type: string
                  description: 'Input audio URL (supported format: YouTube URL).'
                  example: https://example.com/audio.mp3
                audio_file:
                  type: string
                  format: binary
                  description: Audio file to upload and process directly.
                sonify_midi:
                  type: boolean
                  default: true
                  description: >-
                    If true, generates a .wav file that sonifies the MIDI
                    output.
                save_note_events:
                  type: boolean
                  default: true
                  description: If true, saves predicted note events as a CSV file.
                webhook_url:
                  type: string
                  description: Callback URL to receive conversion results.
                  example: https://your-webhook-url.com/callback
              anyOf:
                - required:
                    - audio_url
                - required:
                    - audio_file
      responses:
        '200':
          description: Successfully initiated task
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  task_id:
                    type: string
                  conversion_id:
                    type: string
                  eta:
                    type: integer
                  credit_estimate:
                    type: number
                  message:
                    type: string
                  status:
                    type: string
                example:
                  success: true
                  task_id: cf34f4e0-3273-41e4-95e5-05dc745b9852
                  conversion_id: 0b0b59e5-4c71-49ec-8ca5-5cd05142d5ab
                  eta: 37
                  credit_estimate: 0.016
                  message: Message published to queue
                  status: IN_QUEUE
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Missing or invalid audio_url
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Error during MIDI conversion
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: Python
          source: >-
            import requests


            url = "https://api.wav.com/api/public/v1/audio_to_midi"

            headers = {"Authorization": "<API_KEY>"}


            payload = {
                "sonify_midi": True,
                "save_note_events": True,
                "webhook_url": "https://your-webhook-url.com/callback"
            }


            # Option 1: audio_url

            payload["audio_url"] = "<YOUR_AUDIO_URL>"

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


            # Option 2: File Upload

            # with open("audio.wav", "rb") as f:

            #     files = {"audio_file": f}

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


            print(response.json())
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````