mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
189 KiB
189 KiB
In [ ]:
# preparing notebook for visualization purposes
# (only show outputs between t=0s and t=30s)
from pyannote.core import notebook, Segment
notebook.crop = Segment(0, 30)In [ ]:
# clone pyannote-audio Github repository and update ROOT_DIR accordingly
ROOT_DIR = "/Users/hbredin/Development/pyannote/pyannote-audio"
AUDIO_FILE = f"{ROOT_DIR}/tutorials/assets/sample.wav"In [ ]:
from pyannote.database.util import load_rttm
REFERENCE = f"{ROOT_DIR}/tutorials/assets/sample.rttm"
reference = load_rttm(REFERENCE)["sample"]
referenceIn [ ]:
from huggingface_hub import HfApi
available_models = [m.modelId for m in HfApi().list_models(filter="pyannote-audio-model")]
available_models['pyannote/segmentation', 'pyannote/embedding', 'pyannote/TestModelForContinuousIntegration', 'pyannote/Segmentation-PyanNet-DIHARD']
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 Model
model = Model.from_pretrained("pyannote/segmentation", use_auth_token=True)In [ ]:
model.summarize()| Name | Type | Params | In sizes | Out sizes -------------------------------------------------------------------------------------------------------- 0 | sincnet | SincNet | 42.6 K | [3, 1, 32000] | [3, 60, 115] 1 | lstm | LSTM | 1.4 M | [3, 115, 60] | [[3, 115, 256], [[8, 3, 128], [8, 3, 128]]] 2 | linear | ModuleList | 49.4 K | ? | ? 3 | classifier | Linear | 387 | [3, 115, 128] | [3, 115, 3] 4 | activation | Sigmoid | 0 | [3, 115, 3] | [3, 115, 3] -------------------------------------------------------------------------------------------------------- 1.5 M Trainable params 0 Non-trainable params 1.5 M Total params 5.891 Total estimated model params size (MB)
In [ ]:
specs = model.specifications
specsSpecifications(problem=<Problem.MULTI_LABEL_CLASSIFICATION: 2>, resolution=<Resolution.FRAME: 1>, duration=5.0, warm_up=(0.0, 0.0), classes=['speaker#1', 'speaker#2', 'speaker#3'], permutation_invariant=True)
In [ ]:
from pyannote.audio import Inference
inference = Inference(model, step=2.5)
output = inference(AUDIO_FILE)
outputIn [ ]:
output.data.shape(11, 293, 3)
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 [ ]:
output = inference(audio_in_memory)
outputIn [ ]:
from pyannote.core import Segment
output = inference.crop(AUDIO_FILE, Segment(10, 20))
output