mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
36 KiB
36 KiB
In [ ]:
from huggingface_hub import HfApi
available_pipelines = [p.modelId for p in HfApi().list_models(filter="pyannote-audio-pipeline")]
available_pipelines['pyannote/speaker-diarization', 'pyannote/speaker-segmentation', 'pyannote/voice-activity-detection', 'pyannote/overlapped-speech-detection', 'philschmid/pyannote-speaker-diarization-endpoint']
In [ ]:
from huggingface_hub import notebook_login
notebook_login()Login successful Your token has been saved to /Users/hbredin/.huggingface/token [1m[31mAuthenticated through git-credential store but this isn't the helper defined on your machine. You might have to re-authenticate when pushing to the Hugging Face Hub. Run the following command in your terminal in case you want to set this credential helper as the default git config --global credential.helper store[0m
In [ ]:
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization@develop", use_auth_token=True)In [ ]:
ROOT_DIR = "/Users/hbredin/Development/pyannote/pyannote-audio"
AUDIO_FILE = f"{ROOT_DIR}/tutorials/assets/sample.wav"
dia = pipeline(AUDIO_FILE)In [ ]:
from pyannote.core import Annotation
assert isinstance(dia, Annotation)In [ ]:
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 6.9 8.3 SPEAKER_00 8.3 14.8 SPEAKER_02 9.8 11.0 SPEAKER_00 14.3 18.5 SPEAKER_01 17.9 21.5 SPEAKER_02 21.7 28.6 SPEAKER_01 27.8 29.5 SPEAKER_02
In [ ]:
# we visualize [0, 30] time range
from pyannote.core import notebook, Segment
notebook.crop = Segment(0, 30)
diaIn [ ]:
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)In [ ]:
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")
vad(audio_in_memory)