-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice_timedot_ali_2_labs.py
35 lines (33 loc) · 1.45 KB
/
slice_timedot_ali_2_labs.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
# coding: UTF-8
timepot_align_file_name = "results/timepot_dnn_1"
sentence_dict = dict() # A dictionary of sentence lists, each list contains some phonemes with their begin & end time.
with open(timepot_align_file_name, "r") as timepot_align_file:
current_sentence_name = ""
while 1:
lines = timepot_align_file.readlines(10000)
if not lines:
break
for line in lines:
temp_list = line.strip().split("\t")
# print(temp_list)
if len(temp_list) == 1: # New sentence(sentence name) or sentence end(a char ".").
current_sentence_name = temp_list[0]
continue
if current_sentence_name not in sentence_dict.keys():# First phoneme of a sentence.
sentence_dict[current_sentence_name] = list()
pass
phoneme_list = temp_list[1].strip("[]").split(",")
phoneme_list.append(temp_list[0]+"\n")
phoneme = "\t".join(phoneme_list)
sentence_dict[current_sentence_name].append(phoneme)
pass
pass
pass
labs_dir_name = "labs/dnn1/"
labs_prefix_name = "dnn1_"
labs_extension_name = ".lab"
for sentence_file_name in sentence_dict.keys():
with open(labs_dir_name + labs_prefix_name + sentence_file_name + labs_extension_name, "w") as sentence_file:
sentence_file.writelines(sentence_dict[sentence_file_name])
pass
pass