-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (52 loc) · 1.83 KB
/
main.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
from FeatureExtraction import preemphasize_signal
from FeatureExtraction import extract_mfcc
from InputPreparation import get_audiofilenames
import pandas as pd
import csv
def main(path_to_audiofiles, feature_file_path, DT_pic_name):
"""
Main function which runs through audio files in path_to_audiofiles.
Steps:
1. Pre-emphasis applied on the audio files
2. Compute features (MFCC, MFCC delta etc)
3. Save features to a file
4. Run desicion tree code
"""
audiofiles = get_audiofilenames(path_to_audiofiles)
print("test df ")
df = pd.DataFrame()
mfcc_list = df.values.tolist()
print(" number of rows in the dataframe ")
print(len(df.index))
df.to_csv(feature_file_path)
i = 0
for audiofile in audiofiles:
print(path_to_audiofiles+audiofile)
audio_signal, sample_rate = preemphasize_signal(path_to_audiofiles+audiofile)
mfcc, energy, mfccD, energyD = extract_mfcc(audio_signal, sample_rate)
#print(mfcc)
fields = []
#for mfcc_coef_row in mfcc:
#for mfcc_coef in mfcc_coef_row:
#fields.append(mfcc_coef)
mfcc_coef_row = mfcc[0]
for mfcc_coef in mfcc_coef_row:
fields.append(mfcc_coef)
print("length of fields ")
print(len(fields))
print(fields)
i += 1
with open(r'Data/test.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow(fields)
#for coef_row in mfcc:
# mfcc_list.append(coef_row)
# print("test mfcc list ")
#print(mfcc_list)
print("DONE")
print("number of iterations :" + str(i))
df = pd.read_csv("Data/test.csv", error_bad_lines=False)
print(df)
print(len(df.index))
print("DONE DONE")
main("Data/all_p_no_silence/","Data/test.csv", "DT_pic.png")