> 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 के साथ डायरीकरण

Clore.ai GPUs पर शब्द-स्तरीय टाइमस्टैम्प और स्पीकर डायरीकरण के साथ तेज़ भाषण ट्रांसक्रिप्शन के लिए WhisperX चलाएँ।

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 **Paper:** [arxiv.org/abs/2303.00747](https://arxiv.org/abs/2303.00747)

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

* **शब्द-स्तरीय टाइमस्टैम्प** — wav2vec2 जबरन संरेखण के माध्यम से ±50 ms सटीकता (जबकि सामान्य 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 (छोटा मॉडल) | 10 GB+ (large-v3-turbo) |
| RAM    | 8 GB             | 16 GB+                  |
| डिस्क  | 5 GB             | 20 GB (मॉडल कैश)        |
| Python | 3.9+             | 3.11                    |
| CUDA   | 12.8+            | 12.8+                   |

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

**Clore.ai की सिफारिश:** RTX 3090 ($0.07–0.21/hr) large-v3-turbo मॉडल के लिए batch size 16 पर। RTX 4090 ($0.14–0.42/hr) batch size 32 पर अधिकतम throughput के लिए।

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

```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/cu128
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"भाषा: {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 {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")
```

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

| विधि           | मॉडल               | 1 घंटे का ऑडियो | GPU          | लगभग गति  |
| -------------- | ------------------ | --------------- | ------------ | --------- |
| साधारण Whisper | large-v3           | \~60 min        | RTX 3090     | 1×        |
| faster-whisper | large-v3           | \~5 मिनट        | RTX 3090     | \~12×     |
| **WhisperX**   | **large-v3-turbo** | **\~1 min**     | **RTX 3090** | **\~60×** |
| **WhisperX**   | **large-v3-turbo** | **\~50 sec**    | **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` इसे एक environment variable के रूप में
* **बैच आकार समायोजन** — शुरुआत करें `batch_size=16`, 12 GB कार्ड पर 4–8 तक घटाएँ, 24 GB कार्ड पर 32 तक बढ़ाएँ
* **`int8` कंप्यूट** — उपयोग करें `compute_type="int8"` VRAM उपयोग को लगभग आधा करने के लिए, न्यूनतम गुणवत्ता हानि के साथ
* **Docker इमेज** — `pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime`
* **स्थायी मॉडल कैश** — माउंट करें `/root/.cache/huggingface` ताकि हर कंटेनर रीस्टार्ट पर मॉडल दोबारा डाउनलोड न करने पड़ें

## समस्या निवारण

| समस्या                          | समाधान                                                                                                                            |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `CUDA out of memory`            | कम करें `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.
