-
-
Save vinay-hebb/7a49794b19fdac07b96db1fa2b474761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import os | |
DATA_PATH = "./data/" | |
# Input: Folder Path | |
# Output: Tuple (Label, Indices of the labels, one-hot encoded labels) | |
def get_labels(path=DATA_PATH): | |
labels = os.listdir(path) | |
label_indices = np.arange(0, len(labels)) | |
return labels, label_indices, to_categorical(label_indices) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def save_data_to_array(path=DATA_PATH, max_pad_len=11): | |
labels, _, _ = get_labels(path) | |
for label in labels: | |
# Init mfcc vectors | |
mfcc_vectors = [] | |
wavfiles = [path + label + '/' + wavfile for wavfile in os.listdir(path + '/' + label)] | |
for wavfile in wavfiles: | |
mfcc = wav2mfcc(wavfile, max_pad_len=max_pad_len) | |
mfcc_vectors.append(mfcc) | |
np.save(label + '.npy', mfcc_vectors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment