Create Unique Songs Effortlessly with Diffrhythm

26 Apr 2025
Create Unique Songs Effortlessly with Diffrhythm

In today’s digital landscape, creativity meets technology in exciting ways, and music generation is at the forefront of this innovation. Diffrhythm provides developers with a powerful toolset to create full-length songs using advanced latent diffusion techniques. With a focus on speed and simplicity, this service allows for the seamless integration of music generation capabilities into applications, making it easier than ever to produce high-quality audio content.

Imagine a world where you can generate catchy tunes for your next video game, background music for a podcast, or even unique soundtracks for personal projects—all at the click of a button. Whether you're a game developer looking to enhance user experience or a content creator seeking fresh audio material, Diffrhythm opens up a realm of possibilities.

Prerequisites

Before diving into the music generation features of Diffrhythm, ensure you have a Cognitive Actions API key and a basic understanding of making API calls. This will allow you to easily integrate and utilize the capabilities of Diffrhythm in your projects.

Generate Full-Length Song with Latent Diffusion

The "Generate Full-Length Song with Latent Diffusion" action is designed to create complete songs that resonate with your creative vision. By leveraging state-of-the-art latent diffusion techniques, this action streamlines the music creation process, allowing you to focus on the artistic aspects rather than the technical complexities.

Input Requirements:

  • Lyric: A string containing the lyrics of the song, formatted with timestamps (e.g., [00:10.00]Moonlight spills through broken blinds...).
  • Audio Length: An integer specifying the length of the generated song in seconds (currently fixed at 95 seconds).
  • Reference Prompt: A text prompt that serves as a style reference for the song.
  • Reference Audio Path: A URI to an audio file that is used as a reference for tone and style (must be longer than 10 seconds).

Expected Output: The output is a URL linking to the generated audio file of the song, which can be played or downloaded for further use.

Use Cases for this specific action:

  • Game Development: Create immersive soundtracks that adapt to gameplay or enhance narrative elements.
  • Content Creation: Generate unique background music for videos, podcasts, or live streams, providing a fresh auditory experience for your audience.
  • Personal Projects: Craft custom songs for events, presentations, or personal enjoyment without needing extensive music production skills.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "04977128-5bac-40ff-b30d-0ad3e30c228a" # Action ID for: Generate Full-Length Song with Latent Diffusion

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "lyric": "[00:10.00]Moonlight spills through broken blinds\n[00:13.20]Your shadow dances on the dashboard shrine\n[00:16.85]Neon ghosts in gasoline rain\n[00:20.40]I hear your laughter down the midnight train\n[00:24.15]Static whispers through frayed wires\n[00:27.65]Guitar strings hum our cathedral choirs\n[00:31.30]Flicker screens show reruns of June\n[00:34.90]I'm drowning in this mercury lagoon\n[00:38.55]Electric veins pulse through concrete skies\n[00:42.10]Your name echoes in the hollow where my heartbeat lies\n[00:45.75]We're satellites trapped in parallel light\n[00:49.25]Burning through the atmosphere of endless night\n[01:00.00]Dusty vinyl spins reverse\n[01:03.45]Our polaroid timeline bleeds through the verse\n[01:07.10]Telescope aimed at dead stars\n[01:10.65]Still tracing constellations through prison bars\n[01:14.30]Electric veins pulse through concrete skies\n[01:17.85]Your name echoes in the hollow where my heartbeat lies\n[01:21.50]We're satellites trapped in parallel light\n[01:25.05]Burning through the atmosphere of endless night\n[02:10.00]Clockwork gears grind moonbeams to rust\n[02:13.50]Our fingerprint smudged by interstellar dust\n[02:17.15]Velvet thunder rolls through my veins\n[02:20.70]Chasing phantom trains through solar plane\n[02:24.35]Electric veins pulse through concrete skies\n[02:27.90]Your name echoes in the hollow where my heartbeat lies",
  "audioLength": 95,
  "referenceAudioPath": "https://replicate.delivery/pbxt/Md2hz8ACgvWtwu2szfoq5WPDM3w3GaM2r9oWKtzZ4inPRch5/jourdelune%20-%20MUSIIIIIIIIIIIC%20-%20Sonauto.wav"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

Diffrhythm empowers developers to explore the realm of music generation with ease, transforming the way audio content is created. With the ability to generate full-length songs quickly and efficiently, you can enhance your projects and engage your audience like never before. Whether for commercial applications or personal endeavors, the potential for creativity is vast. Start your journey with Diffrhythm today and unlock new sonic possibilities for your applications!