DiariZen
repository·main·Indexed 19 days ago
https://github.com/butspeechfit/diarizenA speaker diarization toolkit driven by AudioZen and Pyannote 3.1 that utilizes Spatially Aware WavLM models to identify 'who spoke when' in audio recordings. It includes the DiariZenPipeline for inference, support for RTTM format output, and modules for End-to-End Neural Diarization (EEND). The toolkit also provides utilities for structured pruning of WavLM, model checkpoint averaging, and specialized learning rate schedulers like NoamOpt.
What's inside diarizen
- The DiariZen EEND (End-to-End Neural Diarization) module provides scripts for training and performing global inference for speaker diarization. It leverages self-supervised learning (SSL) features, specifically showing high performance when using updated WavLM features.
Overview of Spatially Aware WavLM for Multi-Channel Diarization
mainThediar_ssl_mcrecipe provides scripts for implementing spatially aware WavLM models specifically designed for multi-channel speaker diarization. This approach leverages spatial information to improve speaker segmentation and identification in multi-microphone environments.Compatibility Note: Modified pyannote files in this repository
mainNote that this specific repository contains modifications to the original
pyannote.audiocode for compatibility purposes. If you intend to use the new/original Pyannote code, ensure you are aware of which files have been modified. The modified files in this repository are:pyannote/audio/core/model.pypyannote/audio/core/inference.pypyannote/audio/pipelines/utils/getter.pypyannote/audio/pipelines/utils/diarization.pypyannote/audio/pipelines/speaker_diarization.py
Streaming speaker diarization support
mainpyannote.audiodoes not support streaming speaker diarization out of the box.If you require streaming capabilities, the following alternatives are recommended:
- diart: A project providing streaming speaker diarization based on
pyannote.audio(GitHub). - Streaming VAD: For streaming Voice Activity Detection, refer to the official blog post on streaming VAD based on
pyannote.audio.
- diart: A project providing streaming speaker diarization based on
Improve diarization performance via fine-tuning
mainTo improve the performance of diarization models for your specific use case, follow this workflow:
- Annotate: Manually annotate dozens of conversations with high precision.
- Split: Divide your annotated data into training (80%), development (10%), and test (10%) subsets.
- Format: Set up the data using
pyannote.database. - Adapt: Follow the recipe for adapting a pretrained pipeline found in
tutorials/adapting_pretrained_pipeline.ipynb.
Run hyperparameter sweeps on a Slurm cluster
mainTo perform grid searches or launch multiple jobs on a Slurm cluster, use the
hydra-submitit-launcher.- Install the launcher:
pip install hydra-submitit-launcher --upgrade- Launch a multi-run job using the
--multirunflag and specifying thesubmitit_slurmlauncher. You can sweep over parameters by providing comma-separated values:
pyannote-audio-train \ --multirun hydra/launcher=submitit_slurm \ model=PyanNet +model.lstm.num_layers=2,3,4 +model.lstm.bidirectional=true,false \ task=VoiceActivityDetection \ registry="AMI-diarization-setup/pyannote/database.yml" \ protocol=AMI.SpeakerDiarization.only_wordsWarning: There are known compatibility issues between
pytorch-lightning,hydra-submitit, and multi-GPU setups.Install DiariZen
mainTo install DiariZen, follow these steps to set up a virtual environment, install PyTorch with CUDA 12.1 support, and install the required dependencies including
pyannote-audioanddscoresubmodules.# create virtual python environment conda create --name diarizen python=3.10 conda activate diarizen # install pytorch (CUDA 12.1 build) pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 \ --index-url https://download.pytorch.org/whl/cu121 # install diarizen pip install -r requirements.txt && pip install -e . # install pyannote-audio cd pyannote-audio && pip install -e .[dev,testing] -c ../constraints.txt && cd .. # install dscore git submodule init git submodule updateInstall and set up pyannote.audio
mainTo use
pyannote.audiofor speaker diarization, follow these steps:- Install the package via pip:
pip install pyannote.audio - Access the required models on Hugging Face by accepting the user conditions for:
pyannote/segmentation-3.0pyannote/speaker-diarization-3.1
- Create an access token at hf.co/settings/tokens to authenticate your requests.
pip install pyannote.audio- Install the package via pip:
Run inference with DiariZenPipeline
mainUse the
DiariZenPipelineclass to perform speaker diarization on audio files. You can load pre-trained models from Hugging Face and iterate through the resulting speaker turns.from diarizen.pipelines.inference import DiariZenPipeline # load pre-trained model diar_pipeline = DiariZenPipeline.from_pretrained("BUT-FIT/diarizen-wavlm-large-s80-md") # apply diarization pipeline diar_results = diar_pipeline('./example/EN2002a_30s.wav') # print results for turn, _, speaker in diar_results.itertracks(yield_label=True): print(f"start={turn.start:.1f}s stop={turn.end:.1f}s speaker_{speaker}")Install the pyannote-audio CLI
mainTo use the command line tools for training and evaluation, you must install
pyannote-audiowith the[cli]extra dependencies.pip install pyannote-audio[cli]Use gated models and pipelines offline
mainWhile
pyannote.audiouses a gating process (requiring authentication via Hugging Face) to track usage, this does not prevent offline usage in production environments (e.g., inside adocker runcommand). Once the models or pipelines are authenticated and downloaded, they can be used without repeated authentication. Refer to the following tutorials for specific implementation patterns:- For models:
tutorials/applying_a_model.ipynb - For pipelines:
tutorials/applying_a_pipeline.ipynb
- For models:
Configure training parameters with Hydra
mainpyannote-audio-trainis powered by Hydra. You can override any configuration parameter using dot notation in the command line.Inspect Configuration
To see the actual configuration being used for a training job, add the
--cfg jobflag:pyannote-audio-train --cfg job model=PyanNet task=VoiceActivityDetection ...Override Parameters
To change a parameter like
task.duration, append it to your command:pyannote-audio-train \ model=PyanNet \ task=VoiceActivityDetection task.duration=2.0 \ registry="AMI-diarization-setup/pyannote/database.yml" \ protocol=AMI.SpeakerDiarization.only_wordspyannote-audio-train --cfg job \ model=PyanNet \ task=VoiceActivityDetection \ registry="AMI-diarization-setup/pyannote/database.yml" \ protocol=AMI.SpeakerDiarization.only_words