म्यूज़िक स्ट्रीमिंग

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

कैसे करें गाइड · यह मानकर चलता है कि आपने Music quickstart पूरा कर लिया है।

Music API सिर्फ़ पेड यूज़र्स के लिए उपलब्ध है।

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

यह गाइड मानकर चलती है कि आपने अपनी API key और SDK सेट अप कर ली है। अगर नहीं की है, तो पहले quickstart पूरा करें।

1

API request करें

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

# example.py
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os
from io import BytesIO
from dotenv import load_dotenv
load_dotenv()
elevenlabs = ElevenLabs(
api_key=os.getenv("ELEVENLABS_API_KEY"),
)
stream = elevenlabs.music.stream(
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",
)
# Create a BytesIO object to hold the audio data in memory
audio_stream = BytesIO()
# Write each chunk of audio data to the stream
for chunk in stream:
if chunk:
audio_stream.write(chunk)
# Reset stream position to the beginning
audio_stream.seek(0)
play(audio_stream)
2

कोड चलाएं

python example.py

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

अगले चरण