mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
2.5 MiB
2.5 MiB
In [ ]:
!pip install -qq pyannote.audio==3.1.1
!pip install -qq ipython==7.34.0In [ ]:
!wget -q http://groups.inf.ed.ac.uk/ami/AMICorpusMirror/amicorpus/ES2004a/audio/ES2004a.Mix-Headset.wav
DEMO_FILE = {'uri': 'ES2004a.Mix-Headset', 'audio': 'ES2004a.Mix-Headset.wav'}In [ ]:
!wget -q https://raw.githubusercontent.com/pyannote/AMI-diarization-setup/main/only_words/rttms/test/ES2004a.rttmIn [ ]:
# load groundtruth
from pyannote.database.util import load_rttm
_, groundtruth = load_rttm('ES2004a.rttm').popitem()
# visualize groundtruth
groundtruthIn [ ]:
from pyannote.core import Segment, notebook
# make notebook visualization zoom on 600s < t < 660s time range
EXCERPT = Segment(600, 660)
notebook.crop = EXCERPT
# visualize excerpt groundtruth
groundtruthIn [ ]:
from pyannote.audio import Audio
from IPython.display import Audio as IPythonAudio
waveform, sr = Audio(mono="downmix").crop(DEMO_FILE, EXCERPT)
IPythonAudio(waveform.flatten(), rate=sr)In [ ]:
import google.colab
own_file, _ = google.colab.files.upload().popitem()
OWN_FILE = {'audio': own_file}
notebook.reset()
# load audio waveform and play it
waveform, sample_rate = Audio(mono="downmix")(OWN_FILE)
IPythonAudio(data=waveform.squeeze(), rate=sample_rate, autoplay=True)In [ ]:
groundtruth_rttm, _ = google.colab.files.upload().popitem()
groundtruths = load_rttm(groundtruth_rttm)
if OWN_FILE['audio'] in groundtruths:
groundtruth = groundtruths[OWN_FILE['audio']]
else:
_, groundtruth = groundtruths.popitem()
groundtruth
Upload widget is only available when the cell has been executed in the
current browser session. Please rerun this cell to enable.
Saving sample.rttm to sample.rttm
In [ ]:
from huggingface_hub import notebook_login
notebook_login()VBox(children=(HTML(value='<center> <img\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…
In [ ]:
# load pretrained pipeline
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained('pyannote/speaker-diarization-3.1', token=True)
# send pipeline to GPU (when available)
import torch
if torch.cuda.is_available():
pipeline.to(torch.device('cuda'))
# run the pipeline (with progress bar)
from pyannote.audio.pipelines.utils.hook import ProgressHook
with ProgressHook() as hook:
diarization = pipeline(DEMO_FILE, hook=hook)In [ ]:
diarizationIn [ ]:
from pyannote.metrics.diarization import DiarizationErrorRate
metric = DiarizationErrorRate()
der = metric(groundtruth, diarization)In [ ]:
print(f'diarization error rate = {100 * der:.1f}%')diarization error rate = 19.8%
In [ ]:
mapping = metric.optimal_mapping(groundtruth, diarization)
diarization.rename_labels(mapping=mapping)In [ ]:
groundtruth