mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
- setup: switch to torch 2.0+ and lightning 2.0+ - setup: switch to torchaudio 2.0+ and soundfile 0.12+ - setup: switch to pyannote.core 5.0+ and pyannote.database 5.0+ - setup: switch to speechbrain 0.5.14+ - BREAKING(task): rename `Segmentation` task to `SpeakerDiarization` - BREAKING(task): remove support for variable chunk duration - BREAKING(pipeline): remove `SpeakerSegmentation` pipeline (in favor of `SpeakerDiarization` pipeline) - BREAKING(pipeline): remove support `FINCHClustering` and `HiddenMarkovModelClustering` - BREAKING: drop support for Python 3.7
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().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()(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