This repository was archived by the owner on Oct 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFilenamesAndFilter.py
64 lines (48 loc) · 2 KB
/
getFilenamesAndFilter.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
import pandas as pd
import numpy as np
import os
from scipy import stats
from subprocess import call
np.set_printoptions(threshold=np.inf)
def print_features(localFile):
mfcc = np.nan_to_num(np.array(pd.read_csv(localFile + '_mfcc.csv', header=None), dtype='float64'))
avgOfMfcc = np.mean(mfcc, axis = 0)
for tempMfcc in mfcc:
for i in range(len(tempMfcc)):
tempMfcc[i] = (tempMfcc[i] - avgOfMfcc[i])
return np.mean(mfcc)
def find_zscr(names, means):
zscr = stats.zscore(means)
return dict(zip(names, zscr))
def filterFiles(folderPath, printToFileName):
avgs = {}
for path, directories, filenames in os.walk(folderPath):
for filename in filenames:
if ".wav" in filename and ".csv" not in filename:
if "angry" in filename or "neutral" in filename or "sad" in filename:
localFileName = os.path.join(path, filename)
localFileName = localFileName.replace("/sounds/", "/csv/")
avgs[localFileName] = print_features(localFileName)
means = np.array(list(avgs.values()))
names = np.array(list(avgs.keys()))
scores = find_zscr(names, means)
for s in scores:
printToFile = open(printToFileName, "a+")
if scores[s] > 3 or scores[s] < -3:
ns = "#" + s
print (ns, file = printToFile)
else:
print (s, file = printToFile)
def main():
printToFileNameMen = "Docs/filenames/men_filenames.csv"
printToFileNameWomen = "Docs/filenames/women_filenames.csv"
if os.path.isfile(printToFileNameMen):
os.remove(printToFileNameMen)
if os.path.isfile(printToFileNameWomen):
os.remove(printToFileNameWomen)
filterFiles('../sounds/Men/', printToFileNameMen)
filterFiles('../sounds/Women/', printToFileNameWomen)
call(["sort", printToFileNameMen, "-o", printToFileNameMen])
call(["sort", printToFileNameWomen, "-o", printToFileNameWomen])
if __name__ == '__main__':
main()