> 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/whisperx.md).

# WhisperX with Diarization

WhisperX OpenAI के Whisper को तीन महत्वपूर्ण उन्नयन के साथ बढ़ाता है: **शब्द-स्तर टाइमस्टैम्प** जबरन फोनीम संरेखण के माध्यम से, **स्पीकर डायराइज़ेशन** pyannote.audio का उपयोग करते हुए, और **70× तक वास्तविक-समय गति** faster-whisper के साथ बैच्ड इनफेरेंस के माध्यम से। यह सटीक समय और स्पीकर पहचान की आवश्यकता वाले प्रोडक्शन ट्रांसक्रिप्शन पाइपलाइन के लिए जाने-माने टूल है।

**GitHub:** [m-bain/whisperX](https://github.com/m-bain/whisperX) **PyPI:** [whisperx](https://pypi.org/project/whisperx/) **लाइसेंस:** BSD-4-Clause **पेपर:** [arxiv.org/abs/2303.00747](https://arxiv.org/abs/2303.00747)

## प्रमुख विशेषताएँ

* **शब्द-स्तर टाइमस्टैम्प** — wav2vec2 जबरन संरेखण के माध्यम से ±50 ms सटीकता (vs वैनिला Whisper में ±500 ms)
* **स्पीकर डायराइज़ेशन** — pyannote.audio 3.1 के माध्यम से यह पहचानें कि किसने क्या कहा
* **बैच्ड इनफेरेंस** — RTX 4090 पर 70× तक वास्तविक-समय गति
* **VAD प्री-फ़िल्टरिंग** — Silero VAD ट्रांसक्रिप्शन से पहले मौन हटाता है
* **सभी Whisper मॉडल** — tiny से लेकर large-v3-turbo तक
* **कई आउटपुट फ़ॉर्मेट** — JSON, SRT, VTT, TXT, TSV
* **स्वचालित भाषा पहचान** — या तेज़ प्रोसेसिंग के लिए किसी विशिष्ट भाषा को बाध्य करें

## आवश्यकताएँ

| घटक    | न्यूनतम           | अनुशंसित                |
| ------ | ----------------- | ----------------------- |
| GPU    | RTX 3060 12 GB    | RTX 4090 24 GB          |
| VRAM   | 4 GB (small मॉडल) | 10 GB+ (large-v3-turbo) |
| RAM    | 8 GB              | 16 GB+                  |
| डिस्क  | 5 GB              | 20 GB (मॉडल कैश)        |
| Python | 3.9+              | 3.11                    |
| CUDA   | 11.8+             | 12.1+                   |

**HuggingFace टोकन आवश्यक** स्पीकर डायराइज़ेशन के लिए — लाइसेंस को स्वीकार करें [pyannote/speaker-diarization-3.1](https://huggingface.co/pyannote/speaker-diarization-3.1).

**Clore.ai सिफारिश:** RTX 3090 (~~$0.30–1.00/दिन) large-v3-turbo मॉडल के लिए बैच साइज 16 पर। RTX 4090 (~~$0.50–2.00/दिन) अधिकतम थ्रूपुट के लिए बैच साइज 32 पर।

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

```bash
# WhisperX इंस्टॉल करें
pip install whisperx

# GPU सत्यापित करें
python -c "import torch; print(torch.cuda.get_device_name(0))"
```

यदि आपको CUDA वर्शन संघर्ष मिलते हैं:

```bash
pip install torch==2.5.1+cu124 torchaudio==2.5.1+cu124 --index-url https://download.pytorch.org/whl/cu124
pip install whisperx
```

## त्वरित प्रारम्भ

```python
import whisperx
import json

device = "cuda"
compute_type = "float16"  # कम VRAM के लिए "int8"
batch_size = 16            # यदि VRAM कम हो तो 4-8 पर घटाएँ

# 1. मॉडल लोड करें
model = whisperx.load_model("large-v3-turbo", device, compute_type=compute_type)

# 2. ऑडियो लोड और ट्रांसक्राइब करें
audio = whisperx.load_audio("interview.mp3")
result = model.transcribe(audio, batch_size=batch_size)
print(f"Language: {result['language']}")

# 3. शब्द-स्तर टाइमस्टैम्प के लिए संरेखण करें
model_a, metadata = whisperx.load_align_model(
    language_code=result["language"], device=device
)
result = whisperx.align(
    result["segments"], model_a, metadata, audio, device,
    return_char_alignments=False,
)

# 4. परिणाम प्रिंट करें
for seg in result["segments"]:
    print(f"[{seg['start']:.2f}s → {seg['end']:.2f}s] {seg['text']}")
    for w in seg.get("words", []):
        print(f"  '{w['word']}' @ {w.get('start', 0):.2f}s")

# 5. सहेजें
with open("transcript.json", "w") as f:
    json.dump(result, f, indent=2, ensure_ascii=False)
```

## उपयोग के उदाहरण

### स्पीकर डायराइज़ेशन के साथ ट्रांसक्रिप्शन

```python
import whisperx
import gc
import torch

device = "cuda"
HF_TOKEN = "hf_your_token_here"  # huggingface.co/settings/tokens से

# स्टेप 1: ट्रांसक्राइब करें
model = whisperx.load_model("large-v3-turbo", device, compute_type="float16")
audio = whisperx.load_audio("meeting.mp3")
result = model.transcribe(audio, batch_size=16)

# एलाइनमेंट मॉडल लोड करने से पहले GPU मेमोरी खाली करें
del model; gc.collect(); torch.cuda.empty_cache()

# स्टेप 2: संरेखण
model_a, metadata = whisperx.load_align_model(
    language_code=result["language"], device=device
)
result = whisperx.align(result["segments"], model_a, metadata, audio, device)
del model_a; gc.collect(); torch.cuda.empty_cache()

# स्टेप 3: डायराइज़
diarize_model = whisperx.DiarizationPipeline(
    use_auth_token=HF_TOKEN, device=device
)
diarize_segments = diarize_model(audio, min_speakers=2, max_speakers=6)

# स्टेप 4: शब्दों को स्पीकर्स असाइन करें
result = whisperx.assign_word_speakers(diarize_segments, result)

for seg in result["segments"]:
    speaker = seg.get("speaker", "UNKNOWN")
    print(f"[{speaker}] [{seg['start']:.1f}s → {seg['end']:.1f}s] {seg['text']}")
```

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

```bash
# बुनियादी ट्रांसक्रिप्शन
whisperx audio.mp3 --model large-v3-turbo --device cuda

# भाषा मजबूर करें (तेज़, पहचान छोड़ता है)
whisperx audio.mp3 --model large-v3-turbo --language en --device cuda

# स्पीकर डायराइज़ेशन के साथ
whisperx audio.mp3 --model large-v3-turbo --diarize --hf_token hf_your_token

# SRT सबटाइटल आउटपुट
whisperx audio.mp3 --model large-v3-turbo --output_format srt --output_dir ./subs/

# कम-VRAM मोड
whisperx audio.mp3 --model medium --compute_type int8 --batch_size 4 --device cuda

# किसी डायरेक्टरी को बैच प्रोसेस करें
for f in /data/audio/*.mp3; do
  whisperx "$f" --model large-v3-turbo --output_dir /data/transcripts/
done
```

### SRT जेनरेशन स्क्रिप्ट

```python
import whisperx

def transcribe_to_srt(audio_path, output_path, model_name="large-v3-turbo"):
    device = "cuda"
    model = whisperx.load_model(model_name, device, compute_type="float16")
    audio = whisperx.load_audio(audio_path)
    result = model.transcribe(audio, batch_size=16)

    model_a, metadata = whisperx.load_align_model(
        language_code=result["language"], device=device
    )
    result = whisperx.align(result["segments"], model_a, metadata, audio, device)

    with open(output_path, "w") as f:
        for i, seg in enumerate(result["segments"], 1):
            start = format_ts(seg["start"])
            end = format_ts(seg["end"])
            f.write(f"{i}\n{start} --> {end}\n{seg['text'].strip()}\n\n")

    print(f"SRT saved to {output_path}")

def format_ts(seconds):
    h = int(seconds // 3600)
    m = int((seconds % 3600) // 60)
    s = int(seconds % 60)
    ms = int((seconds % 1) * 1000)
    return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}"

transcribe_to_srt("podcast.mp3", "podcast.srt")
```

## प्रदर्शन बेंचमार्क

| विधि           | मॉडल               | 1h ऑडियो       | GPU          | अनुमानित गति |
| -------------- | ------------------ | -------------- | ------------ | ------------ |
| वैनिला Whisper | large-v3           | \~60 मिनट      | RTX 3090     | 1×           |
| faster-whisper | large-v3           | \~5 मिनट       | RTX 3090     | \~12×        |
| **WhisperX**   | **large-v3-turbo** | **\~1 मिनट**   | **RTX 3090** | **\~60×**    |
| **WhisperX**   | **large-v3-turbo** | **\~50 सैकंड** | **RTX 4090** | **\~70×**    |

| बैच साइज | गति (RTX 4090)     | VRAM  |
| -------- | ------------------ | ----- |
| 4        | \~30× वास्तविक-समय | 6 GB  |
| 8        | \~45× वास्तविक-समय | 8 GB  |
| 16       | \~60× वास्तविक-समय | 10 GB |
| 32       | \~70× वास्तविक-समय | 14 GB |

## Clore.ai उपयोगकर्ताओं के लिए सुझाव

* **चरणों के बीच मुक्त VRAM** — मॉडलों को हटाएँ और कॉल करें `torch.cuda.empty_cache()` ट्रांसक्रिप्शन, संरेखण, और डायराइज़ेशन के बीच
* **HuggingFace टोकन** — डायराइज़ेशन काम करने से पहले आपको pyannote मॉडल लाइसेंस स्वीकार करना होगा; सेट करें `HF_TOKEN` एक पर्यावरण चर के रूप में
* **बैच साइज ट्यूनिंग** — शुरू करें `batch_size=16`, 12 GB कार्ड पर 4–8 तक घटाएँ, 24 GB कार्ड पर 32 तक बढ़ाएँ
* **`int8` compute** — उपयोग करें `compute_type="int8"` न्यूनतम गुणवत्ता हानि के साथ VRAM उपयोग आधा करने के लिए
* **Docker इमेज** — `pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime`
* **स्थायी मॉडल कैश** — माउंट करें `/root/.cache/huggingface` ताकि प्रत्येक कंटेनर रीस्टार्ट पर मॉडल फिर से डाउनलोड न हों

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

| समस्या                          | समाधान                                                                                                                |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `CUDA में आउट ऑफ मेमोरी`        | घटाएँ `batch_size`, उपयोग करें `compute_type="int8"`, या छोटा मॉडल उपयोग करें (medium, small)                         |
| डायराइज़ेशन लौटाता है `UNKNOWN` | सुनिश्चित करें कि HuggingFace टोकन मान्य है और आपने pyannote लाइसेंस स्वीकार कर ली है                                 |
| `No module named 'whisperx'`    | `pip install whisperx` — सुनिश्चित करें कि कोई टाइपो नहीं है (यह है `whisperx`, नहीं `whisper-x`)                     |
| खराब शब्द टाइमस्टैम्प           | जाँच करें कि `whisperx.align()` को कॉल किया गया है के बाद `transcribe()` — कच्चा Whisper आउटपुट शब्द सटीकता नहीं देता |
| भाषा पहचान गलत                  | भाषा को मजबूर करें `--language en` या `language="en"` Python API में                                                  |
| धीमा प्रोसेसिंग                 | बढ़ाएँ `batch_size`, उपयोग करें `large-v3-turbo` की बजाय `large-v3`, सुनिश्चित करें कि GPU साझा नहीं किया जा रहा है   |


---

# 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/whisperx.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.
