14 changed files with 465 additions and 98 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
import sys |
||||
import os |
||||
os.chdir(r'C:\Users\Aki\source\repos\acoustic_model\acoustic_model') |
||||
|
||||
import time |
||||
|
||||
import numpy as np |
||||
import pandas as pd |
||||
|
||||
import fame_functions |
||||
import defaultfiles as default |
||||
sys.path.append(default.toolbox_dir) |
||||
from phoneset import fame_ipa, fame_asr |
||||
|
||||
|
||||
lexicon_dir = os.path.join(default.fame_dir, 'lexicon') |
||||
lexicon_ipa = os.path.join(lexicon_dir, 'lex.ipa') |
||||
lexicon_asr = os.path.join(lexicon_dir, 'lex.asr') |
||||
|
||||
|
||||
## check if all the phones in lexicon.ipa are in fame_ipa.py. |
||||
#timer_start = time.time() |
||||
#phoneset_lex = fame_functions.get_phoneset_from_lexicon(lexicon_ipa, phoneset='ipa') |
||||
#phoneset_py = fame_ipa.phoneset |
||||
#print("phones which is in lexicon.ipa but not in fame_ipa.py:\n{}".format( |
||||
# set(phoneset_lex) - set(phoneset_py))) |
||||
#print("elapsed time: {}".format(time.time() - timer_start)) |
||||
|
||||
# check which word has the phone. |
||||
#timer_start = time.time() |
||||
#extracted = find_phone(lexicon_ipa, 'ⁿ') |
||||
#print("elapsed time: {}".format(time.time() - timer_start)) |
||||
|
||||
|
||||
## get the correspondence between lex_ipa and lex_asr. |
||||
lex_asr = fame_functions.load_lexicon(lexicon_asr) |
||||
lex_ipa = fame_functions.load_lexicon(lexicon_ipa) |
||||
if 0: |
||||
timer_start = time.time() |
||||
translation_key_ipa2asr, phone_unknown = fame_functions.get_translation_key(lexicon_ipa, lexicon_asr) |
||||
print("elapsed time: {}".format(time.time() - timer_start)) |
||||
|
||||
np.save(os.path.join('phoneset', 'output_get_translation_key_translation_key.npy'), translation_key_ipa2asr) |
||||
np.save(os.path.join('phoneset', 'output_get_translation_key_phone_unknown.npy'), phone_unknown) |
||||
else: |
||||
translation_key_ipa2asr = np.load(os.path.join('phoneset', 'output_get_translation_key_translation_key.npy')).item() |
||||
phone_unknown = np.load(os.path.join('phoneset', 'output_get_translation_key_phone_unknown.npy')) |
||||
phone_unknown = list(phone_unknown) |
||||
|
||||
# manually check the correspondence for the phone in phone_unknown. |
||||
#p = phone_unknown[0] |
||||
#lex_ipa_ = find_phone(lexicon_ipa, p, phoneset='ipa') |
||||
|
||||
#for word in lex_ipa_['word']: |
||||
# ipa = lex_ipa[lex_ipa['word'] == word].iat[0, 1] |
||||
# if np.sum(lex_asr['word'] == word) > 0: |
||||
# asr = lex_asr[lex_asr['word'] == word].iat[0, 1] |
||||
|
||||
# ipa_list = convert_phone_set.split_word(ipa, fame_ipa.multi_character_phones) |
||||
# asr_list = asr.split(' ') |
||||
# if p in ipa_list and (len(ipa_list) == len(asr_list)): |
||||
# print("{0}: {1} --> {2}".format(word, ipa_list, asr_list)) |
||||
# for ipa_, asr_ in zip(ipa_list, asr_list): |
||||
# if ipa_ in phone_unknown: |
||||
# translation_key_ipa2asr[ipa_] = asr_ |
||||
# phone_unknown.remove(ipa_) |
||||
translation_key_ipa2asr['ə:'] = 'ə' |
||||
translation_key_ipa2asr['r.'] = 'r' |
||||
translation_key_ipa2asr['r:'] = 'r' |
||||
np.save(os.path.join('phoneset', 'fame_ipa2asr.npy'), translation_key_ipa2asr) |
||||
|
||||
|
||||
## check if all the phones in lexicon.asr are in translation_key_ipa2asr. |
||||
timer_start = time.time() |
||||
phoneset_lex = fame_functions.get_phoneset_from_lexicon(lexicon_asr, phoneset='asr') |
||||
phoneset_lex.remove("") |
||||
phoneset_asr = list(set(translation_key_ipa2asr.values())) |
||||
print("phones which is in lexicon.asr but not in the translation_key_ipa2asr:\n{}".format( |
||||
set(phoneset_lex) - set(phoneset_asr))) |
||||
print("elapsed time: {}".format(time.time() - timer_start)) |
||||
|
||||
## make the translation key between asr to htk. |
||||
#multi_character_phones = [i for i in phoneset_asr if len(i) > 1] |
||||
#multi_character_phones.sort(key=len, reverse=True) |
||||
|
||||
#lexicon_ipa = pd.read_table(lex_ipa, names=['word', 'pronunciation']) |
||||
#with open(lex_ipa_, "w", encoding="utf-8") as fout: |
||||
# for word, pronunciation in zip(lexicon_ipa['word'], lexicon_ipa['pronunciation']): |
||||
# # ignore nasalization and '.' |
||||
# pronunciation_ = pronunciation.replace(u'ⁿ', '') |
||||
# pronunciation_ = pronunciation_.replace('.', '') |
||||
# pronunciation_split = convert_phone_set.split_ipa_fame(pronunciation_) |
||||
# fout.write("{0}\t{1}\n".format(word, ' '.join(pronunciation_split))) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue