fame_phonetics.py and functions to make quests.hed to tie triphone are added.

This commit is contained in:
yemaozi88
2019-03-25 00:06:53 +01:00
parent bf586fcde5
commit b444b70af9
8 changed files with 259 additions and 40 deletions

View File

@ -11,7 +11,7 @@ import numpy as np
import pandas as pd
import fame_functions
from phoneset import fame_ipa, fame_asr
from phoneset import fame_ipa, fame_asr, fame_phonetics
import defaultfiles as default
sys.path.append(default.toolbox_dir)
import file_handling as fh
@ -44,6 +44,9 @@ lexicon_asr = os.path.join(default.fame_dir, 'lexicon', 'lex.asr')
lexicon_oov = os.path.join(default.fame_dir, 'lexicon', 'lex.oov')
config_dir = os.path.join(default.htk_dir, 'config')
phonelist_full_txt = os.path.join(config_dir, 'phonelist_full.txt')
tree_hed = os.path.join(config_dir, 'tree.hed')
quest_hed = os.path.join(config_dir, 'quests.hed')
model_dir = os.path.join(default.htk_dir, 'model')
model_mono0_dir = os.path.join(model_dir, 'mono0')
@ -57,7 +60,7 @@ lexicon_dir = os.path.join(default.htk_dir, 'lexicon')
lexicon_htk_asr = os.path.join(lexicon_dir, 'lex.htk_asr')
lexicon_htk_oov = os.path.join(lexicon_dir, 'lex.htk_oov')
lexicon_htk = os.path.join(lexicon_dir, 'lex.htk')
#lexicon_htk_with_sp = os.path.join(lexicon_dir, 'lex_with_sp.htk')
lexicon_htk_triphone = os.path.join(lexicon_dir, 'lex_triphone.htk')
feature_dir = os.path.join(default.htk_dir, 'mfc')
fh.make_new_directory(feature_dir, existing_dir='leave')
@ -270,7 +273,7 @@ if train_monophone_without_sp:
'mfc',
os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
mlf_file=mlf_file_train,
lexicon_file=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic')
lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic')
)
print("elapsed time: {}".format(time.time() - timer_start))
@ -290,27 +293,27 @@ if add_sp:
modeln_dir_pre = os.path.join(model_mono1_dir, 'iter'+str(niter))
modeln_dir = os.path.join(model_mono1sp_dir, 'iter0')
#hmmdefs_pre = os.path.join(modeln_dir_pre, 'hmmdefs')
chtk.add_sp(modeln_dir_pre, modeln_dir)
print("elapsed time: {}".format(time.time() - timer_start))
print('>>> re-estimation...')
niter = chtk.re_estimation_until_saturated(
model_mono1sp_dir, modeln_dir, improvement_threshold, hcompv_scp_train,
os.path.join(htk_stimmen_dir, 'mfc'),
'mfc',
os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
mlf_file=mlf_file_train_with_sp,
lexicon_file=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
model_type='monophone_with_sp'
)
print("elapsed time: {}".format(time.time() - timer_start))
## ======================= train model with re-aligned mlf =======================
if train_monophone_with_re_aligned_mlf:
print('==== traina monophone with re-aligned mlf ====')
timer_start = time.time()
print('>>> re-aligning the training data... ')
timer_start = time.time()
niter = chtk.get_niter_max(model_mono1sp_dir)
modeln_dir = os.path.join(model_mono1sp_dir, 'iter'+str(niter))
chtk.make_aligned_label(
@ -326,7 +329,6 @@ if train_monophone_with_re_aligned_mlf:
mlf_file_train_with_sp,
hcompv_scp_train,
hcompv_scp_train_updated)
print("elapsed time: {}".format(time.time() - timer_start))
print('>>> re-estimation... ')
timer_start = time.time()
@ -341,7 +343,7 @@ if train_monophone_with_re_aligned_mlf:
'mfc',
os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
mlf_file=mlf_file_train_aligned,
lexicon_file=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
model_type='monophone_with_sp'
)
print("elapsed time: {}".format(time.time() - timer_start))
@ -350,7 +352,7 @@ if train_monophone_with_re_aligned_mlf:
## ======================= train triphone =======================
if train_triphone:
print('==== traina triphone model ====')
#model_out_dir = os.path.join(model_dir, 'hmm1_tri', 'iter1')
timer_start = time.time()
triphonelist_txt = os.path.join(config_dir, 'triphonelist.txt')
triphone_mlf = os.path.join(default.htk_dir, 'label', 'train_triphone.mlf')
@ -385,7 +387,7 @@ if train_triphone:
# 'mfc',
# os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
# mlf_file=triphone_mlf,
# lexicon_file=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
# lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
# model_type='triphone'
# )
#
@ -409,8 +411,21 @@ if train_triphone:
macros=os.path.join(_modeln_dir_pre, 'macros'),
model_type='triphone')
print("elapsed time: {}".format(time.time() - timer_start))
## ======================= train triphone =======================
if train_triphone_tied:
print('==== traina tied-state triphone ====')
timer_start = time.time()
print('>>> making lexicon for triphone... ')
chtk.make_triphone_full(phonelist_full_txt, lexicon_htk_triphone)
print('>>> making headers... ')
chtk.make_tree_header(tree_hed)
fame_phonetics.make_quests_hed(quest_hed)
print("elapsed time: {}".format(time.time() - timer_start))