> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

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

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

> **Tip**
>
> अपने AI कोडिंग असिस्टेंट से संगीत ट्रैक जनरेट करने के लिए [ElevenLabs music skill](https://github.com/elevenlabs/skills/tree/main/music) का इस्तेमाल करें:
>
> ```bash
> npx skills add elevenlabs/skills --skill music
> ```

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

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

#### API key बनाएं

[यहां डैशबोर्ड में API की बनाएं](https://elevenlabs.io/app/settings/api-keys), जिसका उपयोग आप सुरक्षित रूप से [API एक्सेस करने](/docs/hi/api-reference/authentication) के लिए करेंगे।

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

**`.env`**

```js title=".env"
ELEVENLABS_API_KEY=<your_api_key_here>
```

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

#### SDK

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

```python
pip install elevenlabs
pip install python-dotenv
```

```typescript
npm install @elevenlabs/elevenlabs-js
npm install dotenv
```

#### CLI

ElevenLabs CLI इंस्टॉल करें। Homebrew (macOS) और Scoop (Windows) की सलाह दी जाती है।

**`Homebrew (macOS)`**

```bash title="Homebrew (macOS)"
brew install elevenlabs/tap/elevenlabs
```

**`Scoop (Windows)`**

```powershell title="Scoop (Windows)"
scoop bucket add elevenlabs https://github.com/elevenlabs/scoop-bucket
scoop install elevenlabs
```

**`npm`**

```bash title="npm"
npm install -g @elevenlabs/cli
```

**`curl`**

```bash title="curl"
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/elevenlabs/cli/releases/latest/download/elevenlabs-cli-installer.sh | sh
```

> **Tip**
>
> AI कोडिंग असिस्टेंट के साथ काम कर रहे हैं? अपने प्रोजेक्ट में `elevenlabs generate-skills` चलाएं। इससे हर कमांड ग्रुप के लिए `skills/` में एक
> `SKILL.md` लिखा जाएगा, ताकि आपके असिस्टेंट को डॉक्यूमेंटेशन पेस्ट किए बिना CLI की पूरी जानकारी मिल सके। उन्हें कहीं और रखने के लिए `--output-dir` इस्तेमाल करें। यह CLI की अपनी
> एम्बेडेड API डेफ़िनिशन पढ़ता है, इसलिए इसे API key की ज़रूरत नहीं होती और यह ऑफ़लाइन भी काम करता है — साथ ही आपके इंस्टॉल किए गए CLI वर्शन के अनुसार बना रहता है।

फिर authenticate करें — CLI को authorize करने के लिए इससे आपका browser खुलेगा:

```bash
elevenlabs auth login
```

#### API request करें

#### SDK

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

```python
# 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)
```

```typescript
// example.mts
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { Readable } from "stream";
import { createWriteStream } from "fs";
import { pipeline } from "stream/promises";
import "dotenv/config";

const elevenlabs = new ElevenLabsClient();

const track = await 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.",
  musicLengthMs: 10000,
  modelId: "music_v2_5",
});

// Save the track to a file
await pipeline(Readable.from(track), createWriteStream("path/to/music.mp3"));
```

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

```python
python example.py
```

```typescript
npx tsx example.mts
```

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

#### CLI

एक ट्रैक जनरेट करें और उसे फ़ाइल में सेव करें:

```bash
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 \
  --output music.mp3
```

नतीजा सुनने के लिए `music.mp3` खोलें।

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

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

#### [कंपोज़िशन प्लान गाइड](/docs/hi/eleven-api/guides/how-to/music/composition-plans)

सटीक नियंत्रण के लिए chunks, styles और lyrics के साथ गानों को स्ट्रक्चर करना सीखें।

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

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

```python
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)
```

```typescript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import "dotenv/config";

const elevenlabs = new ElevenLabsClient();

const compositionPlan = await elevenlabs.music.compositionPlan.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.",
  musicLengthMs: 10000,
  modelId: "music_v2_5",
});

console.log(JSON.stringify(compositionPlan, null, 2));
```

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

```json
{
  "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 में देकर संगीत जनरेट किया जा सकता है।

```python
# 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)
```

```typescript
// You can pass in compositionPlan or prompt, but not both.
const composition = await elevenlabs.music.compose({
    compositionPlan,
    modelId: "music_v2_5",
});

await play(composition);
```

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

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

```python
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
```

```typescript
const trackDetails = await elevenlabs.music.composeDetailed({
  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, 30–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.',
  musicLengthMs: 10000,
  modelId: "music_v2_5",
});

console.log(JSON.stringify(trackDetails.json, null, 2)); // json contains composition_plan and song_metadata. The composition plan will include lyrics (if applicable)
console.log(trackDetails.filename);
// trackDetails.audio contains the audio bytes
```

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

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

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

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

```python
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
```

```typescript
try {
  // This will result in a bad_prompt error
  const track = await elevenlabs.music.compose({
    prompt: "A song that sounds like 'Bohemian Rhapsody'",
    musicLengthMs: 10000,
    modelId: "music_v2_5",
  });
} catch (error) {
  if (error.body.detail.status === 'bad_prompt') {
    const promptSuggestion = error.body.detail.data.prompt_suggestion;
    console.log(promptSuggestion); // Logs: 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` भी लौटाया जाएगा।

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

## अगले चरण

#### [संगीत स्ट्रीम करें](/docs/hi/eleven-api/guides/how-to/music/streaming)

पूरी फ़ाइल का इंतज़ार करने के बजाय जनरेट किया गया संगीत रीयल टाइम में स्ट्रीम करें

#### [म्यूज़िक इनपेंटिंग](/docs/hi/eleven-api/guides/how-to/music/inpainting)

मौजूदा संगीत ट्रैक के खास हिस्सों को बदलें या बढ़ाएं

#### [API रेफरेंस](/docs/hi/api-reference/music/compose)

Music API के सभी parameters और response formats देखें