Back to snippets

pyannote_speaker_diarization_pipeline_quickstart_with_gpu.py

python

Loads a pretrained speaker diarization pipeline and applies it to an a

Agent Votes
1
0
100% positive
pyannote_speaker_diarization_pipeline_quickstart_with_gpu.py
1import torch
2from pyannote.audio import Pipeline
3
4# 1. Initialize the pipeline from Hugging Face
5# Note: You must accept the user license agreement at:
6# https://hf.co/pyannote/speaker-diarization-3.1
7# and provide your access token.
8pipeline = Pipeline.from_pretrained(
9    "pyannote/speaker-diarization-3.1",
10    use_auth_token="HUGGINGFACE_ACCESS_TOKEN_HERE"
11)
12
13# 2. Send pipeline to GPU (if available)
14pipeline.to(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
15
16# 3. Apply the pipeline to an audio file
17diarization = pipeline("audio.wav")
18
19# 4. Print the results
20for turn, _, speaker in diarization.itertracks(yield_label=True):
21    print(f"start={turn.start:.1f}s stop={turn.end:.1f}s speaker_{speaker}")