VAD & Clustering Audio Segments
1
stars
29
commits
Python
primary language
Jun 29, 2025
updated
This project implements a comprehensive speaker diarization system capable of identifying "who spoke when" in an audio recording. It leverages the state-of-the-art pyannote/speaker-diarization-3.1 pipeline for core diarization tasks and includes custom modules for audio preprocessing, speaker change detection, interactive visualization of results, and robust evaluation using Diarization Error Rate (DER).
The system is designed for modularity, reproducibility, and ease of use, with full Docker support.
pyannote/speaker-diarization-3.1 pipeline from Hugging Face, which integrates VAD, speaker embedding, and clustering.pyannote pipeline intrinsically handles and accounts for overlapping speech segments.git clone https://github.com/D4X-max/Speaker-Diarization-VAD-CAS.git cd Speaker-Diarization-VAD-CAS
This project uses models from Hugging Face Hub (specifically pyannote/speaker-diarization-3.1). To download and use these models, you need a Hugging Face authentication token.
pyannote pipeline. Visit the following links and click on "Agree and Access repository" for each:
speaker-diarization-3.1 model might internally pull segmentation-3.0 and embedding. Accepting conditions for all three is a good practice.)Create a Virtual Environment (Optional but Recommended):
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
Install Dependencies:
pip install -r requirements.txt
(If requirements.txt is not yet generated, you can do so by running pip freeze > requirements.txt after installing all necessary libraries manually, or manually create it with libraries like librosa, numpy, soundfile, pyannote.audio, pyannote.core, pyannote.metrics, matplotlib, torch, etc.)
Dockerfile in the project root.
docker build -t speaker-diarization-app .
(Note: The first time you run a diarization command with Docker, pyannote will download the models to the container's volume. Subsequent runs will be faster.)This project provides several scripts for different functionalities. All scripts should be run from the project's root directory.
For a streamlined workflow, the src/main.py script orchestrates the entire process: preprocessing, diarization, saving outputs, generating a visualization plot, and performing evaluation (if a ground truth RTTM is available).
Command
python -m src.main <path_to_input_audio> --auth_token <your_hugging_face_token> [OPTIONS]
Arguments
**<path_to_input_audio>**: (Required) Path to your .wav or .flac audio file (e.g., data/sample_audio.wav).**--auth_token <your_hugging_face_token>**: (Required) Your Hugging Face authentication token.Options
**--min_speakers <int>**: Minimum number of speakers expected (e.g., 2).**--max_speakers <int>**: Maximum number of speakers expected (e.g., 5).**--clustering_threshold <float>**: Threshold for clustering speaker embeddings (e.g., 0.7).Example
python -m src.main data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE --min_speakers 2
Output This single command will:
outputs/ directory (.rttm and .csv files).plots/ directory (.png file).data/sample_audio.rttm).outputs/ directory (.json file).The main diarization script processes an audio file and outputs RTTM and CSV files.
python src/diarize.py <path_to_input_audio> --auth_token <your_hugging_face_token>
[OPTIONS]
<path_to_input_audio>: Path to your .wav or .flac audio file (e.g., data/sample_audio.wav).--auth_token <your_hugging_face_token>: Your Hugging Face authentication token (required).Options:
--min_speakers <int>: Minimum number of speakers expected (e.g., 2).--max_speakers <int>: Maximum number of speakers expected (e.g., 5).--clustering_threshold <float>: Threshold for clustering speaker embeddings (e.g., 0.7).Example:
python src/diarize.py data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE --min_speakers 1 --max_speakers 3
Output:
Diarization results will be saved in the outputs/ directory:
outputs/<audio_filename_base>_diarization.csvoutputs/<audio_filename_base>_diarization.rttmThis script runs the diarization pipeline and then identifies and reports the timestamps of speaker changes.
python src/speaker_change_detection.py <path_to_input_audio> --auth_token <your_hugging_face_token>
[OPTIONS]
<path_to_input_audio>: Path to your .wav or .flac audio file.--auth_token <your_hugging_face_token>: Your Hugging Face authentication token (required).Options: (Same as diarize.py for passing to the diarization pipeline)
Example:
python src/speaker_change_detection.py data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE
Output:
In addition to the diarization files in outputs/, speaker change points will be printed to the console.
This script generates a visual plot of the diarization results overlaid on the audio waveform.
python src/visualize.py <path_to_input_audio>
[OPTIONS]
<path_to_input_audio>: Path to your .wav or .flac audio file.Options:
--rttm_file <path_to_rttm>: Optional. Path to an existing RTTM file (e.g., outputs/sample_audio_diarization.rttm). If provided, the script will plot this RTTM instead of performing live diarization.--auth_token <your_hugging_face_token>: Required if --rttm_file is NOT used. Your Hugging Face authentication token for live diarization.--min_speakers, --max_speakers, --clustering_threshold: (For live diarization only) Same options as diarize.py.--output_dir <dir_path>: Directory to save the plot (default: plots/).--output_name <filename>: Name of the output PNG file (default: audio_filename_base_diarization.png).--plot_width <float>, --plot_height <float>: Dimensions of the output plot in inches.Examples:
python src/visualize.py data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE --output_dir my_plots --output_name my_diarization_plot.png
python src/visualize.py data/sample_audio.wav --rttm_file outputs/sample_audio_diarization.rttm --output_dir my_plots
Output:
A PNG image of the diarization plot will be saved in the specified output directory (default: plots/).
This script calculates the Diarization Error Rate (DER) between a reference (ground truth) RTTM and a hypothesis (system output) RTTM.
python src/evaluate.py <path_to_reference_rttm> <path_to_hypothesis_rttm>
[OPTIONS]
<path_to_reference_rttm>: Path to your ground truth RTTM file (e.g., data/sample_audio.rttm).<path_to_hypothesis_rttm>: Path to the system-generated RTTM file (e.g., outputs/sample_audio_diarization.rttm).Options:
--output_json <path_to_json>: Path to save a JSON file containing detailed DER results (e.g., der_results.json).Example:
python src/evaluate.py data/sample_audio.rttm outputs/sample_audio_diarization.rttm --output_json outputs/sample_audio_der.json
Output: DER results will be printed to the console and optionally saved to a JSON file.
You can run all the above commands within a Docker container to ensure a consistent environment and avoid local dependency conflicts.
Build the Docker Image (if you haven't already):
docker build -t speaker-diarization-app .
Run Commands via Docker:
To run any of the Python scripts, you'll use docker run and mount your project directory into the container. This allows the container to access your data/ and src/ directories and save outputs to your host machine.
General Docker Run Command Structure:
docker run --rm \
-v "$(pwd)":/app \
-e HF_AUTH_TOKEN="your_hugging_face_token" \ # Pass token as environment variable
speaker-diarization-app \
python /app/src/<script_name>.py /app/<path_to_input_audio_in_container> [OPTIONS]
Important: Replace $(pwd) with %cd% on Windows in Command Prompt or $PWD in PowerShell. Ensure your host machine's data/ and any generated outputs/ or plots/ directories are mapped correctly.
Example: Diarize with Docker:
docker run --rm \
-v "$(pwd)":/app \
-e HF_AUTH_TOKEN="hf_YOUR_TOKEN_HERE" \
speaker-diarization-app \
python /app/src/diarize.py /app/data/sample_audio.wav --min_speakers 1 --max_speakers 2
Example: Visualize with Docker (from existing RTTM):
docker run --rm \
-v "$(pwd)":/app \
speaker-diarization-app \
python /app/src/visualize.py /app/data/sample_audio.wav --rttm_file /app/outputs/sample_audio_diarization.rttm --output_dir /app/plots
(Note: When running visualization without an RTTM file (i.e., live diarization), you'll need to pass the --auth_token argument directly to the python command, instead of the HF_AUTH_TOKEN environment variable).
Example: Evaluate with Docker:
docker run --rm \
-v "$(pwd)":/app \
speaker-diarization-app \
python /app/src/evaluate.py /app/data/sample_audio.rttm /app/outputs/sample_audio_diarization.rttm --output_json /app/outputs/sample_audio_der.json
https://github.com/user-attachments/assets/a987bdcd-764d-432e-aa12-aa2fa8fe9980
Feel free to fork the repository, open issues, or submit pull requests.
(Optional section, e.g., MIT License) [License information here]
29 commits
Python
86.7%
Batchfile
5.9%
Shell
5.2%
Dockerfile
2.3%
VAD & Clustering Audio Segments
1
stars
29
commits
Python
primary language
Jun 29, 2025
updated
This project implements a comprehensive speaker diarization system capable of identifying "who spoke when" in an audio recording. It leverages the state-of-the-art pyannote/speaker-diarization-3.1 pipeline for core diarization tasks and includes custom modules for audio preprocessing, speaker change detection, interactive visualization of results, and robust evaluation using Diarization Error Rate (DER).
The system is designed for modularity, reproducibility, and ease of use, with full Docker support.
pyannote/speaker-diarization-3.1 pipeline from Hugging Face, which integrates VAD, speaker embedding, and clustering.pyannote pipeline intrinsically handles and accounts for overlapping speech segments.git clone https://github.com/D4X-max/Speaker-Diarization-VAD-CAS.git cd Speaker-Diarization-VAD-CAS
This project uses models from Hugging Face Hub (specifically pyannote/speaker-diarization-3.1). To download and use these models, you need a Hugging Face authentication token.
pyannote pipeline. Visit the following links and click on "Agree and Access repository" for each:
speaker-diarization-3.1 model might internally pull segmentation-3.0 and embedding. Accepting conditions for all three is a good practice.)Create a Virtual Environment (Optional but Recommended):
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
Install Dependencies:
pip install -r requirements.txt
(If requirements.txt is not yet generated, you can do so by running pip freeze > requirements.txt after installing all necessary libraries manually, or manually create it with libraries like librosa, numpy, soundfile, pyannote.audio, pyannote.core, pyannote.metrics, matplotlib, torch, etc.)
Dockerfile in the project root.
docker build -t speaker-diarization-app .
(Note: The first time you run a diarization command with Docker, pyannote will download the models to the container's volume. Subsequent runs will be faster.)This project provides several scripts for different functionalities. All scripts should be run from the project's root directory.
For a streamlined workflow, the src/main.py script orchestrates the entire process: preprocessing, diarization, saving outputs, generating a visualization plot, and performing evaluation (if a ground truth RTTM is available).
Command
python -m src.main <path_to_input_audio> --auth_token <your_hugging_face_token> [OPTIONS]
Arguments
**<path_to_input_audio>**: (Required) Path to your .wav or .flac audio file (e.g., data/sample_audio.wav).**--auth_token <your_hugging_face_token>**: (Required) Your Hugging Face authentication token.Options
**--min_speakers <int>**: Minimum number of speakers expected (e.g., 2).**--max_speakers <int>**: Maximum number of speakers expected (e.g., 5).**--clustering_threshold <float>**: Threshold for clustering speaker embeddings (e.g., 0.7).Example
python -m src.main data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE --min_speakers 2
Output This single command will:
outputs/ directory (.rttm and .csv files).plots/ directory (.png file).data/sample_audio.rttm).outputs/ directory (.json file).The main diarization script processes an audio file and outputs RTTM and CSV files.
python src/diarize.py <path_to_input_audio> --auth_token <your_hugging_face_token>
[OPTIONS]
<path_to_input_audio>: Path to your .wav or .flac audio file (e.g., data/sample_audio.wav).--auth_token <your_hugging_face_token>: Your Hugging Face authentication token (required).Options:
--min_speakers <int>: Minimum number of speakers expected (e.g., 2).--max_speakers <int>: Maximum number of speakers expected (e.g., 5).--clustering_threshold <float>: Threshold for clustering speaker embeddings (e.g., 0.7).Example:
python src/diarize.py data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE --min_speakers 1 --max_speakers 3
Output:
Diarization results will be saved in the outputs/ directory:
outputs/<audio_filename_base>_diarization.csvoutputs/<audio_filename_base>_diarization.rttmThis script runs the diarization pipeline and then identifies and reports the timestamps of speaker changes.
python src/speaker_change_detection.py <path_to_input_audio> --auth_token <your_hugging_face_token>
[OPTIONS]
<path_to_input_audio>: Path to your .wav or .flac audio file.--auth_token <your_hugging_face_token>: Your Hugging Face authentication token (required).Options: (Same as diarize.py for passing to the diarization pipeline)
Example:
python src/speaker_change_detection.py data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE
Output:
In addition to the diarization files in outputs/, speaker change points will be printed to the console.
This script generates a visual plot of the diarization results overlaid on the audio waveform.
python src/visualize.py <path_to_input_audio>
[OPTIONS]
<path_to_input_audio>: Path to your .wav or .flac audio file.Options:
--rttm_file <path_to_rttm>: Optional. Path to an existing RTTM file (e.g., outputs/sample_audio_diarization.rttm). If provided, the script will plot this RTTM instead of performing live diarization.--auth_token <your_hugging_face_token>: Required if --rttm_file is NOT used. Your Hugging Face authentication token for live diarization.--min_speakers, --max_speakers, --clustering_threshold: (For live diarization only) Same options as diarize.py.--output_dir <dir_path>: Directory to save the plot (default: plots/).--output_name <filename>: Name of the output PNG file (default: audio_filename_base_diarization.png).--plot_width <float>, --plot_height <float>: Dimensions of the output plot in inches.Examples:
python src/visualize.py data/sample_audio.wav --auth_token hf_YOUR_TOKEN_HERE --output_dir my_plots --output_name my_diarization_plot.png
python src/visualize.py data/sample_audio.wav --rttm_file outputs/sample_audio_diarization.rttm --output_dir my_plots
Output:
A PNG image of the diarization plot will be saved in the specified output directory (default: plots/).
This script calculates the Diarization Error Rate (DER) between a reference (ground truth) RTTM and a hypothesis (system output) RTTM.
python src/evaluate.py <path_to_reference_rttm> <path_to_hypothesis_rttm>
[OPTIONS]
<path_to_reference_rttm>: Path to your ground truth RTTM file (e.g., data/sample_audio.rttm).<path_to_hypothesis_rttm>: Path to the system-generated RTTM file (e.g., outputs/sample_audio_diarization.rttm).Options:
--output_json <path_to_json>: Path to save a JSON file containing detailed DER results (e.g., der_results.json).Example:
python src/evaluate.py data/sample_audio.rttm outputs/sample_audio_diarization.rttm --output_json outputs/sample_audio_der.json
Output: DER results will be printed to the console and optionally saved to a JSON file.
You can run all the above commands within a Docker container to ensure a consistent environment and avoid local dependency conflicts.
Build the Docker Image (if you haven't already):
docker build -t speaker-diarization-app .
Run Commands via Docker:
To run any of the Python scripts, you'll use docker run and mount your project directory into the container. This allows the container to access your data/ and src/ directories and save outputs to your host machine.
General Docker Run Command Structure:
docker run --rm \
-v "$(pwd)":/app \
-e HF_AUTH_TOKEN="your_hugging_face_token" \ # Pass token as environment variable
speaker-diarization-app \
python /app/src/<script_name>.py /app/<path_to_input_audio_in_container> [OPTIONS]
Important: Replace $(pwd) with %cd% on Windows in Command Prompt or $PWD in PowerShell. Ensure your host machine's data/ and any generated outputs/ or plots/ directories are mapped correctly.
Example: Diarize with Docker:
docker run --rm \
-v "$(pwd)":/app \
-e HF_AUTH_TOKEN="hf_YOUR_TOKEN_HERE" \
speaker-diarization-app \
python /app/src/diarize.py /app/data/sample_audio.wav --min_speakers 1 --max_speakers 2
Example: Visualize with Docker (from existing RTTM):
docker run --rm \
-v "$(pwd)":/app \
speaker-diarization-app \
python /app/src/visualize.py /app/data/sample_audio.wav --rttm_file /app/outputs/sample_audio_diarization.rttm --output_dir /app/plots
(Note: When running visualization without an RTTM file (i.e., live diarization), you'll need to pass the --auth_token argument directly to the python command, instead of the HF_AUTH_TOKEN environment variable).
Example: Evaluate with Docker:
docker run --rm \
-v "$(pwd)":/app \
speaker-diarization-app \
python /app/src/evaluate.py /app/data/sample_audio.rttm /app/outputs/sample_audio_diarization.rttm --output_json /app/outputs/sample_audio_der.json
https://github.com/user-attachments/assets/a987bdcd-764d-432e-aa12-aa2fa8fe9980
Feel free to fork the repository, open issues, or submit pull requests.
(Optional section, e.g., MIT License) [License information here]
29 commits
Python
86.7%
Batchfile
5.9%
Shell
5.2%
Dockerfile
2.3%