-
Notifications
You must be signed in to change notification settings - Fork 2
/
pickle_generator.py
180 lines (144 loc) · 5.94 KB
/
pickle_generator.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
import json
import pickle
data_path = "data/"
speech_path = "data/LibriSpeech-wav/test-clean/"
AV_path = "synthetic_dataset/v16/test/"
pickle_name ="test.pickle"
folder_list = os.listdir(data_path+AV_path)
unique_id = 0
path_list=[]
for folders in folder_list:
folder_path = data_path + AV_path + folders +"/"
json_path = folder_path+"cleaned_metadata_v3.json"
f = open(json_path)
data = json.load(f)
len_data = len(data)
for i in range(len_data):
# print("i ",i," len data",len_data)
full_dict = data[i]
speakers = full_dict['speakers']
num_speakers=len(speakers)
for j in range(num_speakers):
speaker_id = str(speakers[j]['id']) #needed
speaker_location = speakers[j]['location'] #needed
speaker_gender = speakers[j]['gender'] #needed
speaker_speech = speakers[j]['speech']
split_speech = speaker_speech.split("-")
full_clean_speech_path = speech_path + split_speech[0] + "/" + split_speech[1] + "/" + speaker_speech +".wav" #needed
view_points = full_dict['viewpoints']
num_view_points = len(view_points)
unique_id = unique_id+1
for k in range(num_view_points):
view_location = view_points[k]['location'] #needed
view_image = view_points[k]['image']
mono_rir_path = view_points[k]['mono_rir'][speaker_id]
full_mono_rir_path = mono_rir_path
full_reverb_speech_path = full_mono_rir_path.replace(".wav","_reverb_speech.wav") #needed
dict_data={}
dict_data['unique_id'] = unique_id
dict_data['speaker_id'] = speaker_id
dict_data['speaker_location'] = speaker_location
dict_data['speaker_gender'] = speaker_gender
dict_data['clean_speech_path'] = full_clean_speech_path
dict_data['view_location'] = view_location
dict_data['view_image'] = view_image
dict_data['mono_rir_path'] = full_mono_rir_path
dict_data['reverb_speech_path'] = full_reverb_speech_path
path_list.append(dict_data)
with open(pickle_name, 'wb') as f:
pickle.dump(path_list, f, protocol=2)
data_path = "data/"
speech_path = "data/LibriSpeech-wav/train-clean-360/"
AV_path = "synthetic_dataset/v16/train/"
pickle_name ="train.pickle"
folder_list = os.listdir(data_path+AV_path)
unique_id = 0
path_list=[]
for folders in folder_list:
folder_path = data_path + AV_path + folders +"/"
json_path = folder_path+"cleaned_metadata_v3.json"
f = open(json_path)
data = json.load(f)
len_data = len(data)
for i in range(len_data):
# print("i ",i," len data",len_data)
full_dict = data[i]
speakers = full_dict['speakers']
num_speakers=len(speakers)
for j in range(num_speakers):
speaker_id = str(speakers[j]['id']) #needed
speaker_location = speakers[j]['location'] #needed
speaker_gender = speakers[j]['gender'] #needed
speaker_speech = speakers[j]['speech']
split_speech = speaker_speech.split("-")
full_clean_speech_path = speech_path + split_speech[0] + "/" + split_speech[1] + "/" + speaker_speech +".wav" #needed
view_points = full_dict['viewpoints']
num_view_points = len(view_points)
unique_id = unique_id+1
for k in range(num_view_points):
view_location = view_points[k]['location'] #needed
view_image = view_points[k]['image']
mono_rir_path = view_points[k]['mono_rir'][speaker_id]
full_mono_rir_path = mono_rir_path
full_reverb_speech_path = full_mono_rir_path.replace(".wav","_reverb_speech.wav") #needed
dict_data={}
dict_data['unique_id'] = unique_id
dict_data['speaker_id'] = speaker_id
dict_data['speaker_location'] = speaker_location
dict_data['speaker_gender'] = speaker_gender
dict_data['clean_speech_path'] = full_clean_speech_path
dict_data['view_location'] = view_location
dict_data['view_image'] = view_image
dict_data['mono_rir_path'] = full_mono_rir_path
dict_data['reverb_speech_path'] = full_reverb_speech_path
path_list.append(dict_data)
with open(pickle_name, 'wb') as f:
pickle.dump(path_list, f, protocol=2)
data_path = "data/"
speech_path = "data/LibriSpeech-wav/dev-clean/"
AV_path = "synthetic_dataset/v16/val/"
pickle_name ="val.pickle"
folder_list = os.listdir(data_path+AV_path)
unique_id = 0
path_list=[]
for folders in folder_list:
folder_path = data_path + AV_path + folders +"/"
json_path = folder_path+"cleaned_metadata_v3.json"
f = open(json_path)
data = json.load(f)
len_data = len(data)
for i in range(len_data):
# print("i ",i," len data",len_data)
full_dict = data[i]
speakers = full_dict['speakers']
num_speakers=len(speakers)
for j in range(num_speakers):
speaker_id = str(speakers[j]['id']) #needed
speaker_location = speakers[j]['location'] #needed
speaker_gender = speakers[j]['gender'] #needed
speaker_speech = speakers[j]['speech']
split_speech = speaker_speech.split("-")
full_clean_speech_path = speech_path + split_speech[0] + "/" + split_speech[1] + "/" + speaker_speech +".wav" #needed
view_points = full_dict['viewpoints']
num_view_points = len(view_points)
unique_id = unique_id+1
for k in range(num_view_points):
view_location = view_points[k]['location'] #needed
view_image = view_points[k]['image']
mono_rir_path = view_points[k]['mono_rir'][speaker_id]
full_mono_rir_path = mono_rir_path
full_reverb_speech_path = full_mono_rir_path.replace(".wav","_reverb_speech.wav") #needed
dict_data={}
dict_data['unique_id'] = unique_id
dict_data['speaker_id'] = speaker_id
dict_data['speaker_location'] = speaker_location
dict_data['speaker_gender'] = speaker_gender
dict_data['clean_speech_path'] = full_clean_speech_path
dict_data['view_location'] = view_location
dict_data['view_image'] = view_image
dict_data['mono_rir_path'] = full_mono_rir_path
dict_data['reverb_speech_path'] = full_reverb_speech_path
path_list.append(dict_data)
with open(pickle_name, 'wb') as f:
pickle.dump(path_list, f, protocol=2)