Create Unique Musical Experiences with the Ardianfe Music Generation Actions

24 Apr 2025
Create Unique Musical Experiences with the Ardianfe Music Generation Actions

In the world of digital creativity, generating personalized music can be a game-changer for applications ranging from video production to interactive experiences. The Ardianfe Music Generation Actions empower developers to create tailored music content through a simple API integration. These pre-built actions allow for customization based on various parameters such as duration, style, and input influences, enabling you to craft unique audio pieces that resonate with your audience.

Prerequisites

Before diving into the integration of the Ardianfe Music Generation Actions, ensure you have the following:

  • API Key: You will need an API key for the Cognitive Actions platform.
  • Setup: Familiarize yourself with basic API request structures, as you will be making HTTP requests to execute the actions.
  • Authentication: Generally, authentication can be handled by passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Custom Music

The Generate Custom Music action allows you to create personalized music by specifying various parameters. This action is particularly useful for developers looking to produce custom audio content based on user input or predefined styles.

Input

The input schema for this action is a structured JSON object that includes several properties:

  • seed (integer): Specifies the seed for the random number generator. A seed of None or -1 will use a random seed.
  • topK (integer): Limits sampling to the top K most probable tokens (default is 250).
  • topP (number): Limits sampling to tokens with a cumulative probability of P (default is 0).
  • prompt (string): A descriptive text prompt for the music to be generated (e.g., "chill music with construction vibes sound behind, dominant in acoustic guitar and piano").
  • duration (integer): Specifies the length of the generated audio in seconds (default is 8 seconds).
  • inputAudio (string): URI of an audio file that influences the generated music.
  • temperature (number): Adjusts the diversity of the sampling process (default is 1).
  • continuation (boolean): If true, the music continues from the input audio; if false, it mimics the melody.
  • modelWeights (string): Specifies the MusicGen model weights to be utilized (default is blank).
  • continuationEnd (integer): Defines the end time for the audio used for continuation (default is the end of the clip).
  • audioOutputFormat (string): Output format for the generated audio (default is "wav").
  • continuationStart (integer): Start time of the audio file used for continuation (default is 0).
  • multiBandDiffusion (boolean): If true, uses MultiBand Diffusion for decoding (only with non-stereo models).
  • classifierFreeGuidance (integer): Controls the extent to which the inputs influence the output (default is 3).
  • audioNormalizationStrategy (string): Determines the method for normalizing audio output (default is "loudness").

Example Input:

{
  "topK": 250,
  "topP": 0,
  "prompt": "chill music with construction vibes sound behind, dominant in acoustic guitar and piano",
  "duration": 60,
  "temperature": 1,
  "continuation": false,
  "audioOutputFormat": "wav",
  "continuationStart": 0,
  "multiBandDiffusion": false,
  "classifierFreeGuidance": 3,
  "audioNormalizationStrategy": "loudness"
}

Output

Upon successful execution, the action returns a URI to the generated audio file. Here’s a sample output:

Example Output:

https://assets.cognitiveactions.com/invocations/c90cc8e7-d572-410f-9acb-4664e1707f9c/a2ffe483-48ff-4864-aff1-5ca4034767aa.wav

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet that demonstrates how to call the Generate Custom Music action using a hypothetical Cognitive Actions execution endpoint:

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 = "3f670a7a-3599-49f7-bf39-bc624fdf6b2e" # Action ID for Generate Custom Music

# Construct the input payload based on the action's requirements
payload = {
  "topK": 250,
  "topP": 0,
  "prompt": "chill music with construction vibes sound behind, dominant in acoustic guitar and piano",
  "duration": 60,
  "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, you will replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the action's requirements, and the endpoint URL is illustrative. The response will provide the URI of the generated music file.

Conclusion

The Ardianfe Music Generation Actions offer a powerful tool for developers looking to integrate custom music generation into their applications. By utilizing the parameters available in the Generate Custom Music action, you can create unique audio experiences tailored to your users' needs. Whether for media production, gaming, or personal projects, the possibilities are endless. Start experimenting with these actions today and bring your creative visions to life!