From f9434a3b66d7f6a83948e722cc15754dccfdc278 Mon Sep 17 00:00:00 2001 From: Skudalen Date: Fri, 2 Jul 2021 10:58:17 +0200 Subject: [PATCH] chore: add the librosa lib --- Handle_emg_data.py | 21 +++++++++++++-------- Present_data.py | 6 ++---- __pycache__/Handle_emg_data.cpython-36.pyc | Bin 0 -> 26164 bytes __pycache__/Handle_emg_data.cpython-38.pyc | Bin 24348 -> 25134 bytes __pycache__/Signal_prep.cpython-36.pyc | Bin 0 -> 1755 bytes 5 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 __pycache__/Handle_emg_data.cpython-36.pyc create mode 100644 __pycache__/Signal_prep.cpython-36.pyc diff --git a/Handle_emg_data.py b/Handle_emg_data.py index 55898bc..77e03bb 100644 --- a/Handle_emg_data.py +++ b/Handle_emg_data.py @@ -7,8 +7,9 @@ from pandas.core.frame import DataFrame from math import floor import sys sys.path.insert(0, '/Users/Markus/Prosjekter git/Slovakia 2021/python_speech_features/python_speech_features') -from python_speech_features.python_speech_features import * +from python_speech_features.python_speech_features import mfcc import json +import librosa #from Present_data import get_data # Global variables for MFCC @@ -585,8 +586,8 @@ class DL_data_handler: main_df = pd.concat([main_df, adding_df], ignore_index=True) samplerate = get_samplerate(main_df) return main_df, samplerate - ''' - def save_mfcc(raw_data_dict, json_path, samples_per_subject): + + def save_mfcc(self, json_path=JSON_PATH): # dictionary to store mapping, labels, and MFCCs data = { @@ -597,13 +598,14 @@ class DL_data_handler: #hop_length = MFCC_STEPSIZE * sample_rate #num_mfcc_vectors_per_segment = math.ceil(samples_per_subject / hop_length) - + raw_data_dict = self.get_samples_dict() + # loop through all subjects to get samples for key, value in raw_data_dict.items(): # save genre label (i.e., sub-folder name) in the mapping - subject_label = 'Subject ' + key + subject_label = 'Subject ' + str(key) data["mapping"].append(subject_label) print("\nProcessing: {}".format(subject_label)) @@ -612,9 +614,12 @@ class DL_data_handler: # load audio file signal, sample_rate = sample[0], sample[1] + n_fft = MFCC_WINDOWSIZE * sample_rate + hop_length = MFCC_STEPSIZE * sample_rate # extract mfcc - mfcc = mfcc_custom(signal, sample_rate, MFCC_WINDOWSIZE, MFCC_STEPSIZE, NR_COEFFICIENTS, NR_MEL_BINS) + mfcc = librosa.feature.mfcc(signal, sample_rate, n_mfcc=NR_COEFFICIENTS, n_fft=n_fft, hop_length=hop_length) + #mfcc = mfcc_custom(signal, sample_rate, MFCC_WINDOWSIZE, MFCC_STEPSIZE, NR_COEFFICIENTS, NR_MEL_BINS) mfcc = mfcc.T print(len(mfcc)) @@ -627,7 +632,7 @@ class DL_data_handler: # save MFCCs to json file with open(json_path, "w") as fp: json.dump(data, fp, indent=4) - ''' + # HELP FUNCTIONS: ------------------------------------------------------------------------: @@ -676,4 +681,4 @@ def mfcc_custom(df:DataFrame, samplesize, windowsize=MFCC_WINDOWSIZE, nr_mel_filters=NR_MEL_BINS): N = get_xory_from_df('x', df) y = get_xory_from_df('y', df) - return N, base.mfcc(y, samplesize, windowsize, stepsize, nr_coefficients, nr_mel_filters) \ No newline at end of file + return N, mfcc(y, samplesize, windowsize, stepsize, nr_coefficients, nr_mel_filters) \ No newline at end of file diff --git a/Present_data.py b/Present_data.py index 45ffb07..81b8922 100644 --- a/Present_data.py +++ b/Present_data.py @@ -222,13 +222,11 @@ def main(): csv_handler = CSV_handler() csv_handler.load_data('soft') dl_data_handler = DL_data_handler(csv_handler) - mfcc_3_plots_1_1_2(csv_handler) - - ''' dl_data_handler.store_samples(10) dict = dl_data_handler.samples_per_subject + print(len(dict.get(2))) dl_data_handler.save_mfcc() - ''' + main() \ No newline at end of file diff --git a/__pycache__/Handle_emg_data.cpython-36.pyc b/__pycache__/Handle_emg_data.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b51c30f0239c8f1101910c829f45abc496e3c4e GIT binary patch literal 26164 zcmeHQYi!)ub>?ekI1i0vNtWfe*6V#}*DFi1z3X+nyWZGx>|}S=v7I=bCS}ID9BHJ{ zjC@J2WrfU3+aPVa%{EPg0NtQ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