-
Notifications
You must be signed in to change notification settings - Fork 3
/
script4.py
44 lines (32 loc) · 1.1 KB
/
script4.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
from python_speech_features import mfcc
from python_speech_features import delta
from python_speech_features import logfbank
import scipy.io.wavfile as wav
import os
import numpy as np
directory = "/home/saurabh/AudioClassifier/genres/"
window = np.append(np.array([0]),np.hamming(441))
features_list =[]
class_list = []
def hm( n ):
return window[n]
def crawler1 ( directory ) :
for folder in os.listdir(directory) :
print folder
crawler2(directory+folder+"/")
def crawler2 ( directory ) :
#print directory
for folder in next(os.walk(directory))[1]:
print "_",folder
class_list.append(folder)
for file in os.listdir(directory+folder) :
print file,
(rate,sig) = wav.read(directory+folder+"/"+file)
mfcc_feat = mfcc(sig,rate ,winlen=0.020,winfunc=hm)
print len(sig),rate,len(mfcc_feat), len(mfcc_feat[0])
features_list.append(mfcc_feat)
#os.system(("sox "+directory+filename+" -e signed-integer "+directory+"wav/"+filename[:-3]+".wav"))
if __name__ == "__main__":
crawler1(directory)
print len(features_list),len(features_list[0]),len(features_list[0][0])
print features_list[0]