# 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/audioSegmentation.py
# def smooth_moving_avg(signal, window=11):
# def self_similarity_matrix(feature_vectors):
# def labels_to_segments(labels, window):
# def segments_to_labels(start_times, end_times, labels, window):
# def compute_metrics(confusion_matrix, class_names):
# def read_segmentation_gt(gt_file):
# def plot_segmentation_results(flags_ind, flags_ind_gt, class_names, mt_step,
#                               evaluate_only=False):
# def evaluate_speaker_diarization(labels, labels_gt):
# def train_hmm_compute_statistics(features, labels):
# def train_hmm_from_file(wav_file, gt_file, hmm_model_name, mid_window, mid_step):
# def train_hmm_from_directory(folder_path, hmm_model_name, mid_window, mid_step):
# def save_hmm(hmm_model_name, model, classes, mid_window, mid_step):
# def hmm_segmentation(audio_file, hmm_model_name, plot_results=False,
#                      gt_file=""):
# def load_ground_truth_segments(gt_file, mt_step):
# def calculate_confusion_matrix(predictions, ground_truth, classes):
# def mid_term_file_classification(input_file, model_name, model_type,
#                                  plot_results=False, gt_file=""):
# def load_ground_truth(gt_file, labels, class_names, mid_step, plot_results):
# def evaluate_segmentation_classification_dir(dir_name, model_name, method_name):
# def silence_removal(signal, sampling_rate, st_win, st_step, smooth_window=0.5,
#                     weight=0.5, plot=False):
# def speaker_diarization(filename, n_speakers, mid_window=1.0, mid_step=0.1,
#                         short_window=0.1, lda_dim=0, plot_res=False):
# def speaker_diarization_evaluation(folder_name, lda_dimensions):
# def music_thumbnailing(signal, sampling_rate, short_window=1.0, short_step=0.5,
#                        thumb_size=10.0, limit_1=0, limit_2=1):


import sys
import os
import numpy as np
from pyAudioAnalysis import audioTrainTest as aT
from pyAudioAnalysis import audioSegmentation as aS
sys.path.insert(0, os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "../"))


def test_speaker_diarization():
    labels, purity_cluster_m, purity_speaker_m = \
        aS.speaker_diarization("test_data/diarizationExample.wav", 
                                4, plot_res=False)
    assert purity_cluster_m > 0.9, "Diarization cluster purity is low"
    assert purity_speaker_m > 0.9, "Diarization speaker purity is low"


def test_mt_file_classification():

# 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/audioSegmentation.py
# def smooth_moving_avg(signal, window=11):
# def self_similarity_matrix(feature_vectors):
# def labels_to_segments(labels, window):
# def segments_to_labels(start_times, end_times, labels, window):
# def compute_metrics(confusion_matrix, class_names):
# def read_segmentation_gt(gt_file):
# def plot_segmentation_results(flags_ind, flags_ind_gt, class_names, mt_step,
#                               evaluate_only=False):
# def evaluate_speaker_diarization(labels, labels_gt):
# def train_hmm_compute_statistics(features, labels):
# def train_hmm_from_file(wav_file, gt_file, hmm_model_name, mid_window, mid_step):
# def train_hmm_from_directory(folder_path, hmm_model_name, mid_window, mid_step):
# def save_hmm(hmm_model_name, model, classes, mid_window, mid_step):
# def hmm_segmentation(audio_file, hmm_model_name, plot_results=False,
#                      gt_file=""):
# def load_ground_truth_segments(gt_file, mt_step):
# def calculate_confusion_matrix(predictions, ground_truth, classes):
# def mid_term_file_classification(input_file, model_name, model_type,
#                                  plot_results=False, gt_file=""):
# def load_ground_truth(gt_file, labels, class_names, mid_step, plot_results):
# def evaluate_segmentation_classification_dir(dir_name, model_name, method_name):
# def silence_removal(signal, sampling_rate, st_win, st_step, smooth_window=0.5,
#                     weight=0.5, plot=False):
# def speaker_diarization(filename, n_speakers, mid_window=1.0, mid_step=0.1,
#                         short_window=0.1, lda_dim=0, plot_res=False):
# def speaker_diarization_evaluation(folder_name, lda_dimensions):
# def music_thumbnailing(signal, sampling_rate, short_window=1.0, short_step=0.5,
#                        thumb_size=10.0, limit_1=0, limit_2=1):


# Path: pytests/test_segmentation.py
import sys
import os
import numpy as np
from pyAudioAnalysis import audioTrainTest as aT
from pyAudioAnalysis import audioSegmentation as aS

sys.path.insert(0, os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "../"))


def test_speaker_diarization():
    labels, purity_cluster_m, purity_speaker_m = \
        aS.speaker_diarization("test_data/diarizationExample.wav", 
                                4, plot_res=False)
    assert purity_cluster_m > 0.9, "Diarization cluster purity is low"
    assert purity_speaker_m > 0.9, "Diarization speaker purity is low"


def test_mt_file_classification():

    labels, class_names, accuracy, cm = aS.mid_term_file_classification(