forked from changjenyin/DNN_HMM_RNN_speech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWFST_exe.py
43 lines (35 loc) · 1.29 KB
/
WFST_exe.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
import os
import sys
def main(argv):
# Process I/O files
seq_file = 'seq_timit_text.txt'
tmp_file = seq_file + '_tmp.txt'
tmp_sentence_file = seq_file + '_sentence.txt'
junk, postfix = os.path.splitext(os.path.basename(seq_file))[0].split('_', 1)
seqs = open('/home/master/03/eric11220/Deep/final/Lexicon_WFST/' + seq_file, 'U')
n_sentences = open('/tmp4/eric11220/sentences_' + postfix + '.txt', 'w')
n_best = sys.argv[1]
idx = 0
for line in seqs:
# After a bunch of n-sequences, output a '\n'
if line == '\n':
continue
if line == '<s>\n':
n_sentences.write('<s>\n')
continue
# Generate a tmp file for each seq
tmp = open('/home/master/03/eric11220/Deep/final/Lexicon_WFST/' + tmp_file, 'w')
tmp.write(line)
tmp.close()
idx += 1
print idx, line
# Run WFST
os.chdir('/home/master/03/eric11220/Deep/final/Lexicon_WFST/')
os.system('./run.sh ' + tmp_file + ' ' + n_best + ' > ' + tmp_sentence_file)
# Write each sentence for RNNLM
tmp_sentence = open(tmp_sentence_file, 'U')
for line in tmp_sentence:
n_sentences.write(line)
n_sentences.write('<s>\n')
if __name__ == '__main__':
main(sys.argv)