Views
No views yet
1# load the pipeline from Hugginface Hub
2from pyannote.audio import Pipeline
3pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization@2022.07")
4
5# apply the pipeline to an audio file
6diarization = pipeline("audio.wav")
7
8# dump the diarization output to disk using RTTM format
9with open("audio.rttm", "w") as rttm:
10 diarization.write_rttm(rttm)1handler = EndpointHandler()
2diarization = handler({"inputs": base64_audio, "parameters": {"num_speakers": 2}})1handler = EndpointHandler()
2diarization = handler({"inputs": base64_audio, "parameters": {"min_speakers": 2, "max_speakers": 5}})1hparams = handler.pipeline.parameters(instantiated=True)
2hparams["segmentation_onset"] += 0.1
3handler.pipeline.instantiate(hparams)1from typing import Dict
2from pyannote.audio import Pipeline
3import torch
4import base64
5import numpy as np
6
7SAMPLE_RATE = 16000
8
9class EndpointHandler():
10 def __init__(self, path=""):
11 # load the model
12 self.pipeline = Pipeline.from_pretrained("KIFF/pyannote-speaker-diarization-endpoint")
13
14 def __call__(self, data: Dict[str, bytes]) -> Dict[str, str]:
15 """
16 Args:
17 data (:obj:):
18 includes the deserialized audio file as bytes
19 Return:
20 A :obj:`dict`:. base64 encoded image
21 """
22 # process input
23 inputs = data.pop("inputs", data)
24 parameters = data.pop("parameters", None) # min_speakers=2, max_speakers=5
25
26 # decode the base64 audio data
27 audio_data = base64.b64decode(inputs)
28 audio_nparray = np.frombuffer(audio_data, dtype=np.int16)
29
30 # prepare pynannote input
31 audio_tensor= torch.from_numpy(audio_nparray).float().unsqueeze(0)
32 pyannote_input = {"waveform": audio_tensor, "sample_rate": SAMPLE_RATE}
33
34 # apply pretrained pipeline
35 # pass inputs with all kwargs in data
36 if parameters is not None:
37 diarization = self.pipeline(pyannote_input, **parameters)
38 else:
39 diarization = self.pipeline(pyannote_input)
40
41 # postprocess the prediction
42 processed_diarization = [
43 {"label": str(label), "start": str(segment.start), "stop": str(segment.end)}
44 for segment, _, label in diarization.itertracks(yield_label=True)
45 ]
46
47 return {"diarization": processed_diarization}| Benchmark | DER% | FA% | Miss% | Conf% | Expected output | File-level evaluation |
|---|---|---|---|---|---|---|
| AISHELL-4 | 14.61 | 3.31 | 4.35 | 6.95 | RTTM | eval |
| AMI Mix-Headset only_words | 18.21 | 3.28 | 11.07 | 3.87 | RTTM | eval |
| AMI Array1-01 only_words | 29.00 | 2.71 | 21.61 | 4.68 | RTTM | eval |
| CALLHOME Part2 | 30.24 | 3.71 | 16.86 | 9.66 | RTTM | eval |
| DIHARD 3 Full | 20.99 | 4.25 | 10.74 | 6.00 | RTTM | eval |
| REPERE Phase 2 | 12.62 | 1.55 | 3.30 | 7.76 | RTTM | eval |
| VoxConverse v0.0.2 | 12.76 | 3.45 | 3.85 | 5.46 | RTTM | eval |
1@inproceedings{Bredin2021,
2 Title = {{End-to-end speaker segmentation for overlap-aware resegmentation}},
3 Author = {{Bredin}, Herv{\'e} and {Laurent}, Antoine},
4 Booktitle = {Proc. Interspeech 2021},
5 Address = {Brno, Czech Republic},
6 Month = {August},
7 Year = {2021},
8}1@inproceedings{Bredin2020,
2 Title = {{pyannote.audio: neural building blocks for speaker diarization}},
3 Author = {{Bredin}, Herv{\'e} and {Yin}, Ruiqing and {Coria}, Juan Manuel and {Gelly}, Gregory and {Korshunov}, Pavel and {Lavechin}, Marvin and {Fustes}, Diego and {Titeux}, Hadrien and {Bouaziz}, Wassim and {Gill}, Marie-Philippe},
4 Booktitle = {ICASSP 2020, IEEE International Conference on Acoustics, Speech, and Signal Processing},
5 Address = {Barcelona, Spain},
6 Month = {May},
7 Year = {2020},
8}