# Whisper Diarization

> A ready-made pipeline that labels who said what, built on Whisper and NeMo

- Category: Multimodal Generation / Audio, Music & Voice
- Language: Python
- Licence: BSD-2-Clause
- Repository: https://github.com/MahmoudAshraf97/whisper-diarization
- Canonical page: https://ai-tldr.dev/tools/whisper-diarization/

## In short

Whisper Diarization is a ready-made pipeline that labels who said what, built on Whisper and NeMo. It sits in the Audio, Music & Voice category of the Multimodal Generation tools and is open-source, written in Python and licensed BSD-2-Clause. To get started: install the prerequisites.

## Overview

Whisper transcribes words but not speakers: run a two-person interview through it and you get one undifferentiated block of text. Whisper Diarization is the pipeline that fills that gap — it stitches Whisper together with voice activity detection, forced alignment and speaker embedding models so every sentence, and in fact every word, comes back tagged with who said it.

The chain is deliberate. Vocals are first separated out of the audio, which makes the speaker embeddings more accurate. Whisper generates the transcription. `ctc-forced-aligner` then corrects and aligns the timestamps so diarization errors caused by time shift are minimised. MarbleNet handles VAD and segmentation to exclude silence, TitaNet extracts a speaker embedding per segment, and the per-word timestamps are matched against those segments — then realigned using punctuation models to absorb small remaining shifts.

It is a script-first project rather than a library: you clone it, install the pinned requirements, and run `diarize.py` against an audio file. A `diarize_parallel.py` variant runs NeMo alongside Whisper instead of after it, which can help on machines with 10 GB or more of VRAM — the result is identical because the two models do not depend on each other. The README is candid about what it does not yet handle: overlapping speakers remain an open problem, and Whisper/NeMo parameters are still coded into `diarize.py` and `helpers.py` rather than exposed as flags.

## What it does

- Word-level speaker attribution, not just sentence-level, by matching forced-aligned word timestamps against diarized segments
- Source separation before embedding extraction, so speaker identity is judged on isolated vocals rather than mixed audio
- NeMo MarbleNet for voice activity detection and segmentation, and TitaNet for speaker embeddings
- Punctuation-model realignment as a final pass to compensate for minor timestamp drift
- A parallel variant (diarize_parallel.py) that runs NeMo concurrently with Whisper when you have ≥10 GB of VRAM
- CLI flags for the Whisper model size, language, device, batch size, source separation and numeral suppression

## Getting started

Python 3.10 or newer is recommended. FFMPEG and Cython are prerequisites — install both before the Python requirements.

1. Install the prerequisites

   Cython and FFMPEG are needed to install the requirements.

```bash
pip install cython
# then FFMPEG, e.g.
sudo apt update && sudo apt install ffmpeg   # Ubuntu / Debian
brew install ffmpeg                          # macOS
choco install ffmpeg                         # Windows (Chocolatey)
```

2. Clone the repo and install the pinned requirements

   The constraints file matters — it pins the versions the pipeline is tested against.

```bash
git clone https://github.com/MahmoudAshraf97/whisper-diarization.git
cd whisper-diarization
pip install -c constraints.txt -r requirements.txt
```

3. Run the pipeline on an audio file

   This is the whole interface: point -a at the file and let the chain run.

```bash
python diarize.py -a AUDIO_FILE_NAME
```

4. Tune it with the CLI options

   The default ASR model is medium.en and the device defaults to cuda when available. --suppress_numerals transcribes numbers as pronounced words, which improves alignment accuracy; reduce --batch-size if you run out of memory (0 disables batching).

```bash
python diarize.py -a interview.wav --whisper-model large-v3 --language en --suppress_numerals --device cuda
```

5. Use the parallel variant on a big GPU

   With ≥10 GB of VRAM this runs NeMo in parallel with Whisper. Still experimental, per the README, but the output is the same.

```bash
python diarize_parallel.py -a AUDIO_FILE_NAME
```

## When to use it

- Turn interview, podcast or meeting recordings into transcripts where each line is attributed to a named speaker channel
- Produce word-level speaker labels for subtitle or caption workflows that need to switch colour or position per speaker
- Prepare diarized transcripts as input for downstream summarisation or analysis, where 'who proposed what' changes the answer
- Evaluate the accuracy cost of source separation and forced alignment on your own audio by toggling --no-stem and comparing
