-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatenp.py
More file actions
32 lines (26 loc) · 933 Bytes
/
createnp.py
File metadata and controls
32 lines (26 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
import librosa
import os
DATA_PATH = "./train/audio"
def wav2mfcc(file_path, max_pad_len=11):
wave, sr = librosa.load(file_path, mono=True, sr=None)
wave = wave[::3]
mfcc = librosa.feature.mfcc(wave, sr=16000)
pad_width = max_pad_len - mfcc.shape[1]
mfcc = np.pad(mfcc, pad_width=((0, 0), (0, pad_width)), mode='constant')
return mfcc
def preprocessing_data(path=DATA_PATH, max_pad_len=11):
try:
s_data = [data for data in os.listdir(path)]
except:
print("error in fetching labels list")
sys.exit()
for data in s_data:
mfcc_vectors = []
filepath = DATA_PATH + '/' + data
for allfiles in os.listdir(filepath):
mfcc = wav2mfcc(filepath+ '/' +allfiles)
mfcc_vectors.append(mfcc)
np.save("data_np" + '/' + data + '.npy', mfcc_vectors)
print(data + ".npy filesaved")
preprocessing_data()