mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
3.8 MiB
3.8 MiB
In [1]:
# for speechbrain
!pip install -qq torch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 torchtext==0.12.0
!pip install -qq speechbrain==0.5.12
# pyannote.audio
!pip install -qq pyannote.audio
# for visualization purposes
!pip install -qq moviepy ipython==7.34.0[K |████████████████████████████████| 750.6 MB 12 kB/s [K |████████████████████████████████| 21.0 MB 1.4 MB/s [K |████████████████████████████████| 2.9 MB 49.5 MB/s [K |████████████████████████████████| 10.4 MB 56.5 MB/s [K |████████████████████████████████| 496 kB 34.8 MB/s [K |████████████████████████████████| 101 kB 13.2 MB/s [K |████████████████████████████████| 1.2 MB 58.4 MB/s [K |████████████████████████████████| 596 kB 56.7 MB/s [K |████████████████████████████████| 109 kB 75.9 MB/s [K |████████████████████████████████| 546 kB 74.2 MB/s [?25h Building wheel for hyperpyyaml (setup.py) ... [?25l[?25hdone [K |████████████████████████████████| 385 kB 30.0 MB/s [K |████████████████████████████████| 110 kB 66.8 MB/s [K |████████████████████████████████| 79 kB 9.1 MB/s [K |████████████████████████████████| 47 kB 5.7 MB/s [K |████████████████████████████████| 41 kB 537 kB/s [K |████████████████████████████████| 129 kB 63.0 MB/s [K |████████████████████████████████| 419 kB 65.9 MB/s [K |████████████████████████████████| 51 kB 201 kB/s [K |████████████████████████████████| 65 kB 5.4 MB/s [K |████████████████████████████████| 585 kB 71.6 MB/s [K |████████████████████████████████| 117 kB 74.6 MB/s [K |████████████████████████████████| 130 kB 64.6 MB/s [K |████████████████████████████████| 308 kB 77.2 MB/s [K |████████████████████████████████| 81 kB 11.4 MB/s [K |████████████████████████████████| 209 kB 75.5 MB/s [K |████████████████████████████████| 140 kB 74.8 MB/s [K |████████████████████████████████| 1.1 MB 64.1 MB/s [K |████████████████████████████████| 58 kB 7.2 MB/s [K |████████████████████████████████| 144 kB 68.4 MB/s [K |████████████████████████████████| 271 kB 68.2 MB/s [K |████████████████████████████████| 94 kB 4.3 MB/s [K |████████████████████████████████| 78 kB 8.5 MB/s [K |████████████████████████████████| 112 kB 68.5 MB/s [K |████████████████████████████████| 147 kB 73.3 MB/s [K |████████████████████████████████| 49 kB 6.3 MB/s [?25h Building wheel for antlr4-python3-runtime (setup.py) ... [?25l[?25hdone Building wheel for julius (setup.py) ... [?25l[?25hdone Building wheel for pyperclip (setup.py) ... [?25l[?25hdone [K |████████████████████████████████| 793 kB 22.7 MB/s [K |████████████████████████████████| 381 kB 72.2 MB/s [31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. jupyter-console 5.2.0 requires prompt-toolkit<2.0.0,>=1.0.0, but you have prompt-toolkit 3.0.30 which is incompatible. google-colab 1.0.0 requires ipython~=5.5.0, but you have ipython 7.34.0 which is incompatible.[0m [?25h
In [2]:
!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 [5]:
!wget -q https://raw.githubusercontent.com/pyannote/AMI-diarization-setup/main/only_words/rttms/test/ES2004a.rttmIn [6]:
# load groundtruth
from pyannote.database.util import load_rttm
_, groundtruth = load_rttm('ES2004a.rttm').popitem()
# visualize groundtruth
groundtruthOut [6]:
In [7]:
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
groundtruthOut [7]:
In [8]:
from pyannote.audio import Audio
from IPython.display import Audio as IPythonAudio
waveform, sr = Audio().crop(DEMO_FILE, EXCERPT)
IPythonAudio(waveform.flatten(), rate=sr)Out [8]:
/usr/local/lib/python3.7/dist-packages/resampy/interpn.py:114: NumbaWarning: [1m[1mThe TBB threading layer requires TBB version 2019.5 or later i.e., TBB_INTERFACE_VERSION >= 11005. Found TBB_INTERFACE_VERSION = 9107. The TBB threading layer is disabled.[0m[0m _resample_loop_p(x, t_out, interp_win, interp_delta, num_table, scale, y)
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 [9]:
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained('pyannote/speaker-diarization')
diarization = pipeline(DEMO_FILE)Downloading: 0%| | 0.00/598 [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 [10]:
diarizationOut [10]:
In [11]:
from pyannote.metrics.diarization import DiarizationErrorRate
metric = DiarizationErrorRate()
der = metric(groundtruth, diarization)In [12]:
print(f'diarization error rate = {100 * der:.1f}%')diarization error rate = 18.4%
In [13]:
mapping = metric.optimal_mapping(groundtruth, diarization)
diarization.rename_labels(mapping=mapping)Out [13]:
In [14]:
groundtruthOut [14]:
In [ ]: