from featextraction import *

if __name__ == "__main__":
    feat_set = input("features: \n")
    dataset = input("dataset: \n")
    if feat_set == "paa-lld":
        feature_names = [
            "zcr",
            "energy",
            "energy_entropy",
            "spectral_centroid",
            "spectral_spread",
            "spectral_entropy",
            "spectral_flux",
            "spectral_rolloff",
            "mfcc_1",
            "mfcc_2",
            "mfcc_3",
            "mfcc_4",
            "mfcc_5",
            "mfcc_6",
            "mfcc_7",
            "mfcc_8",
            "mfcc_9",
            "mfcc_10",
            "mfcc_11",
            "mfcc_12",
            "mfcc_13",
            "chroma_1",
            "chroma_2",
            "chroma_3",
            "chroma_4",
            "chroma_5",
            "chroma_6",
            "chroma_7",
            "chroma_8",
            "chroma_9",
            "chroma_10",
            "chroma_11",
            "chroma_12",
            "chroma_std",
        ]
    elif feat_set == "paa-hsf":
        feature_names = [
            "zcr-mean",
            "zcr-std",
            "energy-mean",
            "energy-std",
            "energy_entropy-mean",
            "energy_entropy-std",
            "spectral_centroid-mean",
            "spectral_centroid-std",
            "spectral_spread-mean",
            "spectral_spread-std",
            "spectral_entropy-mean",
            "spectral_entropy-std",
            "spectral_flux-mean",
            "spectral_flux-std",
            "spectral_rolloff-mean",
            "spectral_rolloff-std",
            "mfcc_1-mean",
            "mfcc_1-std",
            "mfcc_2-mean",
            "mfcc_2-std",
            "mfcc_3-mean",
            "mfcc_3-std",
            "mfcc_4-mean",
            "mfcc_4-std",
            "mfcc_5-mean",
            "mfcc_5-std",
            "mfcc_6-mean",
            "mfcc_6-std",
            "mfcc_7-mean",
            "mfcc_7-std",
            "mfcc_8-mean",
            "mfcc_8-std",
            "mfcc_9-mean",
            "mfcc_9-std",
            "mfcc_10-mean",
            "mfcc_10-std",
            "mfcc_11-mean",
            "mfcc_11-std",
            "mfcc_12-mean",
            "mfcc_12-std",
            "mfcc_13-mean",
            "mfcc_13-std",
            "chroma_1-mean",
            "chroma_1-std",
            "chroma_2-mean",
            "chroma_2-std",
            "chroma_3-mean",
            "chroma_3-std",
            "chroma_4-mean",
            "chroma_4-std",
            "chroma_5-mean",
            "chroma_5-std",
            "chroma_6-mean",
            "chroma_6-std",
            "chroma_7-mean",
            "chroma_7-std",
            "chroma_8-mean",
            "chroma_8-std",
            "chroma_9-mean",
            "chroma_9-std",
            "chroma_10-mean",
            "chroma_10-std",
            "chroma_11-mean",
            "chroma_11-std",
            "chroma_12-mean",
            "chroma_12-std",
            "chroma_std-mean",
            "chroma_std-std",
        ]
    elif feat_set == "egemaps-hsf":
        feature_names = [
            "Loudness_sma3-mean",
            "Loudness_sma3-std",
            "alphaRatio_sma3-mean",
            "alphaRatio_sma3-std",
            "hammarbergIndex_sma3-mean",
            "hammarbergIndex_sma3-std",
            "slope0-500_sma3-mean",
            "slope0-500_sma3-std",
            "slope500-1500_sma3-mean",
            "slope500-1500_sma3-std",
            "spectralFlux_sma3-mean",
            "spectralFlux_sma3-std",
            "mfcc1_sma3-mean",
            "mfcc1_sma3-std",
            "mfcc2_sma3-mean",
            "mfcc2_sma3-std",
            "mfcc3_sma3-mean",
            "mfcc3_sma3-std",
            "mfcc4_sma3-mean",
            "mfcc4_sma3-std",
            "F0semitoneFrom27.5Hz_sma3nz-mean",
            "F0semitoneFrom27.5Hz_sma3nz-std",
            "jitterLocal_sma3nz-mean",
            "jitterLocal_sma3nz-std",
            "shimmerLocaldB_sma3nz-mean",
            "shimmerLocaldB_sma3nz-std",
            "HNRdBACF_sma3nz-mean",
            "HNRdBACF_sma3nz-std",
            "logRelF0-H1-H2_sma3nz-mean",
            "logRelF0-H1-H2_sma3nz-std",
            "logRelF0-H1-A3_sma3nz-mean",
            "logRelF0-H1-A3_sma3nz-std",
            "F1frequency_sma3nz-mean",
            "F1frequency_sma3nz-std",
            "F1bandwidth_sma3nz-mean",
            "F1bandwidth_sma3nz-std",
            "F1amplitudeLogRelF0_sma3nz-mean",
            "F1amplitudeLogRelF0_sma3nz-std",
            "F2frequency_sma3nz-mean",
            "F2frequency_sma3nz-std",
            "F2bandwidth_sma3nz-mean",
            "F2bandwidth_sma3nz-std",
            "F2amplitudeLogRelF0_sma3nz-mean",
            "F2amplitudeLogRelF0_sma3nz-std",
            "F3frequency_sma3nz-mean",
            "F3frequency_sma3nz-std",
            "F3bandwidth_sma3nz-mean",
            "F3bandwidth_sma3nz-std",
            "F3amplitudeLogRelF0_sma3nz-mean",
            "F3amplitudeLogRelF0_sma3nz-std",
        ]
    elif feat_set == "egemaps-lld":
        feature_names = [
            "Loudness_sma3",
            "alphaRatio_sma3",
            "hammarbergIndex_sma3",
            "slope0-500_sma3",
            "slope500-1500_sma3",
            "spectralFlux_sma3",
            "mfcc1_sma3",
            "mfcc2_sma3",
            "mfcc3_sma3",
            "mfcc4_sma3",
            "F0semitoneFrom27.5Hz_sma3nz",
            "jitterLocal_sma3nz",
            "shimmerLocaldB_sma3nz",
            "HNRdBACF_sma3nz",
            "logRelF0-H1-H2_sma3nz",
            "logRelF0-H1-A3_sma3nz",
            "F1frequency_sma3nz",
            "F1bandwidth_sma3nz",
            "F1amplitudeLogRelF0_sma3nz",
            "F2frequency_sma3nz",
            "F2bandwidth_sma3nz",
            "F2amplitudeLogRelF0_sma3nz",
            "F3frequency_sma3nz",
            "F3bandwidth_sma3nz",
            "F3amplitudeLogRelF0_sma3nz",
        ]
    elif feat_set == "compare2016-lld":
        feature_names = [
            "F0final_sma",
            "voicingFinalUnclipped_sma",
            "jitterLocal_sma",
            "jitterDDP_sma",
            "shimmerLocal_sma",
            "logHNR_sma",
            "audspec_lengthL1norm_sma",
            "audspecRasta_lengthL1norm_sma",
            "pcm_RMSenergy_sma",
            "pcm_zcr_sma",
            "audSpec_Rfilt_sma[0]",
            "audSpec_Rfilt_sma[1]",
            "audSpec_Rfilt_sma[2]",
            "audSpec_Rfilt_sma[3]",
            "audSpec_Rfilt_sma[4]",
            "audSpec_Rfilt_sma[5]",
            "audSpec_Rfilt_sma[6]",
            "audSpec_Rfilt_sma[7]",
            "audSpec_Rfilt_sma[8]",
            "audSpec_Rfilt_sma[9]",
            "audSpec_Rfilt_sma[10]",
            "audSpec_Rfilt_sma[11]",
            "audSpec_Rfilt_sma[12]",
            "audSpec_Rfilt_sma[13]",
            "audSpec_Rfilt_sma[14]",
            "audSpec_Rfilt_sma[15]",
            "audSpec_Rfilt_sma[16]",
            "audSpec_Rfilt_sma[17]",
            "audSpec_Rfilt_sma[18]",
            "audSpec_Rfilt_sma[19]",
            "audSpec_Rfilt_sma[20]",
            "audSpec_Rfilt_sma[21]",
            "audSpec_Rfilt_sma[22]",
            "audSpec_Rfilt_sma[23]",
            "audSpec_Rfilt_sma[24]",
            "audSpec_Rfilt_sma[25]",
            "pcm_fftMag_fband250-650_sma",
            "pcm_fftMag_fband1000-4000_sma",
            "pcm_fftMag_spectralRollOff25.0_sma",
            "pcm_fftMag_spectralRollOff50.0_sma",
            "pcm_fftMag_spectralRollOff75.0_sma",
            "pcm_fftMag_spectralRollOff90.0_sma",
            "pcm_fftMag_spectralFlux_sma",
            "pcm_fftMag_spectralCentroid_sma",
            "pcm_fftMag_spectralEntropy_sma",
            "pcm_fftMag_spectralVariance_sma",
            "pcm_fftMag_spectralSkewness_sma",
            "pcm_fftMag_spectralKurtosis_sma",
            "pcm_fftMag_spectralSlope_sma",
            "pcm_fftMag_psySharpness_sma",
            "pcm_fftMag_spectralHarmonicity_sma",
            "mfcc_sma[1]",
            "mfcc_sma[2]",
            "mfcc_sma[3]",
            "mfcc_sma[4]",
            "mfcc_sma[5]",
            "mfcc_sma[6]",
            "mfcc_sma[7]",
            "mfcc_sma[8]",
            "mfcc_sma[9]",
            "mfcc_sma[10]",
            "mfcc_sma[11]",
            "mfcc_sma[12]",
            "mfcc_sma[13]",
            "mfcc_sma[14]",
        ]

    elif feat_set == "compare2016-hsf":
        feature_names = [
            "F0final_sma-mean",
            "F0final_sma-std",
            "voicingFinalUnclipped_sma-mean",
            "voicingFinalUnclipped_sma-std",
            "jitterLocal_sma-mean",
            "jitterLocal_sma-std",
            "jitterDDP_sma-mean",
            "jitterDDP_sma-std",
            "shimmerLocal_sma-mean",
            "shimmerLocal_sma-std",
            "logHNR_sma-mean",
            "logHNR_sma-std",
            "audspec_lengthL1norm_sma-mean",
            "audspec_lengthL1norm_sma-std",
            "audspecRasta_lengthL1norm_sma-mean",
            "audspecRasta_lengthL1norm_sma-std",
            "pcm_RMSenergy_sma-mean",
            "pcm_RMSenergy_sma-std",
            "pcm_zcr_sma-mean",
            "pcm_zcr_sma-std",
            "audSpec_Rfilt_sma[0]-mean",
            "audSpec_Rfilt_sma[0]-std",
            "audSpec_Rfilt_sma[1]-mean",
            "audSpec_Rfilt_sma[1]-std",
            "audSpec_Rfilt_sma[2]-mean",
            "audSpec_Rfilt_sma[2]-std",
            "audSpec_Rfilt_sma[3]-mean",
            "audSpec_Rfilt_sma[3]-std",
            "audSpec_Rfilt_sma[4]-mean",
            "audSpec_Rfilt_sma[4]-std",
            "audSpec_Rfilt_sma[5]-mean",
            "audSpec_Rfilt_sma[5]-std",
            "audSpec_Rfilt_sma[6]-mean",
            "audSpec_Rfilt_sma[6]-std",
            "audSpec_Rfilt_sma[7]-mean",
            "audSpec_Rfilt_sma[7]-std",
            "audSpec_Rfilt_sma[8]-mean",
            "audSpec_Rfilt_sma[8]-std",
            "audSpec_Rfilt_sma[9]-mean",
            "audSpec_Rfilt_sma[9]-std",
            "audSpec_Rfilt_sma[10]-mean",
            "audSpec_Rfilt_sma[10]-std",
            "audSpec_Rfilt_sma[11]-mean",
            "audSpec_Rfilt_sma[11]-std",
            "audSpec_Rfilt_sma[12]-mean",
            "audSpec_Rfilt_sma[12]-std",
            "audSpec_Rfilt_sma[13]-mean",
            "audSpec_Rfilt_sma[13]-std",
            "audSpec_Rfilt_sma[14]-mean",
            "audSpec_Rfilt_sma[14]-std",
            "audSpec_Rfilt_sma[15]-mean",
            "audSpec_Rfilt_sma[15]-std",
            "audSpec_Rfilt_sma[16]-mean",
            "audSpec_Rfilt_sma[16]-std",
            "audSpec_Rfilt_sma[17]-mean",
            "audSpec_Rfilt_sma[17]-std",
            "audSpec_Rfilt_sma[18]-mean",
            "audSpec_Rfilt_sma[18]-std",
            "audSpec_Rfilt_sma[19]-mean",
            "audSpec_Rfilt_sma[19]-std",
            "audSpec_Rfilt_sma[20]-mean",
            "audSpec_Rfilt_sma[20]-std",
            "audSpec_Rfilt_sma[21]-mean",
            "audSpec_Rfilt_sma[21]-std",
            "audSpec_Rfilt_sma[22]-mean",
            "audSpec_Rfilt_sma[22]-std",
            "audSpec_Rfilt_sma[23]-mean",
            "audSpec_Rfilt_sma[23]-std",
            "audSpec_Rfilt_sma[24]-mean",
            "audSpec_Rfilt_sma[24]-std",
            "audSpec_Rfilt_sma[25]-mean",
            "audSpec_Rfilt_sma[25]-std",
            "pcm_fftMag_fband250-650_sma-mean",
            "pcm_fftMag_fband250-650_sma-std",
            "pcm_fftMag_fband1000-4000_sma-mean",
            "pcm_fftMag_fband1000-4000_sma-std",
            "pcm_fftMag_spectralRollOff25.0_sma-mean",
            "pcm_fftMag_spectralRollOff25.0_sma-std",
            "pcm_fftMag_spectralRollOff50.0_sma-mean",
            "pcm_fftMag_spectralRollOff50.0_sma-std",
            "pcm_fftMag_spectralRollOff75.0_sma-mean",
            "pcm_fftMag_spectralRollOff75.0_sma-std",
            "pcm_fftMag_spectralRollOff90.0_sma-mean",
            "pcm_fftMag_spectralRollOff90.0_sma-std",
            "pcm_fftMag_spectralFlux_sma-mean",
            "pcm_fftMag_spectralFlux_sma-std",
            "pcm_fftMag_spectralCentroid_sma-mean",
            "pcm_fftMag_spectralCentroid_sma-std",
            "pcm_fftMag_spectralEntropy_sma-mean",
            "pcm_fftMag_spectralEntropy_sma-std",
            "pcm_fftMag_spectralVariance_sma-mean",
            "pcm_fftMag_spectralVariance_sma-std",
            "pcm_fftMag_spectralSkewness_sma-mean",
            "pcm_fftMag_spectralSkewness_sma-std",
            "pcm_fftMag_spectralKurtosis_sma-mean",
            "pcm_fftMag_spectralKurtosis_sma-std",
            "pcm_fftMag_spectralSlope_sma-mean",
            "pcm_fftMag_spectralSlope_sma-std",
            "pcm_fftMag_psySharpness_sma-mean",
            "pcm_fftMag_psySharpness_sma-std",
            "pcm_fftMag_spectralHarmonicity_sma-mean",
            "pcm_fftMag_spectralHarmonicity_sma-std",
            "mfcc_sma[1]-mean",
            "mfcc_sma[1]-std",
            "mfcc_sma[2]-mean",
            "mfcc_sma[2]-std",
            "mfcc_sma[3]-mean",
            "mfcc_sma[3]-std",
            "mfcc_sma[4]-mean",
            "mfcc_sma[4]-std",
            "mfcc_sma[5]-mean",
            "mfcc_sma[5]-std",
            "mfcc_sma[6]-mean",
            "mfcc_sma[6]-std",
            "mfcc_sma[7]-mean",
            "mfcc_sma[7]-std",
            "mfcc_sma[8]-mean",
            "mfcc_sma[8]-std",
            "mfcc_sma[9]-mean",
            "mfcc_sma[9]-std",
            "mfcc_sma[10]-mean",
            "mfcc_sma[10]-std",
            "mfcc_sma[11]-mean",
            "mfcc_sma[11]-std",
            "mfcc_sma[12]-mean",
            "mfcc_sma[12]-std",
            "mfcc_sma[13]-mean",
            "mfcc_sma[13]-std",
            "mfcc_sma[14]-mean",
            "mfcc_sma[14]-std",
        ]

    features_df = pd.DataFrame(columns=feature_names)

    path = f"/Users/martin/Documents/UNIVERSIDAD/CLASES/4º/2o Cuatri/TFG/code/data/{dataset}"
    with open(f"{path}/metadata.csv") as metadata_f:
        csv_reader = csv.reader(metadata_f, delimiter=",")
        line_count = 0
        for row in csv_reader:
            print(line_count)
            if line_count > 0:
                if dataset == "iemocap":
                    path_to_wav = get_path(row[0])
                elif dataset == "msp":
                    path_to_wav = f"{path}/Audios/{row[0]}.wav"

                if feat_set == "paa-lld":
                    features = extract_paa_lld(path_to_wav)
                elif feat_set == "paa-hsf":
                    features = extract_paa_hsf(path_to_wav)
                elif feat_set == "egemaps-hsf":
                    features = extract_egemaps_hsf(path_to_wav)
                elif feat_set == "egemaps-lld":
                    features = extract_egemaps_lld(path_to_wav)
                elif feat_set == "compare2016-lld":
                    features = extract_compare_lld(path_to_wav)
                elif feat_set == "compare2016-hsf":
                    features = extract_compare_hsf(path_to_wav)
                features_df = features_df.append(features, ignore_index=True)
            line_count += 1
    features_npy = features_df.to_numpy()
    np.save(f"{path}/npy/{feat_set}.npy", features_npy)

