Generate Melodic Improvisations with Fadi MusicGen Cognitive Actions

21 Apr 2025
Generate Melodic Improvisations with Fadi MusicGen Cognitive Actions

Integrating artificial intelligence into music creation can open up new realms of creativity and expression. The Fadi MusicGen Cognitive Actions offer a powerful way to generate melodious improvisations rooted in the rich tradition of Arab maqam music. These pre-built actions allow developers to harness the capabilities of AI in their applications, making it easier to create and innovate in the world of music, arts, and humanities.

Prerequisites

To use the Fadi MusicGen Cognitive Actions, you need:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON format for crafting requests.
  • Familiarity with making HTTP requests through programming libraries (e.g., requests in Python).

Authentication generally involves passing your API key in the headers of your requests to ensure secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Arab Maqam Melodic Improvisations

This action uses a fine-tuned version of MusicGen to create Arab maqam melodic improvisations, also known as taqasim. It allows you to generate music that reflects specific styles and emotions, fostering creativity and intercontinental collaborations in the music domain.

Input

The input for this action is structured as follows:

  • 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 the sampling to the top K most likely tokens; default is 250.
  • topP (number, optional): Limits sampling to tokens with a cumulative probability of p; default is 0.
  • prompt (string, required): A detailed description of the music style and emotion you wish to generate. This directly affects the generated output.
  • duration (integer, optional): Length of the generated audio in seconds; default is 8 seconds.
  • inputAudio (string, optional): URI of an audio file influencing the generated music.
  • temperature (number, optional): Adjusts the randomness of the sampling process; default is 1.
  • continuation (boolean, optional): Determines if the generated music continues from the end of the input melody; default is False.
  • continuationEnd (integer, optional): Specifies the end time for using the input audio in continuation mode.
  • musicGenWeights (string, optional): Specifies the MusicGen weights to be used for generation.
  • audioOutputFormat (string, optional): Output format for generated audio (e.g., "wav" or "mp3"); default is "wav".
  • continuationStart (integer, optional): Start time in seconds for using the input audio in continuation mode; default is 0.
  • multiBandDiffusion (boolean, optional): Enables multi-band diffusion during audio decoding; default is False.
  • classifierFreeGuidance (integer, optional): Enhances the influence of input conditions; default is 3.
  • audioNormalizationStrategy (string, optional): Method for normalizing the audio; default is "loudness".

Example Input:

{
  "topK": 250,
  "topP": 0,
  "prompt": "TaqaseemAjam joyful and optimistic high-pitch improvisation slow and romantic",
  "duration": 30,
  "temperature": 1,
  "continuation": false,
  "audioOutputFormat": "wav",
  "continuationStart": 0,
  "multiBandDiffusion": false,
  "classifierFreeGuidance": 3,
  "audioNormalizationStrategy": "loudness"
}

Output

The action typically returns a URL pointing to the generated audio file.

Example Output:

https://assets.cognitiveactions.com/invocations/5983b00c-a74e-47c5-891f-372246e8c690/a1260d55-654a-44d4-b1ae-86de6b61f395.wav

Conceptual Usage Example (Python)

Here’s how you might call the Generate Arab Maqam Melodic Improvisations action using 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 = "b9c87e67-c980-4849-96a4-cd7bd016bf57"  # Action ID for Generate Arab Maqam Melodic Improvisations

# Construct the input payload based on the action's requirements
payload = {
    "topK": 250,
    "topP": 0,
    "prompt": "TaqaseemAjam joyful and optimistic high-pitch improvisation slow and romantic",
    "duration": 30,
    "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 actual API key. The action ID for generating Arab maqam melodic improvisations is included, along with the structured input payload that outlines the music style and parameters.

Conclusion

The Fadi MusicGen Cognitive Actions provide developers with powerful tools for generating unique Arab maqam melodic improvisations. By leveraging these actions, you can create innovative musical experiences that reflect rich cultural heritages. Start experimenting with these capabilities to explore the intersection of AI and music in your applications!