Unlocking Music Insights: Classify Engagement & Approachability with Cognitive Actions

22 Apr 2025
Unlocking Music Insights: Classify Engagement & Approachability with Cognitive Actions

In today's digital landscape, understanding how music resonates with listeners is crucial for artists, producers, and businesses alike. The mtg/music-approachability-engagement API provides powerful Cognitive Actions that allow developers to analyze music tracks in terms of their approachability and engagement. By leveraging transfer learning models and effnet-discogs embeddings, these actions enable you to categorize music effectively, thus enhancing user experience in applications ranging from music recommendation systems to analytics platforms.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests, as you will need to send requests to the Cognitive Actions endpoint.
  • Basic knowledge of JSON to structure your input and handle the output effectively.

Authentication typically involves including your API key in the request headers, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Classify Music Approachability and Engagement

This action utilizes advanced models to classify music based on its approachability and engagement. It can provide outputs in different formats, including binary classifications, trinary classifications, or regression values, making it versatile for various use cases.

  • Category: Sound Classification

Input

The input schema for this action consists of the following fields:

  • url (optional): A string representing the YouTube URL of the music to process. If provided, this overrides the audio input.
  • audio (optional): A string with the URI of the audio file to process. This field should be specified if the YouTube URL is not provided.
  • modelType (required): A string that specifies the type of model to use for processing. Options available are:
    • regression (default)
    • 2 classes
    • 3 classes

Example Input:

{
  "audio": "https://replicate.delivery/mgxm/3a90482a-2a14-435d-8c26-7cb5cb44b5d8/edm.mp3",
  "modelType": "2 classes"
}

Output

The output typically returns a URL pointing to a detailed result of the classification, which may include insights into the approachability and engagement levels of the analyzed music.

Example Output:

https://assets.cognitiveactions.com/invocations/cdef2e07-7266-46f1-a6bf-7403d3f6a29d/8d00733f-b6c9-4f59-bc8c-75498e4b729b.md

Conceptual Usage Example (Python)

Here’s how you might call this action using Python. This snippet demonstrates how to structure the input and send a request to the API:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "5b6a2207-9727-45da-b1a3-20cd75e04ab7" # Action ID for Classify Music Approachability and Engagement

# Construct the input payload based on the action's requirements
payload = {
    "audio": "https://replicate.delivery/mgxm/3a90482a-2a14-435d-8c26-7cb5cb44b5d8/edm.mp3",
    "modelType": "2 classes"
}

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

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this code snippet, you replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id is set to the ID of the action we're invoking. The payload is structured according to the input schema, and the request is sent to the hypothetical endpoint. Upon successful execution, the results are printed in a readable format.

Conclusion

The Cognitive Actions for music approachability and engagement offer developers a robust way to analyze and categorize music tracks. By integrating these actions, you can unlock insights into how music engages listeners, opening doors to innovative applications in various industries. Whether you're building recommendation systems, enhancing user experiences, or conducting music analytics, these tools can significantly enhance your application's capabilities. Start experimenting with the API today to discover the potential it holds for your projects!