Create 8-Bit Music with the MusicGen Mario Cognitive Actions

Integrating AI-generated music into your applications has never been easier with the fofr/musicgen-mario Cognitive Actions. This innovative API allows developers to generate music inspired by the classic 8-bit sounds of Super Mario Bros (1985). The MusicGen model offers a range of customizable parameters, enabling you to create unique soundscapes that can enhance your projects, whether for games, interactive media, or creative explorations.
Prerequisites
Before you start using the MusicGen Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which you will use for authentication.
- Basic familiarity with making HTTP requests from your programming environment of choice.
Authentication typically involves passing your API key in the request headers.
Cognitive Actions Overview
Generate Music with Mario Theme
Description: This action generates music using the MusicGen model fine-tuned on 8-bit Super Mario Bros. It allows customization of various parameters, such as the duration of the music, input audio, and output format.
Category: Music Generation
Input
The input schema for this action requires the following fields:
- seed (integer, optional): Specifies the seed for the random number generator. If set to
Noneor-1, a random seed will be automatically used. - topK (integer, optional): Restricts sampling to the top K most probable tokens. Default is
250. - topP (number, optional): Limits sampling to tokens with a cumulative probability of P. Default is
0, which means top_k sampling is used. - prompt (string, required): A descriptive prompt for the desired music output (e.g., "spooky 8bit super mario").
- duration (integer, optional): Duration of the generated audio in seconds. Default is
8. - inputAudio (string, optional): URI of an audio file used to influence the generated music.
- temperature (number, optional): Regulates diversity of sampling. Default is
1. - continuation (boolean, optional): If true, the generated music continues from the
inputAudiomelody. Default isfalse. - customWeights (string, optional): Specifies MusicGen weights to use. Leave blank to use default settings.
- continuationEnd (integer, optional): End time for the audio segment used in continuation. Default is
-1. - audioOutputFormat (string, optional): Format of the output audio file. Possible values are
wavandmp3. Default iswav. - continuationStart (integer, optional): Start time for the audio segment used in continuation. Default is
0. - multiBandDiffusion (boolean, optional): If true, decodes using MultiBand Diffusion. Default is
false. - classifierFreeGuidance (integer, optional): Enhances input influence on the output. Default is
3. - audioNormalizationStrategy (string, optional): Method used for normalizing audio output. Default is
loudness.
Example Input:
{
"topK": 250,
"topP": 0,
"prompt": "spooky 8bit super mario",
"duration": 8,
"temperature": 1,
"continuation": false,
"audioOutputFormat": "wav",
"continuationStart": 0,
"multiBandDiffusion": false,
"classifierFreeGuidance": 3,
"audioNormalizationStrategy": "loudness"
}
Output
The action returns a URL link to the generated audio file. For example:
Example Output:
https://assets.cognitiveactions.com/invocations/8165273c-d0cd-49b5-befb-69ae3d380486/b5697a1e-2ea6-42ca-8e38-04c33dccbda7.wav
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet to illustrate how you can call 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 = "cadc3ae1-33ca-4ae9-897f-5802a8b0ccdb" # Action ID for Generate Music with Mario Theme
# Construct the input payload based on the action's requirements
payload = {
"topK": 250,
"topP": 0,
"prompt": "spooky 8bit super mario",
"duration": 8,
"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 example, replace the placeholder with your actual API key and the endpoint URL. The action ID and input payload are structured based on the requirements of the "Generate Music with Mario Theme" action.
Conclusion
The MusicGen Mario Cognitive Actions empower developers to easily generate nostalgic 8-bit music, providing a unique touch to applications and projects. With customizable options and simple integration, you can create engaging soundscapes that resonate with both retro enthusiasts and new audiences alike. Explore these actions further to enhance your applications and bring your creative visions to life!