Compose Unique Music with the MusicGen Bacharach Chord Cognitive Actions

23 Apr 2025
Compose Unique Music with the MusicGen Bacharach Chord Cognitive Actions

In the realm of music generation, the MusicGen Bacharach Chord set of Cognitive Actions offers developers a powerful tool to create original compositions by leveraging text-based or audio chord progressions. This specification allows for extensive customization over parameters such as BPM, duration, and output format, thus maximizing creative potential in music production.

Prerequisites

Before you dive into integrating the MusicGen Bacharach Chord actions, ensure you have the following:

  • API Key: You'll need an API key to authenticate your requests to the Cognitive Actions platform. This key should be included in your request headers.
  • Setup: Familiarity with JSON payloads and basic HTTP requests will be beneficial as you work with the Cognitive Actions API.

Authentication typically involves passing your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Music with Chord Progression

The Generate Music with Chord Progression action allows you to create music by processing specified chord progressions while customizing various musical parameters. This action falls under the music-generation category.

Input

The input for this action is structured as follows:

  • seed (optional, integer): Specifies the seed for the random number generator. Set to None or -1 for an automatic random seed.
  • topK (optional, integer): Limits sampling to the k most likely tokens. Default is 250.
  • topP (optional, number): Limits sampling to tokens within the cumulative probability p. Defaults to 0, which means top-k sampling is utilized.
  • prompt (required, string): The initial description or theme of the music (e.g., "bossa nova in the style of burt bacharach").
  • duration (optional, integer): Specifies the audio duration in seconds. Default is 8 seconds.
  • temperature (optional, number): Adjusts sampling variability; higher values yield more diverse outputs.
  • audioEndTime (optional, integer): The ending timestamp of the audio file used for chord conditioning.
  • continuation (optional, boolean): Determines if the music should continue from provided audio chords.
  • outputFormat (optional, string): Specifies the output file format, defaulting to 'wav'.
  • timeSignature (optional, string): Defines the time signature, affecting chord processing.
  • audioStartTime (optional, integer): Specifies the starting timestamp of the audio for chord conditioning.
  • beatsPerMinute (optional, number): Sets the BPM for the output, affecting text chord processing.
  • textBasedChords (optional, string): Defines a chord progression in text format.
  • audioBasedChords (optional, string): An audio file used for chord conditioning.
  • chromaCoefficient (optional, number): Multiplier for processing multi-hot chord chroma.
  • multiBandDiffusion (optional, boolean): Enables decoding of EnCodec tokens using Multi-Band Diffusion.
  • normalizationStrategy (optional, string): Defines the method for normalizing audio output.
  • classifierFreeGuidance (optional, integer): Influences how strongly input shapes the output.

Here’s an example of the input JSON payload you might use:

{
  "topK": 250,
  "topP": 0,
  "prompt": "bossa nova in the style of burt bacharach",
  "duration": 60,
  "temperature": 1,
  "continuation": false,
  "outputFormat": "wav",
  "timeSignature": "4/4",
  "audioStartTime": 0,
  "beatsPerMinute": 90,
  "textBasedChords": "A:min A:min E:min Bb:maj F:maj F:maj D:min,G C,E:min",
  "multiBandDiffusion": false,
  "normalizationStrategy": "loudness",
  "classifierFreeGuidance": 3
}

Output

Upon invoking this action, you can expect a response containing the URL of the generated audio file, as illustrated below:

"https://assets.cognitiveactions.com/invocations/380985a3-d9fa-4333-a1e4-948a1373c8d2/221f19af-563c-45c1-a79d-f78673a50e4c.wav"

This URL links directly to the audio file produced by your specifications.

Conceptual Usage Example (Python)

Below is a conceptual Python snippet demonstrating how you might call the Cognitive Actions execution endpoint for this action:

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 = "9400506b-7b6d-4ee5-adc1-ba6949f20a48"  # Action ID for Generate Music with Chord Progression

# Construct the input payload based on the action's requirements
payload = {
    "topK": 250,
    "topP": 0,
    "prompt": "bossa nova in the style of burt bacharach",
    "duration": 60,
    "temperature": 1,
    "continuation": False,
    "outputFormat": "wav",
    "timeSignature": "4/4",
    "audioStartTime": 0,
    "beatsPerMinute": 90,
    "textBasedChords": "A:min A:min E:min Bb:maj F:maj F:maj D:min,G C,E:min",
    "multiBandDiffusion": False,
    "normalizationStrategy": "loudness",
    "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 code, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable contains the necessary input parameters for generating music. The endpoint URL and request structure are illustrative and may vary based on the actual API specifications.

Conclusion

The MusicGen Bacharach Chord Cognitive Action enables developers to craft unique musical pieces by leveraging advanced parameters and settings. With the ability to manipulate chord progressions, output formats, and more, you can create diverse compositions tailored to your application's needs. Explore the possibilities and let your creativity flow with this powerful tool!