mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
- BREAKING(io): channels are now 0-indexed (used to be 1-indexed) - BREAKING(io): multi-channel audio is no longer downmixed to mono by default. You should update how `pyannote.audio.core.io.Audio` is instantiated: * replace `Audio()` by `Audio(mono="downmix")`; * replace `Audio(mono=True)` by `Audio(mono="downmix")`; * replace `Audio(mono=False)` by `Audio()`.
3.9 MiB
3.9 MiB
In [ ]:
!pip install -qq https://github.com/pyannote/pyannote-audio/archive/refs/heads/develop.zip
!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)
Upload widget is only available when the cell has been executed in the
current browser session. Please rerun this cell to enable.
Saving sample.wav to sample.wav
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()Login successful Your token has been saved to /root/.huggingface/token
In [ ]:
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained('pyannote/speaker-diarization', use_auth_token=True)
diarization = pipeline(DEMO_FILE)Downloading: 0%| | 0.00/500 [00:00<?, ?B/s]
Downloading: 0%| | 0.00/17.7M [00:00<?, ?B/s]
Downloading: 0%| | 0.00/318 [00:00<?, ?B/s]
Downloading: 0%| | 0.00/1.92k [00:00<?, ?B/s]
Downloading: 0%| | 0.00/83.3M [00:00<?, ?B/s]
Downloading: 0%| | 0.00/1.92k [00:00<?, ?B/s]
Downloading: 0%| | 0.00/5.53M [00:00<?, ?B/s]
Downloading: 0%| | 0.00/129k [00:00<?, ?B/s]
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.2%
In [ ]:
mapping = metric.optimal_mapping(groundtruth, diarization)
diarization.rename_labels(mapping=mapping)In [ ]:
groundtruth