mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
* related bugs: #1119 #1128 #1130 * related discussions: #1123 #1103 #1126 #1121
48 KiB
48 KiB
In [4]:
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 [4]:
['pyannote/overlapped-speech-detection', 'pyannote/speaker-diarization', 'pyannote/speaker-segmentation', 'pyannote/voice-activity-detection']
In [2]:
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 [5]:
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization@develop", use_auth_token=True)In [6]:
ROOT_DIR = "/Users/hbredin/Development/pyannote/pyannote-audio"
AUDIO_FILE = f"{ROOT_DIR}/tutorials/assets/sample.wav"
dia = pipeline(AUDIO_FILE)In [7]:
from pyannote.core import Annotation
assert isinstance(dia, Annotation)In [8]:
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.1 SPEAKER_02 7.6 8.3 SPEAKER_00 8.3 14.8 SPEAKER_02 9.8 11.0 SPEAKER_00 14.3 18.5 SPEAKER_00 17.9 21.5 SPEAKER_01 21.7 28.6 SPEAKER_00 27.8 29.5 SPEAKER_02
In [9]:
# we visualize [0, 30] time range
from pyannote.core import notebook, Segment
notebook.crop = Segment(0, 30)
diaOut [9]:
In [10]:
from pyannote.database.util import load_rttm
REFERENCE = f"{ROOT_DIR}/tutorials/assets/sample.rttm"
reference = load_rttm(REFERENCE)["sample"]
# map hypothesized and reference speakers for visualization purposes
pipeline.optimal_mapping(dia, reference)Out [10]:
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 [12]:
vad = Pipeline.from_pretrained("pyannote/voice-activity-detection", use_auth_token=True)
vad(audio_in_memory)Out [12]:
In [21]:
# look ma: no hands!
offline_vad = Pipeline.from_pretrained("config.yaml")
offline_vad(audio_in_memory)Out [21]:
In [22]:
# just checking output is the same
assert (vad(audio_in_memory) == offline_vad(audio_in_memory))
