Overview of pyannote.audio
mainpyannote.audio is an open-source toolkit designed for state-of-the-art speaker diarization tasks.repository·main·Indexed 26 days ago
https://github.com/pyannote/pyannote-audioA Python-based toolkit for state-of-the-art speaker diarization built on PyTorch. It provides pretrained models and pipelines, including the open-source community-1 pipeline and the premium precision-2 service via pyannoteAI. The toolkit includes features for sliding window inference, model fine-tuning, layer freezing, and a CLI for optimizing, benchmarking, and applying pipelines to audio files.
pyannote.audio is an open-source toolkit designed for state-of-the-art speaker diarization tasks.Gated models and pipelines can be used offline. While the initial authentication process (filling out gating forms) is required to access them, you do not need to go through the authentication process every time you run your application (e.g., in a docker run command) once they are accessed.
For specific instructions on offline usage:
tutorials/applying_a_model.ipynb.tutorials/applying_a_pipeline.ipynb.The precision-2 pipeline is a premium service that runs on pyannoteAI servers. To use it:
dashboard.pyannote.ai.Pipeline.from_pretrained using the pyannote/speaker-diarization-precision-2 identifier.from pyannote.audio import Pipeline
# Precision-2 premium speaker diarization service
pipeline = Pipeline.from_pretrained(
"pyannote/speaker-diarization-precision-2", token="PYANNOTEAI_API_KEY")
output = pipeline("audio.wav") # runs on pyannoteAI servers
# print the result
for turn, speaker in output.speaker_diarization:
print(f"start={turn.start:.1f}s stop={turn.end:.1f}s {speaker}")The community-1 pipeline runs locally. To use it, you must:
pyannote/speaker-diarization-community-1 on Hugging Face.hf.co/settings/tokens.Pipeline.from_pretrained.You can optionally move the pipeline to a GPU using .to(torch.device("cuda")) and use a ProgressHook to monitor progress.
import torch
from pyannote.audio import Pipeline
from pyannote.audio.pipelines.utils.hook import ProgressHook
# Community-1 open-source speaker diarization pipeline
pipeline = Pipeline.from_pretrained(
"pyannote/speaker-diarization-community-1",
token="HUGGINGFACE_ACCESS_TOKEN")
# send pipeline to GPU (when available)
pipeline.to(torch.device("cuda"))
# apply pretrained pipeline (with optional progress hook)
with ProgressHook() as hook:
output = pipeline("audio.wav", hook=hook) # runs locally
# print the result
for turn, speaker in output.speaker_diarization:
print(f"start={turn.start:.1f}s stop={turn.end:.1f}s speaker_{speaker}")To set up the environment for developing the pyannote.audio library, install the package in editable mode with development and testing dependencies, then install the pre-commit hooks.
pip install -e .[dev,testing]
pre-commit installpyannote.audio toolkit, ensure ffmpeg is installed on your machine (required by the torchcodec audio decoding library). You can then install the package using uv (recommended) or pip.pytest to verify the library installation and development environment.pytestTo improve performance beyond the default pretrained models, you can fine-tune the pipeline using your own data. The recommended workflow is:
pyannote.database.tutorials/adapting_pretrained_pipeline.ipynb to adapt the pretrained pipeline to your specific domain.tutorials/applying_a_pipeline.ipynb tutorial for implementation details.You can control the optional anonymous telemetry feature using environment variables, within a Python session, or globally across sessions. Telemetry tracks pipeline origin, class, and file duration/speaker counts, but does not track user identity.
Environment Variable:
Set PYANNOTE_METRICS_ENABLED to 1 to enable or 0 to disable.
Python Session:
Use set_telemetry_metrics(bool) from pyannote.audio.telemetry.
Global Configuration:
Use set_telemetry_metrics(bool, save_choice_as_default=True) to persist settings across sessions.
# enable metrics
export PYANNOTE_METRICS_ENABLED=1
# disable metrics
export PYANNOTE_METRICS_ENABLED=0from pyannote.audio.telemetry import set_telemetry_metrics
# enable metrics for current session
set_telemetry_metrics(True)
# disable metrics globally
set_telemetry_metrics(False, save_choice_as_default=True)pyannote.database to load a protocol and prepare datasets for training. Protocols typically provide access to train(), development(), and test() sets.To finetune a model like pyannote/segmentation-3.0 for OSD, follow these steps:
huggingface_hub.notebook_login() to access weights.pytorch-lightning to fit the model.from pyannote.audio.tasks import OverlappedSpeechDetection
from pyannote.audio.core.model import Model
import pytorch_lightning as pl
# 1. Initialize task
osd = OverlappedSpeechDetection(protocol, duration=2., batch_size=16)
# 2. Load model and assign task
pretrained_model = Model.from_pretrained("pyannote/segmentation-3.0", token=True)
pretrained_model.task = osd
# 3. Train
trainer = pl.Trainer(max_epochs=1)
trainer.fit(pretrained_model)from pyannote.audio.tasks import OverlappedSpeechDetection
from pyannote.audio.core.model import Model
import pytorch_lightning as pl
osd = OverlappedSpeechDetection(protocol, duration=2., batch_size=16)
pretrained_model = Model.from_pretrained("pyannote/segmentation-3.0", token=True)
pretrained_model.task = osd
trainer = pl.Trainer(max_epochs=1)
trainer.fit(pretrained_model)