msaf/run.py
def run_hierarchical(audio_file, bounds_module, labels_module, frame_times,
                     config, annotator_id=0):
    """Runs hierarchical algorithms with the specified identifiers on the
    audio_file. See run_algorithm for more information.
    """
    # Sanity check
    if bounds_module is None:
        raise NoHierBoundaryError("A boundary algorithm is needed when using "
                                  "hierarchical segmentation.")

    # Get features to make code nicer
    features = config["features"].features

    # Compute boundaries
    S = bounds_module.Segmenter(audio_file, **config)
    est_idxs, est_labels = S.processHierarchical()

    # Compute labels if needed
    if labels_module is not None and \
            bounds_module.__name__ != labels_module.__name__:
        # Compute labels for each level in the hierarchy
        flat_config = deepcopy(config)
        flat_config["hier"] = False
        for i, level_idxs in enumerate(est_idxs):
            S = labels_module.Segmenter(audio_file,
                                        in_bound_idxs=level_idxs,
                                        **flat_config)
            est_labels[i] = S.processFlat()[1]

    # Make sure the first and last boundaries are included for each
    # level in the hierarchy
    est_times = []
    cleaned_est_labels = []
    for level in range(len(est_idxs)):
        est_level_times, est_level_labels = \
            utils.process_segmentation_level(
                est_idxs[level], est_labels[level], features.shape[0],
                frame_times, config["features"].dur)
        est_times.append(est_level_times)
        cleaned_est_labels.append(est_level_labels)
    est_labels = cleaned_est_labels

    return est_times, est_labels
def run_hierarchical(audio_file, bounds_module, labels_module, frame_times,
                     config, annotator_id=0):
    """Runs hierarchical algorithms with the specified identifiers on the
    audio_file. See run_algorithm for more information.
    """
    # Sanity check
    if bounds_module is None:
        raise NoHierBoundaryError("A boundary algorithm is needed when using "
                                  "hierarchical segmentation.")

    # Get features to make code nicer
    features = config["features"].features

    # Compute boundaries
    S = bounds_module.Segmenter(audio_file, **config)
    est_idxs, est_labels = S.processHierarchical()

    # Compute labels if needed
    if labels_module is not None and \
            bounds_module.__name__ != labels_module.__name__:
        # Compute labels for each level in the hierarchy
        flat_config = deepcopy(config)
        flat_config["hier"] = False
        for i, level_idxs in enumerate(est_idxs):
            S = labels_module.Segmenter(audio_file,
                                        in_bound_idxs=level_idxs,
                                        **flat_config)
            est_labels[i] = S.processFlat()[1]

    # Make sure the first and last boundaries are included for each
    # level in the hierarchy
    est_times = []
    cleaned_est_labels = []
    for level in range(len(est_idxs)):
        est_level_times, est_level_labels = \
            utils.process_segmentation_level(
                est_idxs[level], est_labels[level], features.shape[0],
                frame_times, config["features"].dur)
        est_times.append(est_level_times)
        cleaned_est_labels.append(est_level_labels)
    est_labels = cleaned_est_labels

    return est_times, est_labels
Runs hierarchical algorithms with the specified identifiers on the
    audio_file. See run_algorithm for more information.