Create Captivating Music with the Sakemin MusiConGen Cognitive Actions

25 Apr 2025
Create Captivating Music with the Sakemin MusiConGen Cognitive Actions

In the ever-evolving landscape of music creation, the Sakemin MusiConGen API stands out as a powerful tool for generating customized musical compositions. The Cognitive Actions provided by this API empower developers to transform textual descriptions into rich audio experiences by controlling various musical elements such as rhythm, chords, tempo, and instrumentation. This article explores how to leverage these pre-built actions to enhance your applications with unique musical outputs.

Prerequisites

Before diving into the integration of the Sakemin MusiConGen Cognitive Actions, ensure you have the following:

  • API Key: You will need an API key to authenticate your requests to the MusiConGen platform.
  • Internet Access: Since the API operates in the cloud, an internet connection is required to send requests and receive responses.

Authentication typically involves including your API key in the request headers, ensuring secure access to the API.

Cognitive Actions Overview

Generate Music with Rhythm and Chord Control

Description: This action allows you to generate music by controlling rhythm and chords through a text-to-music transformation. Users can specify chord progressions, tempo, time signatures, and instrument configurations, enabling a diverse range of musical outputs.

Category: Music Generation

Input

The input for this action is structured according to the following schema:

{
  "seed": "integer (optional)",
  "topK": "integer (default: 250)",
  "topP": "number (default: 0)",
  "prompt": "string (required)",
  "duration": "integer (default: 30, maximum: 30)",
  "temperature": "number (default: 1)",
  "outputFormat": "string (default: 'wav', enum: ['wav', 'mp3'])",
  "timeSignature": "string (default: '4/4')",
  "beatsPerMinute": "number (default: 120)",
  "textBasedChords": "string (default: 'C G A:min F')",
  "classifierFreeGuidance": "integer (default: 3)"
}

Example Input:

{
  "topK": 250,
  "topP": 0,
  "prompt": "A laid-back blues shuffle with a relaxed tempo, warm guitar tones, and a comfortable groove, perfect for a slow dance or a night in. Instruments: electric guitar, bass, drums.",
  "duration": 30,
  "temperature": 1,
  "outputFormat": "wav",
  "timeSignature": "4/4",
  "beatsPerMinute": 120,
  "textBasedChords": "C G A:min F",
  "classifierFreeGuidance": 3
}

Output

Upon successful execution, this action returns the URL to the generated audio file, typically in WAV format.

Example Output:

https://assets.cognitiveactions.com/invocations/ad866516-93f9-44f6-ac37-e4926001d4d6/4bef98a8-8c71-42f1-b344-4035b747308e.wav

Conceptual Usage Example (Python)

Here’s how you might invoke this action using Python to generate music:

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 = "9984dec8-57f9-4480-a63a-49c60597f742"  # Action ID for Generate Music with Rhythm and Chord Control

# Construct the input payload based on the action's requirements
payload = {
    "topK": 250,
    "topP": 0,
    "prompt": "A laid-back blues shuffle with a relaxed tempo, warm guitar tones, and a comfortable groove, perfect for a slow dance or a night in. Instruments: electric guitar, bass, drums.",
    "duration": 30,
    "temperature": 1,
    "outputFormat": "wav",
    "timeSignature": "4/4",
    "beatsPerMinute": 120,
    "textBasedChords": "C G A:min F",
    "classifierFreeGuidance": 3
}

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 example, replace the placeholder for COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the action's input schema, ensuring that you provide all required fields.

Conclusion

The Sakemin MusiConGen Cognitive Actions open up a world of possibilities for music generation within your applications. By harnessing the power of these pre-built actions, you can easily create unique musical compositions tailored to specific moods and styles. Whether you're building a game, an interactive application, or a creative tool, these actions will enhance user experiences with captivating audio. Start experimenting with the provided action today and explore the creative potentials it unlocks!