msaf/run.py
def process(in_path, annot_beats=False, feature="pcp", framesync=False,
            boundaries_id=msaf.config.default_bound_id,
            labels_id=msaf.config.default_label_id, hier=False,
            sonify_bounds=False, plot=False, n_jobs=4, annotator_id=0,
            config=None, out_bounds="out_bounds.wav", out_sr=22050):
    """Main process to segment a file or a collection of files.

    Parameters
    ----------
    in_path: str
        Input path. If a directory, MSAF will function in collection mode.
        If audio file, MSAF will be in single file mode.
    annot_beats: bool
        Whether to use annotated beats or not.
    feature: str
        String representing the feature to be used (e.g. pcp, mfcc, tonnetz)
    framesync: str
        Whether to use framesync features or not (default: False -> beatsync)
    boundaries_id: str
        Identifier of the boundaries algorithm (use "gt" for groundtruth)
    labels_id: str
        Identifier of the labels algorithm (use None to not compute labels)
    hier : bool
        Whether to compute a hierarchical or flat segmentation.
    sonify_bounds: bool
        Whether to write an output audio file with the annotated boundaries
        or not (only available in Single File Mode).
    plot: bool
        Whether to plot the boundaries and labels against the ground truth.
    n_jobs: int
        Number of processes to run in parallel. Only available in collection
        mode.
    annotator_id: int
        Annotator identificator in the ground truth.
    config: dict
        Dictionary containing custom configuration parameters for the
        algorithms.  If None, the default parameters are used.
    out_bounds: str
        Path to the output for the sonified boundaries (only in single file
        mode, when sonify_bounds is True.
    out_sr : int
        Sampling rate for the sonified bounds.

    Returns
    -------
    results : list
        List containing tuples of (est_times, est_labels) of estimated
        boundary times and estimated labels.
        If labels_id is None, est_labels will be a list of -1.
    """
    # Seed random to reproduce results
    np.random.seed(123)

    # Set up configuration based on algorithms parameters
    if config is None:
        config = io.get_configuration(feature, annot_beats, framesync,
                                      boundaries_id, labels_id)
        config["features"] = None

    # Save multi-segment (hierarchical) configuration
    config["hier"] = hier
    if not os.path.exists(in_path):
        raise NoAudioFileError("File or directory does not exists, %s" %
                               in_path)
    if os.path.isfile(in_path):
        # Single file mode
        # Get (if they exitst) or compute features
        file_struct = msaf.io.FileStruct(in_path)

        # Use temporary file in single mode
        file_struct.features_file = msaf.config.features_tmp_file

        # Get features
        config["features"] = Features.select_features(
            feature, file_struct, annot_beats, framesync)

        # And run the algorithms
        est_times, est_labels = run_algorithms(file_struct, boundaries_id,
                                               labels_id, config,
                                               annotator_id=annotator_id)

        if sonify_bounds:
            logging.info("Sonifying boundaries in %s..." % out_bounds)
            audio_hq, sr = librosa.load(in_path, sr=out_sr)
            utils.sonify_clicks(audio_hq, est_times, out_bounds, out_sr)

        if plot:
            plotting.plot_one_track(file_struct, est_times, est_labels,
                                    boundaries_id, labels_id)

        # TODO: Only save if needed
        # Save estimations
        msaf.utils.ensure_dir(os.path.dirname(file_struct.est_file))
        io.save_estimations(file_struct, est_times, est_labels,
                            boundaries_id, labels_id, **config)

        return est_times, est_labels
    else:
        # Collection mode
        file_structs = io.get_dataset_files(in_path)

        return Parallel(n_jobs=n_jobs)(delayed(process_track)(
            file_struct, boundaries_id, labels_id, config,
            annotator_id=annotator_id) for file_struct in file_structs[:])
def process(in_path, annot_beats=False, feature="pcp", framesync=False,
            boundaries_id=msaf.config.default_bound_id,
            labels_id=msaf.config.default_label_id, hier=False,
            sonify_bounds=False, plot=False, n_jobs=4, annotator_id=0,
            config=None, out_bounds="out_bounds.wav", out_sr=22050):
    # Seed random to reproduce results
    np.random.seed(123)

    # Set up configuration based on algorithms parameters
    if config is None:
        config = io.get_configuration(feature, annot_beats, framesync,
                                      boundaries_id, labels_id)
        config["features"] = None

    # Save multi-segment (hierarchical) configuration
    config["hier"] = hier
    if not os.path.exists(in_path):
        raise NoAudioFileError("File or directory does not exists, %s" %
                               in_path)
    if os.path.isfile(in_path):
        # Single file mode
        # Get (if they exitst) or compute features
        file_struct = msaf.io.FileStruct(in_path)

        # Use temporary file in single mode
        file_struct.features_file = msaf.config.features_tmp_file

        # Get features
        config["features"] = Features.select_features(
            feature, file_struct, annot_beats, framesync)

        # And run the algorithms
        est_times, est_labels = run_algorithms(file_struct, boundaries_id,
                                               labels_id, config,
                                               annotator_id=annotator_id)

        if sonify_bounds:
            logging.info("Sonifying boundaries in %s..." % out_bounds)
            audio_hq, sr = librosa.load(in_path, sr=out_sr)
            utils.sonify_clicks(audio_hq, est_times, out_bounds, out_sr)

        if plot:
            plotting.plot_one_track(file_struct, est_times, est_labels,
                                    boundaries_id, labels_id)

        # TODO: Only save if needed
        # Save estimations
        msaf.utils.ensure_dir(os.path.dirname(file_struct.est_file))
        io.save_estimations(file_struct, est_times, est_labels,
                            boundaries_id, labels_id, **config)

        return est_times, est_labels
    else:
        # Collection mode
        file_structs = io.get_dataset_files(in_path)

        return Parallel(n_jobs=n_jobs)(delayed(process_track)(
            file_struct, boundaries_id, labels_id, config,
            annotator_id=annotator_id) for file_struct in file_structs[:])
def process ( in_path , annot_beats = False , feature = "pcp" , framesync = False , boundaries_id = msaf . config . default_bound_id , labels_id = msaf . config . default_label_id , hier = False , sonify_bounds = False , plot = False , n_jobs = 4 , annotator_id = 0 , config = None , out_bounds = "out_bounds.wav" , out_sr = 22050 ) : # Seed random to reproduce results np . random . seed ( 123 ) # Set up configuration based on algorithms parameters if config is None : config = io . get_configuration ( feature , annot_beats , framesync , boundaries_id , labels_id ) config [ "features" ] = None # Save multi-segment (hierarchical) configuration config [ "hier" ] = hier if not os . path . exists ( in_path ) : raise NoAudioFileError ( "File or directory does not exists, %s" % in_path ) if os . path . isfile ( in_path ) : # Single file mode # Get (if they exitst) or compute features file_struct = msaf . io . FileStruct ( in_path ) # Use temporary file in single mode file_struct . features_file = msaf . config . features_tmp_file # Get features config [ "features" ] = Features . select_features ( feature , file_struct , annot_beats , framesync ) # And run the algorithms est_times , est_labels = run_algorithms ( file_struct , boundaries_id , labels_id , config , annotator_id = annotator_id ) if sonify_bounds : logging . info ( "Sonifying boundaries in %s..." % out_bounds ) audio_hq , sr = librosa . load ( in_path , sr = out_sr ) utils . sonify_clicks ( audio_hq , est_times , out_bounds , out_sr ) if plot : plotting . plot_one_track ( file_struct , est_times , est_labels , boundaries_id , labels_id ) # TODO: Only save if needed # Save estimations msaf . utils . ensure_dir ( os . path . dirname ( file_struct . est_file ) ) io . save_estimations ( file_struct , est_times , est_labels , boundaries_id , labels_id , * * config ) return est_times , est_labels else : # Collection mode file_structs = io . get_dataset_files ( in_path ) return Parallel ( n_jobs = n_jobs ) ( delayed ( process_track ) ( file_struct , boundaries_id , labels_id , config , annotator_id = annotator_id ) for file_struct in file_structs [ : ] )
Main process to segment a file or a collection of files.

    Parameters
    ----------
    in_path: str
        Input path. If a directory, MSAF will function in collection mode.
        If audio file, MSAF will be in single file mode.
    annot_beats: bool
        Whether to use annotated beats or not.
    feature: str
        String representing the feature to be used (e.g. pcp, mfcc, tonnetz)
    framesync: str
        Whether to use framesync features or not (default: False -> beatsync)
    boundaries_id: str
        Identifier of the boundaries algorithm (use "gt" for groundtruth)
    labels_id: str
        Identifier of the labels algorithm (use None to not compute labels)
    hier : bool
        Whether to compute a hierarchical or flat segmentation.
    sonify_bounds: bool
        Whether to write an output audio file with the annotated boundaries
        or not (only available in Single File Mode).
    plot: bool
        Whether to plot the boundaries and labels against the ground truth.
    n_jobs: int
        Number of processes to run in parallel. Only available in collection
        mode.
    annotator_id: int
        Annotator identificator in the ground truth.
    config: dict
        Dictionary containing custom configuration parameters for the
        algorithms.  If None, the default parameters are used.
    out_bounds: str
        Path to the output for the sonified boundaries (only in single file
        mode, when sonify_bounds is True.
    out_sr : int
        Sampling rate for the sonified bounds.

    Returns
    -------
    results : list
        List containing tuples of (est_times, est_labels) of estimated
        boundary times and estimated labels.
        If labels_id is None, est_labels will be a list of -1.
Main process to segment a file or a collection of files .