Compose Unique Tracks Effortlessly with MusicGen Gabba Cognitive Actions

21 Apr 2025
Compose Unique Tracks Effortlessly with MusicGen Gabba Cognitive Actions

The MusicGen Gabba Cognitive Actions allow developers to create compelling music tracks by leveraging advanced AI capabilities. By specifying attributes such as genre, tempo, and other parameters, you can generate high-quality audio that can even incorporate existing audio inputs. With features like MultiBand Diffusion and classifier-free guidance, these actions enhance the richness and fidelity of the generated music.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with using REST APIs and handling JSON data.
  • Basic understanding of Python for conceptual code examples.

To authenticate, you will typically pass your API key in the headers of your requests, allowing you to securely access the MusicGen Gabba actions.

Cognitive Actions Overview

Generate Music with MusicGen Gabba

The Generate Music with MusicGen Gabba action enables you to create original music tracks based on a provided prompt and various customizable parameters. This action is categorized under music-generation.

Input

The input schema for this action includes several fields that can be used to tailor the music generation process:

  • seed (integer, optional): Specifies the seed for the random number generator. If set to None or -1, a random seed will be used.
  • topK (integer, optional): Limits sampling to the k most probable tokens. Default is 250.
  • topP (number, optional): Limits sampling to tokens with a cumulative probability of p. Defaults to using top_k sampling if set to 0.
  • prompt (string, required): A textual description of the music to be generated (e.g., "gabba, 180bpm").
  • duration (integer, optional): Duration of the generated audio in seconds (default is 8).
  • inputAudio (string, optional): URI to an audio file influencing the generated music.
  • temperature (number, optional): Defines the variance of the sampling process; higher values indicate more diversity (default is 1).
  • continuation (boolean, optional): When True, the generated music extends the input audio.
  • continuationEnd (integer, optional): Specifies the end time for continuation in the audio file.
  • musicGenWeights (string, optional): Specifies the MusicGen weights to use.
  • audioOutputFormat (string, optional): Defines the format for the generated audio file (default is wav).
  • continuationStart (integer, optional): Specifies the start time in the audio file for continuation.
  • multiBandDiffusion (boolean, optional): Uses MultiBand Diffusion to decode EnCodec tokens.
  • classifierFreeGuidance (integer, optional): Adjusts the input's influence on the output (default is 3).
  • audioNormalizationStrategy (string, optional): Specifies the strategy for audio normalization (default is loudness).

Example Input:

{
  "topK": 250,
  "topP": 0,
  "prompt": "gabba, 180bpm",
  "duration": 20,
  "temperature": 1,
  "continuation": false,
  "audioOutputFormat": "wav",
  "continuationStart": 0,
  "multiBandDiffusion": false,
  "classifierFreeGuidance": 3,
  "audioNormalizationStrategy": "loudness"
}

Output

Upon successful execution, this action returns a URL to the generated audio file. The output will typically look like this:

Example Output:

https://assets.cognitiveactions.com/invocations/19f18e0f-8c02-4740-97ae-4e10165049d6/aad13535-b775-4dd6-99c7-59921cd14781.wav

Conceptual Usage Example (Python)

Here’s how you might implement the Generate Music with MusicGen Gabba action in Python:

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 = "ed346cba-6fec-4e02-98ba-3615da76a07c"  # Action ID for Generate Music with MusicGen Gabba

# Construct the input payload based on the action's requirements
payload = {
    "topK": 250,
    "topP": 0,
    "prompt": "gabba, 180bpm",
    "duration": 20,
    "temperature": 1,
    "continuation": False,
    "audioOutputFormat": "wav",
    "continuationStart": 0,
    "multiBandDiffusion": False,
    "classifierFreeGuidance": 3,
    "audioNormalizationStrategy": "loudness"
}

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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your API key. The payload variable is structured according to the action's input requirements, and the response will give you the URL to the generated music.

Conclusion

The MusicGen Gabba Cognitive Actions provide developers with a powerful tool for generating unique music tracks tailored to specific attributes. By integrating these actions into your applications, you can create customized audio experiences that leverage cutting-edge AI technology. Start experimenting with different prompts and parameters to see what musical masterpieces you can create!