# Path: pyAudioAnalysis/MidTermFeatures.py
# def beat_extraction(short_features, window_size, plot=False):
# def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step,
#                            short_window, short_step):
# def directory_feature_extraction(folder_path, mid_window, mid_step,
#                                  short_window, short_step,
#                                  compute_beat=True):
# def multiple_directory_feature_extraction(path_list, mid_window, mid_step,
#                                           short_window, short_step,
#                                           compute_beat=False):
# def directory_feature_extraction_no_avg(folder_path, mid_window, mid_step,
#                                         short_window, short_step):
# def mid_feature_extraction_to_file(file_path, mid_window, mid_step,
#                                    short_window, short_step, output_file,
#                                    store_short_features=False, store_csv=False,
#                                    plot=False):
# def mid_feature_extraction_file_dir(folder_path, mid_window, mid_step,
#                                     short_window, short_step,
#                                     store_short_features=False, store_csv=False,
#                                     plot=False):
# 
# Path: pyAudioAnalysis/audioTrainTest.py
# class Knn:
#     def __init__(self, features, labels, neighbors):
#     def classify(self, test_sample):
# def classifier_wrapper(classifier, classifier_type, test_sample):
# def regression_wrapper(model, model_type, test_sample):
# def train_knn(features, labels, neighbors):
# def train_svm(features, labels, c_param, kernel='linear'):
# def train_random_forest(features, labels, n_estimators):
# def train_gradient_boosting(features, labels, n_estimators):
# def train_extra_trees(features, labels, n_estimators):
# def train_svm_regression(features, labels, c_param, kernel='linear'):
# def train_random_forest_regression(features, labels, n_estimators):
# def extract_features_and_train(paths, mid_window, mid_step, short_window,
#                                short_step, classifier_type, model_name,
#                                compute_beat=False, train_percentage=0.90,
#                                dict_of_ids=None,
#                                use_smote=False):
# def save_parameters(path, *parameters):
# def feature_extraction_train_regression(folder_name, mid_window, mid_step,
#                                         short_window, short_step, model_type,
#                                         model_name, compute_beat=False):
# def load_model_knn(knn_model_name, is_regression=False):
# def load_model(model_name, is_regression=False):
# def group_split(X, y, train_indeces, test_indeces, split_id):
# def evaluate_classifier(features, class_names, classifier_name, params,
#                         parameter_mode, list_of_ids=None, n_exp=-1,
#                         train_percentage=0.90,
#                         smote=False):
# def evaluate_regression(features, labels, n_exp, method_name, params):
# def print_confusion_matrix(cm, class_names):
# def features_to_matrix(features):
# def pca_wrapper(features, dimensions):
# def compute_class_rec_pre_f1(c_mat):
# def evaluate_model_for_folders(input_test_folders, model_name, model_type,
#                                positive_class, plot=True):
# def file_classification(input_file, model_name, model_type):
# def file_regression(input_file, model_name, model_type):
# def lda(data, labels, red_dim):
# def train_speaker_models():
# def main(argv):
#         P = np.zeros((n_classes,))
#                 R = regression_wrapper(classifier, method_name, fTest)
#     R = []
#     C = np.cov((data.T))


import shutil, struct, simplejson
import ntpath
import os
import sklearn
import sklearn.discriminant_analysis
import sys
import plotly.express as px
from scipy.spatial import distance
from pylab import *
from pyAudioAnalysis import MidTermFeatures as aF
from pyAudioAnalysis import audioTrainTest as aT
from sklearn.preprocessing import StandardScaler
            return
        
        names_category_toviz = [ntpath.basename(w).
                                    replace('.wav','').split(" --- ")[0]
                                for w in wav_files];
        names_to_viz = [ntpath.basename(w).replace('.wav', '')
                        for w in wav_files];


        scaler = StandardScaler()
        F = scaler.fit_transform(all_mt_feat)
        
        # check that the new PCA dimension is at most equal
        # to the number of samples
        K1 = 2
        K2 = 10
        if K1 > F.shape[0]:
            K1 = F.shape[0]
        if K2 > F.shape[0]:
            K2 = F.shape[0]
        pca1 = sklearn.decomposition.PCA(n_components = K1)
        pca1.fit(F)        
        pca2 = sklearn.decomposition.PCA(n_components = K2)
        pca2.fit(F)        

        finalDims = pca1.transform(F)
        finalDims2 = pca2.transform(F)
    else:
        # long-term statistics cannot be applied in this context
        # (LDA needs mid-term features)

# Path: pyAudioAnalysis/MidTermFeatures.py
# def beat_extraction(short_features, window_size, plot=False):
# def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step,
#                            short_window, short_step):
# def directory_feature_extraction(folder_path, mid_window, mid_step,
#                                  short_window, short_step,
#                                  compute_beat=True):
# def multiple_directory_feature_extraction(path_list, mid_window, mid_step,
#                                           short_window, short_step,
#                                           compute_beat=False):
# def directory_feature_extraction_no_avg(folder_path, mid_window, mid_step,
#                                         short_window, short_step):
# def mid_feature_extraction_to_file(file_path, mid_window, mid_step,
#                                    short_window, short_step, output_file,
#                                    store_short_features=False, store_csv=False,
#                                    plot=False):
# def mid_feature_extraction_file_dir(folder_path, mid_window, mid_step,
#                                     short_window, short_step,
#                                     store_short_features=False, store_csv=False,
#                                     plot=False):
# 
# Path: pyAudioAnalysis/audioTrainTest.py
# class Knn:
#     def __init__(self, features, labels, neighbors):
#     def classify(self, test_sample):
# def classifier_wrapper(classifier, classifier_type, test_sample):
# def regression_wrapper(model, model_type, test_sample):
# def train_knn(features, labels, neighbors):
# def train_svm(features, labels, c_param, kernel='linear'):
# def train_random_forest(features, labels, n_estimators):
# def train_gradient_boosting(features, labels, n_estimators):
# def train_extra_trees(features, labels, n_estimators):
# def train_svm_regression(features, labels, c_param, kernel='linear'):
# def train_random_forest_regression(features, labels, n_estimators):
# def extract_features_and_train(paths, mid_window, mid_step, short_window,
#                                short_step, classifier_type, model_name,
#                                compute_beat=False, train_percentage=0.90,
#                                dict_of_ids=None,
#                                use_smote=False):
# def save_parameters(path, *parameters):
# def feature_extraction_train_regression(folder_name, mid_window, mid_step,
#                                         short_window, short_step, model_type,
#                                         model_name, compute_beat=False):
# def load_model_knn(knn_model_name, is_regression=False):
# def load_model(model_name, is_regression=False):
# def group_split(X, y, train_indeces, test_indeces, split_id):
# def evaluate_classifier(features, class_names, classifier_name, params,
#                         parameter_mode, list_of_ids=None, n_exp=-1,
#                         train_percentage=0.90,
#                         smote=False):
# def evaluate_regression(features, labels, n_exp, method_name, params):
# def print_confusion_matrix(cm, class_names):
# def features_to_matrix(features):
# def pca_wrapper(features, dimensions):
# def compute_class_rec_pre_f1(c_mat):
# def evaluate_model_for_folders(input_test_folders, model_name, model_type,
#                                positive_class, plot=True):
# def file_classification(input_file, model_name, model_type):
# def file_regression(input_file, model_name, model_type):
# def lda(data, labels, red_dim):
# def train_speaker_models():
# def main(argv):
#         P = np.zeros((n_classes,))
#                 R = regression_wrapper(classifier, method_name, fTest)
#     R = []
#     C = np.cov((data.T))


# Path: pyAudioAnalysis/audioVisualization.py
import shutil, struct, simplejson
import ntpath
import os
import sklearn
import sklearn.discriminant_analysis
import sys
import plotly.express as px
from scipy.spatial import distance
from pylab import *
from pyAudioAnalysis import MidTermFeatures as aF
from pyAudioAnalysis import audioTrainTest as aT
from sklearn.preprocessing import StandardScaler

            return
        
        names_category_toviz = [ntpath.basename(w).
                                    replace('.wav','').split(" --- ")[0]
                                for w in wav_files];
        names_to_viz = [ntpath.basename(w).replace('.wav', '')
                        for w in wav_files];


        scaler = StandardScaler()
        F = scaler.fit_transform(all_mt_feat)
        
        # check that the new PCA dimension is at most equal
        # to the number of samples
        K1 = 2
        K2 = 10
        if K1 > F.shape[0]:
            K1 = F.shape[0]
        if K2 > F.shape[0]:
            K2 = F.shape[0]
        pca1 = sklearn.decomposition.PCA(n_components = K1)
        pca1.fit(F)        
        pca2 = sklearn.decomposition.PCA(n_components = K2)
        pca2.fit(F)        

        finalDims = pca1.transform(F)
        finalDims2 = pca2.transform(F)
    else:
        # long-term statistics cannot be applied in this context
        # (LDA needs mid-term features)

        all_mt_feat, Ys, wav_files = aF.\