This repository has been 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
/
csv_files_times.py
97 lines (73 loc) · 3.92 KB
/
csv_files_times.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
import pandas as pd
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import os
targetPath = os.path.abspath("../csv")
np.set_printoptions(threshold=np.inf)
mfccFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_mfcc.csv"))]
del1Files = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_del1.csv"))]
del2Files = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_del2.csv"))]
entropyFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_entropy.csv"))]
rmsFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_rms.csv"))]
zeroCrossingFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_zeroCrossing.csv"))]
powerFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if name.endswith(("_powerSpectrum.csv"))]
def printTimes(startIndex, endIndex, jump, localFile, writeToFile):
mfcc = np.nan_to_num(np.array(pd.read_csv(localFile + '_mfcc.csv', header=None), dtype='float64'))
power = np.nan_to_num(np.array(pd.read_csv(localFile + '_powerSpectrum.csv', header=None), dtype='float64'))
count = 0
for i in range(len(mfcc)):
# print(startIndex, "ms ->", endIndex, "ms Mean Mfcc:", np.mean(mfcc[i]), "Mean Power:", np.mean(power[i]))
print(startIndex, endIndex, file = writeToFile)
startIndex += jump
endIndex += jump
count += 1
return
def powerEntropyMfccZC(localFile):
# print("Power file: " + str(powerFile.split("/")[-1]) + " Entropy file: " + str(entropyFile.split("/")[-1]))
power = np.nan_to_num(np.array(pd.read_csv(localFile + '_powerSpectrum.csv', header=None), dtype='float64'))
entropy = np.nan_to_num(np.array(pd.read_csv(localFile + '_entropy.csv', header=None), dtype='float64'))
mfcc = np.nan_to_num(np.array(pd.read_csv(localFile + '_mfcc.csv', header=None), dtype='float64'))
zeroCrossing = np.nan_to_num(np.array(pd.read_csv(localFile + '_zeroCrossing.csv', header=None), dtype='float64'))
if power.shape[0] != entropy.shape[1]:
print("Number of frames in power array is not equal to number of entropy values in entropy array.")
return
if (power.shape[0] != mfcc.shape[0]):
print("Number of frames in power array is not equal to number of frames in mfcc array.")
return
avgPowerOfFrames = []
avgPowerOfFrames = np.array(np.append(avgPowerOfFrames, np.mean(power, axis=1)))
entropy = np.reshape(entropy, entropy.shape[1])
ratioOfMfccs = []
for frame in mfcc:
avg1 = sum(frame[0:3]) / 3
avg2 = sum(frame[10:13]) / 3
ratioOfMfccs = np.append(ratioOfMfccs, avg1 / avg2)
ratioOfMfccs = np.nan_to_num(ratioOfMfccs)
zeroCrossing = np.reshape(zeroCrossing, zeroCrossing.shape[1])
# print("avgPowerOfFrames: ", str(avgPowerOfFrames.shape), " entropy: ", str(entropy.shape))
return avgPowerOfFrames, entropy, ratioOfMfccs, zeroCrossing
def main():
menNames = np.ravel(np.array(pd.read_csv('Docs/filenames/men_filenames.csv', header = None, dtype = str)))
# print(menNames)
for localFileName in menNames:
# if(localFileName.split('/')[-1][0] > 'k' or localFileName.split('/')[-1][0] > 'K'):
localFile = open('25ms_times/' + localFileName.split('/')[-1] + '_times.csv', 'w')
print(localFileName.split('/')[-1], file = localFile)
printTimes(0, 25, 15, localFileName, localFile)
if __name__ == '__main__':
main()