forked from tugstugi/pytorch-dc-tts
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprocess_emovdb.py
93 lines (68 loc) · 2.41 KB
/
process_emovdb.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
import os
import shutil
import string
import re
PATH = "./emovdb/"
emotions = {}
speakers = os.listdir(PATH)
for speaker in speakers:
speaker_path = PATH+speaker+"/"
print(speaker_path)
speaker_emotions = os.listdir(speaker_path)
for emotion in speaker_emotions:
if emotion not in emotions:
emotions[emotion] = []
emotions[emotion].append(speaker_path+emotion)
PROCESSED_DIR = './processed_emovdb_disgust'
if os.path.isdir(PROCESSED_DIR) == False:
os.mkdir(PROCESSED_DIR)
os.mkdir(PROCESSED_DIR+'/wavs')
TRANSCRIPT_PATH = './cmuarctic.data'
def remove_punct(string):
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
for x in string.lower():
if x in punctuations:
string = string.replace(x, "")
return string.lower()
def process_transcript(transcript):
with open(transcript, 'r') as f:
lines = f.readlines()
label_to_transcript = {}
for line in lines:
line = line.split('"')
sent = line[1]
label = line[0].rstrip().split('_')[-1]
if label[0] == 'b':
continue
label = label[1:]
label_to_transcript[label] = remove_punct(sent)
return label_to_transcript
label_to_transcript = process_transcript(TRANSCRIPT_PATH)
list_transcript_files = []
for emotion in emotions.keys():
# Remove this to preprocess on all emotions
if emotion != 'disgust':
continue
emotion_paths = emotions[emotion]
count_emotion = 0
for path in emotion_paths:
audios = os.listdir(path)
speaker = path.split('/')[-2]
for audio in audios:
#print('-------------------------')
#print(audio)
label = audio.split('_')[-1].split('.')[0]
#print(label)
label_name = emotion+"_"+str(count_emotion)+"_"+speaker+"_"+label
#print(label_name)
count_emotion += 1
try:
list_transcript_files.append(label_name+"|"+label_to_transcript[label])
shutil.copyfile(path+'/'+audio,PROCESSED_DIR+'/wavs/'+label_name+".wav")
except:
print('Failed for file - ', path+'/'+audio)
print('Done emotion - ', emotion)
print('Count - ', count_emotion)
with open(PROCESSED_DIR+"/transcript.csv","w+") as f:
f.write("\n".join(list_transcript_files))
print('File Writing Done')