<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Running MSAF
The main MSAF functionality is demonstrated here.
Step1:  Single File Mode
This mode analyzes one audio file at a time.
Step2:  Using different Algorithms
MSAF includes multiple algorithms both for boundary retrieval and structural grouping (or labeling). In this section we demonstrate how to try them out.
Note
Step3:  Using different Features
Some algorithms allow the input of different type of features (e.g., harmonic, timbral). In this section we show how we can input different features to MSAF.
Step4:  Evaluate Results
The results can be evaluated as long as there is an existing file containing reference annotations. The results are stored in a pandas DataFrame. MSAF has to run these algorithms (using msaf.process described above) before being able to evaluate its results.
Step5:  Explore Algorithm Parameters
Now let's modify the configuration of one of the files, and modify it to see how different the results are.
We will use Widgets, which will become handy here.
Step6:  Collection Mode
MSAF is able to run and evaluate mutliple files using multi-threading. In this section we show this functionality.
<ASSISTANT_TASK:>
Python Code:
from __future__ import print_function
import msaf
import librosa
import seaborn as sns
# and IPython.display for audio output
import IPython.display
# Setup nice plots
sns.set(style="dark")
%matplotlib inline
Explanation: Running MSAF
The main MSAF functionality is demonstrated here.
End of explanation
# Choose an audio file and listen to it
audio_file = "../datasets/Sargon/audio/01-Sargon-Mindless.mp3"
IPython.display.Audio(filename=audio_file)
# Segment the file using the default MSAF parameters
boundaries, labels = msaf.process(audio_file)
print(boundaries)
# Sonify boundaries
sonified_file = "my_boundaries.wav"
sr = 44100
boundaries, labels = msaf.process(audio_file, sonify_bounds=True, 
                                  out_bounds=sonified_file, out_sr=sr)
# Listen to results
audio = librosa.load(sonified_file, sr=sr)[0]
IPython.display.Audio(audio, rate=sr)
Explanation: Single File Mode
This mode analyzes one audio file at a time.
End of explanation
# First, let's list all the available boundary algorithms
print(msaf.get_all_boundary_algorithms())
# Try one of these boundary algorithms and print results
boundaries, labels = msaf.process(audio_file, boundaries_id="foote", plot=True)
# Let's check all the structural grouping (label) algorithms available
print(msaf.get_all_label_algorithms())
# Try one of these label algorithms
boundaries, labels = msaf.process(audio_file, boundaries_id="foote", labels_id="fmc2d")
print(boundaries)
print(labels)
# If available, you can use previously annotated boundaries and a specific labels algorithm
# Set plot = True to plot the results
boundaries, labels = msaf.process(audio_file, boundaries_id="gt", 
                                  labels_id="scluster", plot=True)
Explanation: Using different Algorithms
MSAF includes multiple algorithms both for boundary retrieval and structural grouping (or labeling). In this section we demonstrate how to try them out.
Note: more algorithms are available in msaf-gpl.
End of explanation
# Let's check what available features are there in MSAF
print(msaf.AVAILABLE_FEATS)
# Segment the file using the Foote method for boundaries, C-NMF method for labels, and MFCC features
boundaries, labels = msaf.process(audio_file, feature="mfcc", boundaries_id="foote", 
                                  labels_id="cnmf", plot=True)
Explanation: Using different Features
Some algorithms allow the input of different type of features (e.g., harmonic, timbral). In this section we show how we can input different features to MSAF.
End of explanation
# Evaluate the results. It returns a pandas data frame.
evaluations = msaf.eval.process(audio_file, boundaries_id="foote", labels_id="fmc2d")
IPython.display.display(evaluations)
Explanation: Evaluate Results
The results can be evaluated as long as there is an existing file containing reference annotations. The results are stored in a pandas DataFrame. MSAF has to run these algorithms (using msaf.process described above) before being able to evaluate its results.
End of explanation
# First, check which are foote's algorithm parameters:
print(msaf.algorithms.foote.config)
# play around with IPython.Widgets
from IPython.html.widgets import interact
# Obtain the default configuration
bid = "foote"  # Boundaries ID
lid = None     # Labels ID
feature = "hpcp"
config = msaf.io.get_configuration(feature, annot_beats=False, framesync=False, 
                                   boundaries_id=bid, labels_id=lid)
# Sweep M_gaussian parameters
@interact(M_gaussian=(50, 500, 25))
def _run_msaf(M_gaussian):
    # Set the configuration
    config["M_gaussian"] = M_gaussian
    
    # Segment the file using the Foote method, and Pitch Class Profiles for the features
    results = msaf.process(audio_file, feature=feature, boundaries_id=bid, 
                           config=config, plot=True)
    # Evaluate the results. It returns a pandas data frame.
    evaluations = msaf.eval.process(audio_file, feature=feature, boundaries_id=bid,
                                    config=config)
    IPython.display.display(evaluations)
Explanation: Explore Algorithm Parameters
Now let's modify the configuration of one of the files, and modify it to see how different the results are.
We will use Widgets, which will become handy here.
End of explanation
dataset = "../datasets/Sargon/"
results = msaf.process(dataset, n_jobs=4, boundaries_id="foote")
# Evaluate in collection mode
evaluations = msaf.eval.process(dataset, n_jobs=4, boundaries_id="foote")
IPython.display.display(evaluations)
Explanation: Collection Mode
MSAF is able to run and evaluate mutliple files using multi-threading. In this section we show this functionality.
End of explanation
<END_TASK>