म्यूज़िक क्विकस्टार्ट

Music API से म्यूज़िक जनरेट करना सीखें।

यह गाइड आपको हमारे Music API से संगीत जनरेट करना दिखाएगी।

अपने AI कोडिंग असिस्टेंट से संगीत ट्रैक जनरेट करने के लिए ElevenLabs music skill का इस्तेमाल करें:

npx skills add elevenlabs/skills --skill music
Music API सिर्फ़ पेड यूज़र्स के लिए उपलब्ध है।

Music API का इस्तेमाल

1

API key बनाएं

डैशबोर्ड में यहां API key बनाएं, जिसका इस्तेमाल आप API एक्सेस करने के लिए सुरक्षित रूप से करेंगे।

key को मैनेज्ड सीक्रेट के रूप में स्टोर करें और अपनी पसंद के अनुसार इसे SDKs को .env फ़ाइल के ज़रिए एनवायरनमेंट वेरिएबल के रूप में या सीधे अपने ऐप के कॉन्फ़िगरेशन में पास करें।

.env
ELEVENLABS_API_KEY=<your_api_key_here>
2

SDK इंस्टॉल करें

हम अपने API key को environment variable से लोड करने के लिए dotenv library का भी इस्तेमाल करेंगे।

pip install elevenlabs
pip install python-dotenv
3

API request करें

अपनी पसंदीदा भाषा के हिसाब से example.py या example.mts नाम की नई फ़ाइल बनाएं और इसमें यह कोड जोड़ें:

# example.py
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os
from dotenv import load_dotenv
load_dotenv()
elevenlabs = ElevenLabs(
api_key=os.getenv("ELEVENLABS_API_KEY"),
)
track = elevenlabs.music.compose(
prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
music_length_ms=10000,
model_id="music_v2_5",
)
# Save the track to a file
with open("path/to/music.mp3", "wb") as f:
for chunk in track:
f.write(chunk)

फिर इसे चलाएं:

python example.py

आपको जनरेट किया गया संगीत सुनाई देना चाहिए।

कंपोज़िशन प्लान

कंपोज़िशन प्लान एक JSON ऑब्जेक्ट है, जो उस संगीत का ज़्यादा बारीकी से वर्णन करता है जिसे आप जनरेट करना चाहते हैं। तेज़ प्रोटोटाइपिंग के लिए टेक्स्ट प्रॉम्प्ट इस्तेमाल करें और जब आपको खास chunk structure, lyrics की सटीक टाइमिंग या जटिल अरेंजमेंट चाहिए हों, तब कंपोज़िशन प्लान इस्तेमाल करें।

कंपोज़िशन प्लान जनरेट करना

API का इस्तेमाल करके प्रॉम्प्ट से कंपोज़िशन प्लान जनरेट किया जा सकता है।

from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os
from dotenv import load_dotenv
load_dotenv()
elevenlabs = ElevenLabs(
api_key=os.getenv("ELEVENLABS_API_KEY"),
)
composition_plan = elevenlabs.music.composition_plan.create(
prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
music_length_ms=10000,
model_id="music_v2_5",
)
print(composition_plan)

ऊपर दिया गया कोड नीचे दिए गए जैसा एक कंपोज़िशन प्लान जनरेट करेगा:

{
"chunks": [
{
"text": "[Intro]",
"durationMs": 3000,
"positiveStyles": [
"electronic",
"fast-paced",
"rising synth arpeggio",
"glitch fx",
"filtered noise sweep",
"soft punchy kick building tension",
"high adrenaline"
],
"negativeStyles": ["soft pads", "melodic vocals", "ambient textures"],
"contextAdherence": "high"
},
{
"text": "[Peak Drop]",
"durationMs": 4000,
"positiveStyles": [
"full punchy drums",
"distorted bass stab",
"aggressive rhythmic hits",
"rapid arpeggio sequences"
],
"negativeStyles": ["smooth transitions", "clean bass", "slow buildup"],
"contextAdherence": "high"
},
{
"text": "[Final Burst]",
"durationMs": 3000,
"positiveStyles": [
"glitch stutter",
"energy burst vox chopped sample",
"quick transitions",
"snare rolls"
],
"negativeStyles": ["long reverb tails", "fadeout", "gentle melodies"],
"contextAdherence": "high"
}
]
}

कंपोज़िशन प्लान इस्तेमाल करना

कंपोज़िशन प्लान को compose method में देकर संगीत जनरेट किया जा सकता है।

# You can pass in composition_plan or prompt, but not both.
composition = elevenlabs.music.compose(
composition_plan=composition_plan,
model_id="music_v2_5",
)
play(composition)

जानकारी के साथ संगीत जनरेट करना

हर संगीत जनरेशन के लिए प्रॉम्प्ट से एक कंपोज़िशन प्लान बनाया जाता है। detailed response endpoint का इस्तेमाल करके आप इस प्लान को पाने का विकल्प चुन सकते हैं।

track_details = elevenlabs.music.compose_detailed(
prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
music_length_ms=10000,
model_id="music_v2_5",
)
print(track_details.json) # json contains composition_plan and song_metadata. The composition plan will include lyrics (if applicable)
print(track_details.filename)
# track_details.audio contains the audio bytes

कॉपीराइट वाली सामग्री

कॉपीराइट वाली सामग्री शामिल करने वाला संगीत या कंपोज़िशन प्लान जनरेट करने की कोशिश करने पर error मिलेगा। इसमें किसी बैंड या संगीतकार का नाम लेना या कॉपीराइट वाले lyrics इस्तेमाल करना शामिल है।

कॉपीराइट वाली सामग्री वाले प्रॉम्प्ट

इन मामलों में API एक bad_prompt error लौटाएगा, जिसमें उस प्रॉम्प्ट का सुझाव होगा जिसे आप इसके बजाय इस्तेमाल कर सकते हैं।

try:
# This will result in a bad_prompt error
track = elevenlabs.music.compose(
prompt="A song that sounds like 'Bohemian Rhapsody'",
music_length_ms=10000,
model_id="music_v2_5",
)
except Exception as e:
if e.body['detail']['status'] == 'bad_prompt':
prompt_suggestion = e.body['detail']['data']['prompt_suggestion']
print(prompt_suggestion) # Prints: An epic rock ballad with dramatic tempo changes, operatic harmonies, and a narrative structure that blends melancholy with bursts of theatrical intensity.
# Use the prompt suggestion to generate the track instead

कॉपीराइट वाली सामग्री वाले कंपोज़िशन प्लान

कंपोज़िशन प्लान जनरेट करते समय अगर कॉपीराइट वाली सामग्री इस्तेमाल करने वाले styles शामिल हों, तो bad_composition_plan error लौटाया जाएगा। संगीत प्रॉम्प्ट की तरह ही, error में एक सुझाया गया कंपोज़िशन प्लान composition_plan_suggestion भी लौटाया जाएगा।

अगर कंपोज़िशन प्लान या प्रॉम्प्ट में हानिकारक सामग्री हो, तो कोई सुझाया गया प्रॉम्प्ट नहीं लौटाया जाएगा।

अगले चरण