> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-hi/audio-and-voice/demucs-separation.md).

# Demucs Separation

Demucs के साथ संगीत को स्टेम्स (वोकल्स, ड्रम्स, बेस, अन्य) में अलग करें।

{% hint style="success" %}
सभी उदाहरण GPU सर्वरों पर चलाए जा सकते हैं जिन्हें द्वारा किराए पर लिया गया है [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace).
{% endhint %}

## CLORE.AI पर किराये पर लेना

1. पर जाएँ [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace)
2. GPU प्रकार, VRAM, और मूल्य के अनुसार फ़िल्टर करें
3. चुनें **ऑन-डिमांड** (निश्चित दर) या **स्पॉट** (बिड प्राइस)
4. अपना ऑर्डर कॉन्फ़िगर करें:
   * Docker इमेज चुनें
   * पोर्ट सेट करें (SSH के लिए TCP, वेब UI के लिए HTTP)
   * यदि आवश्यक हो तो एनवायरनमेंट वेरिएबल जोड़ें
   * स्टार्टअप कमांड दर्ज करें
5. भुगतान चुनें: **CLORE**, **BTC**, या **USDT/USDC**
6. ऑर्डर बनाएं और डिप्लॉयमेंट का इंतज़ार करें

### अपने सर्वर तक पहुँचें

* कनेक्शन विवरण में खोजें **मेरे ऑर्डर**
* वेब इंटरफेस: HTTP पोर्ट URL का उपयोग करें
* SSH: `ssh -p <port> root@<proxy-address>`

## Demucs क्या है?

Meta AI का Demucs कर सकता है:

* संगीत से वोकल्स अलग करना
* ड्रम्स, बेस और अन्य उपकरण निकालना
* किसी भी ऑडियो फ़ॉर्मेट को प्रोसेस करना
* उच्च-गुणवत्ता स्टेम एक्सट्रैक्शन

## त्वरित तैनाती

**Docker इमेज:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
```

**पोर्ट:**

```
22/tcp
7860/http
```

**कमांड:**

```bash
pip install demucs gradio && \
python -c "
import gradio as gr
from demucs.pretrained import get_model
from demucs.apply import apply_model
import torch
import torchaudio
import tempfile
import os

model = get_model('htdemucs')
model.cuda()

def separate(audio_path, stem):
    wav, sr = torchaudio.load(audio_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    stems = {'drums': 0, 'bass': 1, 'other': 2, 'vocals': 3}
    output = sources[stems[stem]].cpu()

    with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
        torchaudio.save(f.name, output, sr)
        return f.name

demo = gr.Interface(
    fn=separate,
    inputs=[gr.Audio(type='filepath'), gr.Dropdown(['vocals', 'drums', 'bass', 'other'])],
    outputs=gr.Audio(),
    title='Demucs Audio Separator'
)
demo.launch(server_name='0.0.0.0', server_port=7860)
"
```

## अपनी सेवा तक पहुँचना

डिप्लॉयमेंट के बाद, अपना खोजें `http_pub` URL में **मेरे ऑर्डर**:

1. जाएँ **मेरे ऑर्डर** पृष्ठ
2. अपने ऑर्डर पर क्लिक करें
3. खोजें `http_pub` URL (उदा., `abc123.clorecloud.net`)

उपयोग करें `https://YOUR_HTTP_PUB_URL` की बजाय `localhost` नीचे दिए उदाहरणों में।

## इंस्टॉलेशन

```bash
pip install demucs

# या
pip install -e git+https://github.com/facebookresearch/demucs#egg=demucs
```

## कमांड लाइन उपयोग

### बेसिक सेपरेशन

```bash

# 4 स्टेम्स में अलग करें
demucs song.mp3

# आउटपुट: separated/htdemucs/song/{drums,bass,other,vocals}.wav
```

### विकल्प

```bash
demucs \
    --two-stems vocals \     # केवल वोकल्स + इंस्ट्रुमेंटल
    -n htdemucs \            # मॉडल का नाम
    -d cuda \                # GPU का उपयोग करें
    -o ./output \            # आउटपुट डायरेक्टरी
    --mp3 \                  # MP3 के रूप में आउटपुट
    song.mp3
```

### फ़ोल्डर प्रोसेस करें

```bash
demucs --two-stems vocals -d cuda ./songs/*.mp3
```

## Python API

### बेसिक सेपरेशन

```python
from demucs.pretrained import get_model
from demucs.apply import apply_model
import torchaudio
import torch

# मॉडल लोड करें
model = get_model('htdemucs')
model.cuda()
model.eval()

# ऑडियो लोड करें
wav, sr = torchaudio.load("song.mp3")
wav = wav.cuda()

# अलग करें
with torch.no_grad():
    sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

# sources का आकार: [4, channels, samples]

# 0: drums, 1: bass, 2: other, 3: vocals

# स्टेम्स सेव करें
stems = ['drums', 'bass', 'other', 'vocals']
for i, stem in enumerate(stems):
    torchaudio.save(f"{stem}.wav", sources[i].cpu(), sr)
```

### केवल वोकल्स प्राप्त करें

```python
def extract_vocals(audio_path):
    wav, sr = torchaudio.load(audio_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    vocals = sources[3].cpu()  # इंडेक्स 3 = वोकल्स
    return vocals, sr

vocals, sr = extract_vocals("song.mp3")
torchaudio.save("vocals.wav", vocals, sr)
```

### इंस्ट्रुमेंटल प्राप्त करें (बिना वोकल्स)

```python
def extract_instrumental(audio_path):
    wav, sr = torchaudio.load(audio_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    # ड्रम्स + बेस + अन्य को जोड़ें
    instrumental = sources[0] + sources[1] + sources[2]
    return instrumental.cpu(), sr

instrumental, sr = extract_instrumental("song.mp3")
torchaudio.save("instrumental.wav", instrumental, sr)
```

## मॉडल वेरिएंट

| मॉडल         | स्टेम्स | गुणवत्ता   | स्पीड |
| ------------ | ------- | ---------- | ----- |
| htdemucs     | 4       | सर्वोत्तम  | मध्यम |
| htdemucs\_ft | 4       | Best+      | धीमा  |
| htdemucs\_6s | 6       | बहुत अच्छा | मध्यम |
| mdx\_extra   | 4       | बहुत अच्छा | तेज़  |

### 6-स्टेम मॉडल

```python
model = get_model('htdemucs_6s')

# स्टेम्स: drums, bass, other, vocals, guitar, piano
```

### फाइन-ट्यून किया गया मॉडल

```python
model = get_model('htdemucs_ft')

# अधिक उच्च गुणवत्ता परन्तु धीमा
```

## बैच प्रोसेसिंग

```python
import os
from demucs.pretrained import get_model
from demucs.apply import apply_model
import torchaudio
import torch

model = get_model('htdemucs')
model.cuda()
model.eval()

input_dir = "./songs"
output_dir = "./separated"

for filename in os.listdir(input_dir):
    if filename.endswith(('.mp3', '.wav', '.flac')):
        input_path = os.path.join(input_dir, filename)
        song_output_dir = os.path.join(output_dir, filename.rsplit('.', 1)[0])
        os.makedirs(song_output_dir, exist_ok=True)

        print(f"Processing: {filename}")

        wav, sr = torchaudio.load(input_path)
        wav = wav.cuda()

        with torch.no_grad():
            sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

        stems = ['drums', 'bass', 'other', 'vocals']
        for i, stem in enumerate(stems):
            torchaudio.save(
                os.path.join(song_output_dir, f"{stem}.wav"),
                sources[i].cpu(),
                sr
            )

        print(f"Saved: {song_output_dir}")
```

## API सर्वर

```python
from fastapi import FastAPI, UploadFile
from fastapi.responses import FileResponse
from demucs.pretrained import get_model
from demucs.apply import apply_model
import torchaudio
import torch
import tempfile
import os

app = FastAPI()

model = get_model('htdemucs')
model.cuda()
model.eval()

@app.post("/separate")
async def separate(file: UploadFile, stem: str = "vocals"):
    # अपलोड की गई फ़ाइल सेव करें
    with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
        content = await file.read()
        tmp.write(content)
        tmp_path = tmp.name

    # लोड और अलग करें
    wav, sr = torchaudio.load(tmp_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    stems = {'drums': 0, 'bass': 1, 'other': 2, 'vocals': 3}
    output = sources[stems[stem]].cpu()

    # आउटपुट सेव करें
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as out:
        torchaudio.save(out.name, output, sr)
        return FileResponse(out.name, media_type="audio/wav")

@app.post("/instrumental")
async def get_instrumental(file: UploadFile):
    with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
        content = await file.read()
        tmp.write(content)
        tmp_path = tmp.name

    wav, sr = torchaudio.load(tmp_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    # गैर-वोकल स्टेम्स को संयोजित करें
    instrumental = sources[0] + sources[1] + sources[2]

    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as out:
        torchaudio.save(out.name, instrumental.cpu(), sr)
        return FileResponse(out.name, media_type="audio/wav")

# चलाएँ: uvicorn server:app --host 0.0.0.0 --port 8000
```

## मेमोरी अनुकूलन

### लंबे ऑडियो के लिए

```python
from demucs.apply import apply_model

# लंबे ऑडियो के लिए स्प्लिटिंग का उपयोग करें
sources = apply_model(
    model,
    wav.unsqueeze(0),
    split=True,         # चंक्स में विभाजित करें
    overlap=0.25,       # चंक्स के बीच ओवरलैप
    progress=True
)[0]
```

### सीमित VRAM के लिए

```python

# कुछ ऑपरेशनों के लिए CPU का उपयोग करें
model.cpu()
wav = wav.cpu()

# या सेगमेंट प्रोसेसिंग का उपयोग करें
sources = apply_model(
    model,
    wav.unsqueeze(0),
    split=True,
    segment=10  # 10 सेकंड सेगमेंट
)[0]
```

## उपयोग के मामले

### कराओके ट्रैक

```python
def create_karaoke(song_path):
    wav, sr = torchaudio.load(song_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    # वोकल्स को छोड़कर सब कुछ
    karaoke = sources[0] + sources[1] + sources[2]
    return karaoke.cpu(), sr
```

### रीमिक्स तैयारी

```python
def extract_all_stems(song_path, output_dir):
    wav, sr = torchaudio.load(song_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    stems = ['drums', 'bass', 'other', 'vocals']
    paths = {}

    for i, stem in enumerate(stems):
        path = os.path.join(output_dir, f"{stem}.wav")
        torchaudio.save(path, sources[i].cpu(), sr)
        paths[stem] = path

    return paths
```

### अकापेला निकालना

```python
def extract_acapella(song_path):
    wav, sr = torchaudio.load(song_path)
    wav = wav.cuda()

    with torch.no_grad():
        sources = apply_model(model, wav.unsqueeze(0), split=True)[0]

    vocals = sources[3]
    return vocals.cpu(), sr
```

## गुणवत्ता सुझाव

### सर्वश्रेष्ठ परिणामों के लिए

* लॉसलेस इनपुट का उपयोग करें (WAV, FLAC)
* ऊंचा सैंपल रेट = बेहतर गुणवत्ता
* उपयोग करें `htdemucs_ft` महत्वपूर्ण कार्य के लिए

### पोस्ट-प्रोसेसिंग

```python
from pydub import AudioSegment
from pydub.effects import normalize, high_pass_filter

# अलग किया गया वोकल लोड करें
vocals = AudioSegment.from_wav("vocals.wav")

# कम रम्बल हटाएं
vocals = high_pass_filter(vocals, 80)

# सामान्यीकरण
vocals = normalize(vocals)

vocals.export("vocals_clean.wav", format="wav")
```

## प्रदर्शन

| ऑडियो की लंबाई | GPU      | समय      |
| -------------- | -------- | -------- |
| 3 मिनट का गाना | RTX 3090 | \~15s    |
| 3 मिनट का गाना | RTX 4090 | \~10s    |
| 3 मिनट का गाना | A100     | \~8s     |
| 1 घंटा एलबम    | RTX 3090 | \~5 मिनट |

## समस्याओं का निवारण

### आउट ऑफ़ मेमोरी

```bash

# छोटे सेगमेंट्स का उपयोग करें
demucs --segment 10 song.mp3
```

### खराब सेपरेशन

* htdemucs\_ft मॉडल का उपयोग करें
* इनपुट गुणवत्ता जांचें
* भारी रूप से कंप्रेस्ड MP3 से बचें

### आर्टिफैक्ट्स

* ओवरलैप बढ़ाएं
* उच्च गुणवत्ता वाला मॉडल इस्तेमाल करें
* इनपुट में क्लिपिंग की जाँच करें

## लागत अनुमान

सामान्य CLORE.AI मार्केटप्लेस दरें (2024 के अनुसार):

| GPU       | घंटात्मक दर | दैनिक दर | 4-घंटे सत्र |
| --------- | ----------- | -------- | ----------- |
| RTX 3060  | \~$0.03     | \~$0.70  | \~$0.12     |
| RTX 3090  | \~$0.06     | \~$1.50  | \~$0.25     |
| RTX 4090  | \~$0.10     | \~$2.30  | \~$0.40     |
| A100 40GB | \~$0.17     | \~$4.00  | \~$0.70     |
| A100 80GB | \~$0.25     | \~$6.00  | \~$1.00     |

*कीमतें प्रदाता और मांग के अनुसार बदलती हैं। जाँच करें* [*CLORE.AI मार्केटप्लेस*](https://clore.ai/marketplace) *वर्तमान दरों के लिए।*

**पैसे बचाएँ:**

* उपयोग करें **स्पॉट** लचीले वर्कलोड के लिए मार्केट (अक्सर 30-50% सस्ता)
* भुगतान करें **CLORE** टोकन के साथ
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले कदम

* [RVC वॉयस क्लोन](/guides/guides_v2-hi/audio-and-voice/rvc-voice-clone.md) - निर्यात किए गए वोकल्स को प्रोसेस करें
* [AudioCraft म्यूजिक](/guides/guides_v2-hi/audio-and-voice/audiocraft-music.md) - नया संगीत जेनरेट करें
* [Whisper ट्रांसक्रिप्शन](/guides/guides_v2-hi/audio-and-voice/whisper-transcription.md) - वोकल्स का ट्रांसक्राइब करें


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-hi/audio-and-voice/demucs-separation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
