mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
140 KiB
140 KiB
In [4]:
!pip install -qq pyannote.audio==3.1.1
!pip install -qq ipython==7.34.0
!wget -q "https://github.com/pyannote/pyannote-audio/raw/develop/tutorials/assets/sample.wav"
!wget -q "https://github.com/pyannote/pyannote-audio/raw/develop/tutorials/assets/sample.rttm"
!wget -q -P ./assets/ "https://github.com/pyannote/pyannote-audio/blob/develop/tutorials/assets/download-model.png"
!wget -q -P ./assets/ "https://github.com/pyannote/pyannote-audio/blob/develop/tutorials/assets/download-pipeline.png"In [13]:
AUDIO_FILE = "sample.wav"
REFERENCE = "sample.rttm"In [10]:
ROOT_DIR = "<path-to-pyannote-github-repo>/pyannote-audio"
AUDIO_FILE = f"{ROOT_DIR}/tutorials/assets/sample.wav"
REFERENCE = f"{ROOT_DIR}/tutorials/assets/sample.rttm"In [2]:
from huggingface_hub import HfApi
available_pipelines = [p.modelId for p in HfApi().list_models(filter="pyannote-audio-pipeline")]
list(filter(lambda p: p.startswith("pyannote/"), available_pipelines))Out [2]:
['pyannote/overlapped-speech-detection', 'pyannote/speaker-diarization', 'pyannote/speaker-segmentation', 'pyannote/voice-activity-detection', 'pyannote/speaker-diarization-3.0', 'pyannote/speaker-diarization-3.1']
In [ ]:
from huggingface_hub import notebook_login
notebook_login()In [ ]:
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1", use_auth_token=True)In [9]:
dia = pipeline(AUDIO_FILE)In [10]:
from pyannote.core import Annotation
assert isinstance(dia, Annotation)In [11]:
for speech_turn, track, speaker in dia.itertracks(yield_label=True):
print(f"{speech_turn.start:4.1f} {speech_turn.end:4.1f} {speaker}")6.7 7.2 SPEAKER_01 7.2 7.2 SPEAKER_02 7.6 8.3 SPEAKER_01 8.3 9.9 SPEAKER_02 9.9 10.9 SPEAKER_01 10.5 14.7 SPEAKER_02 10.9 11.0 SPEAKER_00 14.3 17.9 SPEAKER_00 18.0 21.5 SPEAKER_02 18.2 18.4 SPEAKER_00 21.8 28.5 SPEAKER_00 27.9 30.0 SPEAKER_02
In [12]:
# we visualize [0, 30] time range
from pyannote.core import notebook, Segment
notebook.crop = Segment(0, 30)
diaOut [12]:
In [14]:
from pyannote.database.util import load_rttm
reference = load_rttm(REFERENCE)["sample"]
# map hypothesized and reference speakers for visualization purposes
pipeline.optimal_mapping(dia, reference)Out [14]:
In [11]:
import torchaudio
waveform, sample_rate = torchaudio.load(AUDIO_FILE)
print(f"{type(waveform)=}")
print(f"{waveform.shape=}")
print(f"{waveform.dtype=}")
audio_in_memory = {"waveform": waveform, "sample_rate": sample_rate}type(waveform)=<class 'torch.Tensor'> waveform.shape=torch.Size([1, 480000]) waveform.dtype=torch.float32
In [ ]:
vad = Pipeline.from_pretrained("pyannote/voice-activity-detection", use_auth_token=True)In [12]:
vad(audio_in_memory)Out [12]:
In [ ]:
# look ma: no hands!
offline_vad = Pipeline.from_pretrained("config.yaml")
offline_vad(audio_in_memory)In [ ]:
# just checking output is the same
assert (vad(audio_in_memory) == offline_vad(audio_in_memory))
