> 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-de/audio-and-stimme/whisperx.md).

# WhisperX mit Sprecherdiarisierung

Führe WhisperX für schnelle Sprachtranskription mit Wort-Zeitstempeln und Sprecherdiarisierung auf Clore.ai-GPUs aus.

WhisperX erweitert OpenAIs Whisper um drei entscheidende Verbesserungen: **Zeitstempel auf Wortebene** durch erzwungene Phonem-Ausrichtung, **Sprecherdiarisierung** mit pyannote.audio, und **bis zu 70× Echtzeitgeschwindigkeit** durch Batch-Inferenz mit faster-whisper. Es ist das Standardwerkzeug für Produktions-Transkriptions-Pipelines, die präzise Zeitangaben und Sprecheridentifikation benötigen.

**GitHub:** [m-bain/whisperX](https://github.com/m-bain/whisperX) **PyPI:** [whisperx](https://pypi.org/project/whisperx/) **Lizenz:** BSD-4-Clause **Paper:** [arxiv.org/abs/2303.00747](https://arxiv.org/abs/2303.00747)

## Hauptfunktionen

* **Zeitstempel auf Wortebene** — ±50 ms Genauigkeit durch erzwungene wav2vec2-Ausrichtung (vs. ±500 ms in Vanilla Whisper)
* **Sprecherdiarisierung** — erkenne, wer was gesagt hat, mittels pyannote.audio 3.1
* **Batch-Inferenz** — bis zu 70× Echtzeitgeschwindigkeit auf einer RTX 4090
* **VAD-Vorfilterung** — Silero VAD entfernt Stille vor der Transkription
* **Alle Whisper-Modelle** — tiny bis large-v3-turbo
* **Mehrere Ausgabeformate** — JSON, SRT, VTT, TXT, TSV
* **Automatische Spracherkennung** — oder erzwinge eine bestimmte Sprache für eine schnellere Verarbeitung

## Anforderungen

| Komponente | Minimum               | Empfohlen               |
| ---------- | --------------------- | ----------------------- |
| GPU        | RTX 3060 12 GB        | RTX 4090 24 GB          |
| VRAM       | 4 GB (kleines Modell) | 10 GB+ (large-v3-turbo) |
| RAM        | 8 GB                  | 16 GB+                  |
| Festplatte | 5 GB                  | 20 GB (Modell-Cache)    |
| Python     | 3.9+                  | 3.11                    |
| CUDA       | 12.8+                 | 12.8+                   |

**HuggingFace-Token erforderlich** für die Sprecherdiarisierung — akzeptiere die Lizenz auf [pyannote/speaker-diarization-3.1](https://huggingface.co/pyannote/speaker-diarization-3.1).

**Clore.ai-Empfehlung:** RTX 3090 ($0.07–0.21/hr) für das large-v3-turbo-Modell mit Batch-Größe 16. RTX 4090 ($0.14–0.42/hr) für maximalen Durchsatz bei Batch-Größe 32.

## Installation

```bash
# WhisperX installieren
pip install whisperx

# GPU überprüfen
python -c "import torch; print(torch.cuda.get_device_name(0))"
```

Falls CUDA-Versionskonflikte auftreten:

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

## Schnellstart

```python
import whisperx
import json

device = "cuda"
compute_type = "float16"  # "int8" für weniger VRAM
batch_size = 16            # auf 4–8 reduzieren, wenn der VRAM knapp ist

# 1. Modell laden
model = whisperx.load_model("large-v3-turbo", device, compute_type=compute_type)

# 2. Audio laden und transkribieren
audio = whisperx.load_audio("interview.mp3")
result = model.transcribe(audio, batch_size=batch_size)
print(f"Sprache: {result['language']}")

# 3. Für Zeitstempel auf Wortebene ausrichten
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. Ergebnisse ausgeben
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. Speichern
with open("transcript.json", "w") as f:
    json.dump(result, f, indent=2, ensure_ascii=False)
```

## Anwendungsbeispiele

### Transkription mit Sprecherdiarisierung

```python
import whisperx
import gc
import torch

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

# Schritt 1: Transkribieren
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-Speicher vor dem Laden des Ausrichtungsmodells freigeben
del model; gc.collect(); torch.cuda.empty_cache()

# Schritt 2: Ausrichten
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()

# Schritt 3: Diarisieren
diarize_model = whisperx.DiarizationPipeline(
    use_auth_token=HF_TOKEN, device=device
)
diarize_segments = diarize_model(audio, min_speakers=2, max_speakers=6)

# Schritt 4: Sprecher den Wörtern zuweisen
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']}")
```

### Verwendung über die Kommandozeile

```bash
# Einfache Transkription
whisperx audio.mp3 --model large-v3-turbo --device cuda

# Sprache erzwingen (schneller, überspringt Erkennung)
whisperx audio.mp3 --model large-v3-turbo --language en --device cuda

# Mit Sprecherdiarisierung
whisperx audio.mp3 --model large-v3-turbo --diarize --hf_token hf_your_token

# SRT-Untertitelausgabe
whisperx audio.mp3 --model large-v3-turbo --output_format srt --output_dir ./subs/

# Modus für wenig VRAM
whisperx audio.mp3 --model medium --compute_type int8 --batch_size 4 --device cuda

# Ein Verzeichnis im Batch verarbeiten
for f in /data/audio/*.mp3; do
  whisperx "$f" --model large-v3-turbo --output_dir /data/transcripts/
done
```

### SRT-Generierungsskript

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

    SRT gespeichert unter {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")
```

## Leistungsbenchmarks

| Methode          | Modell             | 1 Stunde Audio | GPU          | Ungefähre Geschwindigkeit |
| ---------------- | ------------------ | -------------- | ------------ | ------------------------- |
| Standard-Whisper | large-v3           | \~60 Min.      | RTX 3090     | 1×                        |
| faster-whisper   | large-v3           | \~5 min        | RTX 3090     | \~12×                     |
| **WhisperX**     | **large-v3-turbo** | **\~1 Min.**   | **RTX 3090** | **\~60×**                 |
| **WhisperX**     | **large-v3-turbo** | **\~50 Sek.**  | **RTX 4090** | **\~70×**                 |

| Batch-Größe | Geschwindigkeit (RTX 4090) | VRAM  |
| ----------- | -------------------------- | ----- |
| 4           | \~30× Echtzeit             | 6 GB  |
| 8           | \~45× Echtzeit             | 8 GB  |
| 16          | \~60× Echtzeit             | 10 GB |
| 32          | \~70× Echtzeit             | 14 GB |

## Tipps für Clore.ai-Nutzer

* **VRAM zwischen den Schritten freigeben** — Modelle löschen und aufrufen `torch.cuda.empty_cache()` zwischen Transkription, Ausrichtung und Diarisierung
* **HuggingFace-Token** — du musst die pyannote-Modelllizenz akzeptieren, bevor die Diarisierung funktioniert; setze `HF_TOKEN` als Umgebungsvariable
* **Batch-Size-Tuning** — beginne mit `batch_size=16`, reduziere auf 4–8 bei 12-GB-Karten, erhöhe auf 32 bei 24-GB-Karten
* **`int8` Berechnung** — verwenden Sie `compute_type="int8"` um die VRAM-Nutzung bei minimalem Qualitätsverlust zu halbieren
* **Docker-Image** — `pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime`
* **Persistenter Modell-Cache** — einbinden `/root/.cache/huggingface` um das erneute Herunterladen der Modelle bei jedem Container-Neustart zu vermeiden

## Fehlerbehebung

| Problem                              | Lösung                                                                                                                                |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| `CUDA-Speicher erschöpft`            | Reduziere `batch_size`, verwende `compute_type="int8"`, oder verwende ein kleineres Modell (medium, small)                            |
| Diarisierung gibt zurück `UNBEKANNT` | Stelle sicher, dass der HuggingFace-Token gültig ist und du die pyannote-Lizenz akzeptiert hast                                       |
| `Kein Modul namens 'whisperx'`       | `pip install whisperx` — stelle sicher, dass kein Tippfehler vorliegt (es ist `whisperx`, nicht `whisper-x`)                          |
| Schlechte Zeitstempel auf Wortebene  | Prüfe, dass `whisperx.align()` nach `transcribe()` aufgerufen wird — die rohe Whisper-Ausgabe verfügt nicht über Wortgenauigkeit      |
| Falsche Spracherkennung              | Erzwinge die Sprache mit `--language en` oder `language="en"` in der Python-API                                                       |
| Langsame Verarbeitung                | Erhöhen Sie `batch_size`, verwende `large-v3-turbo` anstelle von `large-v3`, stelle sicher, dass die GPU nicht gemeinsam genutzt wird |


---

# 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-de/audio-and-stimme/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.
