Skip to content

Instantly share code, notes, and snippets.

@vinay-hebb
Forked from manashmandal/get_labels.py
Created October 18, 2018 15:13
Show Gist options
  • Save vinay-hebb/7a49794b19fdac07b96db1fa2b474761 to your computer and use it in GitHub Desktop.
Save vinay-hebb/7a49794b19fdac07b96db1fa2b474761 to your computer and use it in GitHub Desktop.
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)
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