Effortlessly Transcribe Piano Audio to MIDI with Cognitive Actions

27 Apr 2025
Effortlessly Transcribe Piano Audio to MIDI with Cognitive Actions

In the world of music production and composition, the ability to convert piano audio recordings into MIDI files can be a game changer. Our Piano Transcription service offers developers an advanced solution to accurately transcribe piano performances into digital MIDI format. This service leverages a high-resolution transcription system that utilizes the MAESTRO V2.0.0 dataset, ensuring precise note detection and high fidelity in the transcription process.

Imagine the convenience of transforming your recorded piano pieces into editable MIDI files within moments, enabling seamless integration into digital audio workstations (DAWs) for further manipulation or arrangement. The key benefits of this service include speed, accuracy, and simplification of the transcription process, allowing musicians and producers to focus on creativity rather than manual transcription.

Use Cases

  • Music Production: Quickly convert piano performances into MIDI for use in music production software, allowing for easy editing and arrangement.
  • Learning and Analysis: Students and educators can use the transcription service to analyze piano pieces, gaining insights into note progressions and techniques.
  • Composition: Composers can record their ideas and instantly turn them into MIDI, facilitating instant playback and adjustments.
  • Archiving: Musicians can preserve their performances in a digital format, making it easier to share and collaborate with others.

Prerequisites

To get started with the Piano Transcription service, you'll need a Cognitive Actions API key and a basic understanding of how to make API calls.

Transcribe Piano Audio to MIDI

The primary action of the Piano Transcription service is to transcribe piano audio recordings into MIDI files. This action addresses the need for musicians and producers to convert audio performances into a more manipulable format, enhancing workflow and creative potential.

Input Requirements:
The action requires a single input property:

  • audioInput: A URI pointing to the input audio file, which must be accessible for processing. For example:
    "audioInput": "https://replicate.delivery/mgxm/f1fb0f34-b7ca-45cb-b0a3-4f288f29c6ce/the_entertainer.m4a"
    

Expected Output:
Upon successful transcription, the output will be a link to the generated MIDI file. For instance, the output could resemble:

"https://assets.cognitiveactions.com/invocations/d062aed0-7d47-401f-84df-dc1d3e419d8f/fc442660-3392-4526-8c42-a6bf88480e9b.mp4"

Use Cases for this specific action:

  • Music Producers: Instantly convert their recorded piano improvisations into MIDI to enhance their productions.
  • Educators: Provide students with the ability to transcribe and analyze their performances or famous pieces.
  • Composers: Facilitate the quick transformation of ideas into a digital format that can be easily edited or shared.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "63601323-5318-4e58-9f59-5731e0fb8657" # Action ID for: Transcribe Piano Audio to MIDI

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "audioInput": "https://replicate.delivery/mgxm/f1fb0f34-b7ca-45cb-b0a3-4f288f29c6ce/the_entertainer.m4a"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The Piano Transcription service is an invaluable tool for anyone involved in music creation or education. By offering a reliable and efficient way to convert piano audio into MIDI format, it streamlines workflows and unleashes creative possibilities. Whether you're producing, teaching, or composing, this service allows you to focus on what truly matters—making music.

Take the next step in your music production journey by integrating the Piano Transcription service into your projects and experience the benefits firsthand!