-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_data.py
137 lines (107 loc) · 3.46 KB
/
import_data.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from filehash import filehash
from shutil import copyfile
import os
# FileFormat: {Emotion}-{Gender}-{Language}-{Hash}.{wav|mp3}
# Example: 04-F-EN-91d50642dd930e9542c39d36f0516d45f4e1af0d.wav
target_dir = os.path.abspath('./data/train')
emotion_dict = {
'Neutral': '01',
'Calm': '02',
'Happy': '03',
'Sad': '04',
'Angry': '05',
'Fearful': '06',
'Disgust': '07',
'Surprised': '08'
}
language_dict = {
'English': 'EN',
'German': 'DE'
}
gender_dict = {
'Male': 'M',
'Female': 'F'
}
def get_files_recursive(dir_name, files=[]):
dir_name = os.path.abspath(dir_name)
dir_content = os.listdir(dir_name)
for file_name in dir_content:
file_path = os.path.join(dir_name, file_name)
if (os.path.isdir(file_path)):
files = get_files_recursive(file_path, files)
else:
files.append(file_path)
return files
def rename_german_data():
dir_path = os.path.abspath('./data/german')
german_emotions = {
'W': 'Angry',
'L': 'Calm',
'E': 'Disgust',
'A': 'Fearful',
'F': 'Happy',
'T': 'Sad',
'N': 'Neutral'
}
german_genders = {
'03': 'M',
'08': 'F',
'09': 'F',
'10': 'M',
'11': 'M',
'12': 'M',
'13': 'F',
'14': 'F',
'15': 'M',
'16': 'F'
}
for file_path in get_files_recursive(dir_path):
file_name = os.path.basename(file_path)
if file_name.endswith('.wav'):
emotion = emotion_dict[german_emotions[file_name[5:6]]]
actor_no = file_name[0:2]
gender = german_genders[actor_no]
file_hash = filehash(file_path)
dst_file_name = emotion + '-' + gender + '-' + 'DE' + '-' + file_hash + '.wav'
dst_path = os.path.join(target_dir, dst_file_name)
copyfile(file_path, dst_path)
def rename_toronto_data():
dir_path = os.path.abspath('./data/toronto_university')
toronto_emotion_dict = {
'neutral': '01',
'Calm': '02',
'happy': '03',
'sad': '04',
'angry': '05',
'fear': '06',
'disgust': '07',
'ps': '08'
}
for file_path in get_files_recursive(dir_path):
file_name = os.path.basename(file_path)
if file_name.endswith('.wav'):
file_name_parts = file_name.replace('.wav', '').split('_')
gender = 'N'
emotion = toronto_emotion_dict[file_name_parts[2]]
# print(emotion)
file_hash = filehash(file_path)
dst_file_name = emotion + '-' + gender + '-' + 'EN' + '-' + file_hash + '.wav'
dst_path = os.path.join(target_dir, dst_file_name)
copyfile(file_path, dst_path)
def rename_engie_data():
dir_path = os.path.abspath('./data/engie')
for file_path in get_files_recursive(dir_path):
file_name = os.path.basename(file_path)
if file_name.endswith('.wav'):
file_name_parts = file_name.replace('.wav', '').split('-')
gender = 'F'
if (int(file_name_parts[6]) % 2 > 0):
gender = 'M'
emotion = file_name_parts[2]
file_hash = filehash(file_path)
dst_file_name = emotion + '-' + gender + '-' + 'EN' + '-' + file_hash + '.wav'
dst_path = os.path.join(target_dir, dst_file_name)
copyfile(file_path, dst_path)
# rename_german_data()
# rename_engie_data()
rename_toronto_data()