-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoLexiconGenerator.py
39 lines (38 loc) · 1.92 KB
/
autoLexiconGenerator.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
# coding=utf-8
import sys
import re
import os
word_directory = './PYWVox/'
pronunciation_directory = './PYPs/'
destination_directory = './Components/'
lexicon_name = 'voxforge_lexicon_part_1'
if os.path.exists(word_directory) and os.path.exists(pronunciation_directory):
print('Loading...')
file_list = ''
for file_or_folder in os.listdir(word_directory):
name_extension = str(file_or_folder).split('.')
word_path = os.path.join(word_directory, str(name_extension[0]) + '.pywv')
pronunciation_path = os.path.join(pronunciation_directory, str(name_extension[0]) + '.pyp')
new_path = os.path.join(destination_directory, str(name_extension[0]) + '.tmp')
# judge wheather one object in the directory is a file.
if os.path.isfile(word_path) and os.path.isfile(pronunciation_path):
os.system('paste -d " " ' + word_path + ' ' + pronunciation_path + ' > ' + new_path)
file_list += new_path
file_list += ' '
os.system("cat " + file_list + " > " + destination_directory + lexicon_name)
#os.system("cat " + file_list + "i > " + destination_directory + lexicon_name)
for file_or_folder in os.listdir(destination_directory):
name_extension = str(file_or_folder).split('.')
# judge wheather one object in the directory is a file.
if len(name_extension)==2 and name_extension[1]=='tmp':
os.remove(os.path.join(word_directory, str(name_extension[0]) + '.pywv'))
#os.remove(os.path.join(pronunciation_directory, str(name_extension[0]) + '.pyp'))
os.remove(os.path.join(destination_directory, file_or_folder))
else:
print('Wrong path!')
print('---------------------------------------')
print('Executing ...\n')
print('Congratuation, new lexicon file ' + lexicon_name + ' has been generated in ' + destination_directory + ' directory.')
print('---------------------------------------')
#fr.close()
#fw.close()