Create Unique Music Tracks Effortlessly with Yue's Cognitive Actions

25 Apr 2025
Create Unique Music Tracks Effortlessly with Yue's Cognitive Actions

In the rapidly evolving world of music production, having the right tools can make all the difference. Yue offers developers a powerful set of Cognitive Actions designed to generate music tracks that are not only unique but also tailored to specific requirements. By leveraging the capabilities of the YuE-s1-7B model, these actions simplify the music creation process, allowing for quick generation of diverse musical compositions.

Imagine being able to create original songs complete with lyrics, structured segments, and customizable genres—all in a matter of minutes. Whether you’re developing an application for musicians, content creators, or even for personal projects, Yue's music generation feature will enhance creativity and streamline workflows.

Prerequisites

To get started with Yue's Cognitive Actions, you'll need an API key for access and a basic understanding of how to make API calls.

Generate Music with YuE-s1-7B

The primary action, Generate Music with YuE-s1-7B, allows you to create music tracks featuring multi-language lyrics and customizable song segments. This action is particularly valuable for developers looking to integrate music generation capabilities into their applications.

Purpose

This action solves the challenge of music creation by automating the process of generating unique tracks based on user-defined inputs. It is ideal for creating songs that fit specific moods, genres, or themes, all while maintaining a level of artistic integrity that resonates with listeners.

Input Requirements

To use this action, you'll need to provide several key inputs:

  • Lyrics: A string containing the lyrics structured with tags (e.g., verse, chorus, bridge) to define different sections of the song.
  • Genre Description: A text string that describes the musical style, mood, and vocal characteristics.
  • Maximum New Tokens: An integer that specifies the maximum number of tokens to generate, with values ranging from 500 to 3000.
  • Number of Segments: An integer indicating how many segments of music to generate (1 to 10).
  • Quantization Methods: Options for quantization during the generation process, enhancing performance and reducing resource usage.

Expected Output

The expected output of this action is a direct link to the generated music track in MP3 format. This allows developers to easily integrate the output into their applications or share it with users.

Use Cases for this Specific Action

  • Music Apps: Create a platform where users can generate custom songs for personal use or for sharing on social media.
  • Content Creation: Provide content creators with a tool to quickly generate background music for videos, podcasts, or streams.
  • Educational Tools: Develop applications that help users learn about music composition by generating tracks based on their input.
  • Game Development: Use this action to create dynamic soundtracks that adapt to gameplay or player choices.
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 = "89168af8-3b8c-499b-b9f0-cadfd44dfa20" # Action ID for: Generate Music with YuE-s1-7B

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "lyrics": "[verse]\nStaring at the sunset, colors paint the sky\nThoughts of you keep swirling, can't deny\nI know I let you down, I made mistakes\nBut I'm here to mend the heart I didn't break\n\n[chorus]\nEvery road you take, I'll be one step behind\nEvery dream you chase, I'm reaching for the light\nYou can't fight this feeling now\nI won't back down\nYou know you can't deny it now\nI won't back down\n\n[verse]\nThey might say I'm foolish, chasing after you\nBut they don't feel this love the way we do\nMy heart beats only for you, can't you see?\nI won't let you slip away from me\n\n[chorus]\nEvery road you take, I'll be one step behind\nEvery dream you chase, I'm reaching for the light\nYou can't fight this feeling now\nI won't back down\nYou know you can't deny it now\nI won't back down\n\n[bridge]\nNo, I won't back down, won't turn around\nUntil you're back where you belong\nI'll cross the oceans wide, stand by your side\nTogether we are strong\n\n[outro]\nEvery road you take, I'll be one step behind\nEvery dream you chase, love's the tie that binds\nYou can't fight this feeling now\nI won't back down",
  "genreDescription": "inspiring female uplifting pop airy vocal electronic bright vocal vocal",
  "maximumNewTokens": 1500,
  "numberOfSegments": 2
}

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

Yue's Cognitive Actions for music generation offer an innovative way to create unique tracks quickly and efficiently. By integrating these actions into your applications, you can provide users with a powerful tool that enhances creativity and simplifies the music-making process. Whether for personal projects, content creation, or commercial applications, the possibilities are endless. Start exploring Yue’s music generation capabilities today and unlock new avenues of musical expression!