-
Notifications
You must be signed in to change notification settings - Fork 2
/
read_iitkgp.py
116 lines (110 loc) · 3.32 KB
/
read_iitkgp.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import numpy as np
import scipy.io.wavfile as wav
import os
import scipy.stats
import _pickle as cPickle
from python_speech_features import mfcc,delta,ssc
numfeatper=7
mfc=13
dell=13
sscc=26
filtt=13
def featurex(filepath):
# print(filepath)
(rate,X) = wav.read(filepath)
ceps = mfcc(X,rate)
delt=delta(ceps,2)
sscz=ssc(X,rate)
filt=delta(delt,2)
ls = []
for i in range(ceps.shape[1]):
temp = ceps[:,i]
lfeatures = [np.mean(temp), np.var(temp), np.amax(temp), np.amin(temp),scipy.stats.kurtosis(temp), scipy.stats.skew(temp),scipy.stats.iqr(temp)]
temp2 = np.array(lfeatures)
ls.append(temp2)
ls2=[]
for i in range(delt.shape[1]):
dtemp = delt[:,i]
dlfeatures = [np.mean(dtemp), np.var(dtemp), np.amax(dtemp), np.amin(dtemp),scipy.stats.kurtosis(dtemp), scipy.stats.skew(dtemp),scipy.stats.iqr(dtemp)]
dtemp2 = np.array(dlfeatures)
ls2.append(dtemp2)
ls3=[]
for i in range(sscz.shape[1]):
stemp = sscz[:,i]
slfeatures = [np.mean(stemp), np.var(stemp), np.amax(stemp), np.amin(stemp),scipy.stats.kurtosis(stemp), scipy.stats.skew(stemp),scipy.stats.iqr(stemp)]
stemp3 = np.array(slfeatures)
ls3.append(stemp3)
ls4=[]
for i in range(filt.shape[1]):
ftemp=filt[:,i]
flfeatures=[np.mean(ftemp), np.var(ftemp), np.amax(ftemp), np.amin(ftemp),scipy.stats.kurtosis(ftemp), scipy.stats.skew(ftemp),scipy.stats.iqr(ftemp)]
ftemp4 = np.array(flfeatures)
ls4.append(ftemp4)
source = np.array(ls).flatten()
source = np.append(source, np.array(ls2).flatten())
source = np.append(source, np.array(ls3).flatten())
source = np.append(source, np.array(ls4).flatten())
return source
def read_iitkgp(img_cols=(mfc+sscc+dell+filtt)*numfeatper):
num = 10015
solns=['A','D','F','H','N','S','SU']
data=np.empty(shape=(num, img_cols))
print(data.shape)
label = []
i=0
rootdir = "F:/Sorted Database/anger/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(1)
i=i+1
rootdir = "F:/Sorted Database/disgust/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(2)
i=i+1
rootdir = "F:/Sorted Database/fear/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(3)
i=i+1
rootdir = "F:/Sorted Database/happy/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(4)
i=i+1
rootdir = "F:/Sorted Database/neutral/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(5)
i=i+1
rootdir = "F:/Sorted Database/sadness/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(6)
i=i+1
rootdir = "F:/Sorted Database/surprise/"
for filename in os.listdir(rootdir):
name = "".join(filename)
full_name = rootdir+name
data[i]=featurex(full_name)
label.append(7)
i=i+1
label=np.array(label)
f = open('D:/IIITD/iitkgp.pkl', 'wb')
cPickle.dump((data, label), f)
print(data.shape)
print(label.shape)
f.close()
read_iitkgp()