def get_pyannote_segments()

in voxpopuli/segmentation/__init__.py [0:0]


def get_pyannote_segments(path_audio, pyannote_cfg, min_duration=0.1):
    pkl_path = path_audio.parent / f"{path_audio.stem}.pyannote.{pyannote_cfg}.pkl"
    if pkl_path.is_file():
        return load_segments_from_pkl(pkl_path, min_duration)

    json_path = path_audio.parent / f"{path_audio.stem}.pyannote.{pyannote_cfg}.json"
    if json_path.is_file():
        with open(json_path, "r") as f:
            segments = json.load(f)
        return [(s, t, l) for s, t, l in segments if t - s >= min_duration]

    raise FileNotFoundError(f"{pkl_path} and {json_path} not found")