-
Notifications
You must be signed in to change notification settings - Fork 1
/
AlignedDeleteList.py
64 lines (50 loc) · 1.87 KB
/
AlignedDeleteList.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
#!/usr/bin/env python
#author:gaigai 2013/12/3
#This program generate the modifid mfcc list by Aligned.mlf Phoneme.mlf and list.mfc0
#input:Aligned.mlf Phoneme.mlf list.mfc0
#output:mlist.mfc0
import sys
if __name__ == '__main__':
if (len(sys.argv) != 4):
print 'Usage: AlignedDeleteList.py infile(Aligned.mlf) infile(Phoneme.mlf) infile(list.mfc0)'
sys.exit(1)
inFile1 = open(sys.argv[1],'r')
inFile2 = open(sys.argv[2],'r')
inFile3 = open(sys.argv[3],'r')
filename = sys.argv[3]
# name the output file by the infile's name of list.mfc0.
if "/" in filename:#judge the path
filename = filename[:filename.rindex("/")+1] + "m" + filename[filename.rindex("/")+1:]
else:
filename = "m" + filename
outFile = open(filename,'w')
alignedContent = inFile1.readlines()
phonemeContent = inFile2.readlines()
mfcListContent = inFile3.readlines()
alignedId = []
phonemeId = []
compareId = []
for items in alignedContent:# get all the id in aligned file
if ".lab" in items:
newitem = items[items.index("/")+1:items.rindex(".")]
alignedId.append(newitem)
for items in phonemeContent:# get all the id in phoneme file
if ".lab" in items:
newitem = items[items.index("/")+1:items.rindex(".")]
phonemeId.append(newitem)
alignedId.sort()
phonemeId.sort()
for items in phonemeId:
if items not in alignedId:
compareId.append(items)
for comItem in compareId:# find the different id and delete it in the list
for items in mfcListContent:
if comItem in items:
print "delete: %s" %items
mfcListContent.remove(items)
for items in mfcListContent:
outFile.write(items)
inFile1.close()
inFile2.close()
inFile3.close()
outFile.close()