Compare commits
5 Commits
fa81b70b27
...
master
Author | SHA1 | Date | |
---|---|---|---|
97486e5599 | |||
2004399179 | |||
b444b70af9 | |||
bf586fcde5 | |||
fdd165ce6a |
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>4d8c8573-32f0-4a62-9e62-3ce5cc680390</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>fame_hmm.py</StartupFile>
|
||||
<StartupFile>check_novoapi.py</StartupFile>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
@ -51,6 +51,9 @@
|
||||
<Compile Include="fame_hmm.py" />
|
||||
<Compile Include="phoneset\fame_asr.py" />
|
||||
<Compile Include="phoneset\fame_ipa.py" />
|
||||
<Compile Include="phoneset\fame_phonetics.py">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="stimmen_functions.py" />
|
||||
<Compile Include="stimmen_test.py" />
|
||||
</ItemGroup>
|
||||
|
@ -29,48 +29,47 @@ forced_alignment_novo70 = True
|
||||
|
||||
|
||||
## ===== load novo phoneset =====
|
||||
phoneset_ipa, phoneset_novo70, translation_key_ipa2novo70, translation_key_novo702ipa = novoapi_functions.load_phonset()
|
||||
phoneset_ipa, phoneset_novo70, translation_key_ipa2novo70, translation_key_novo702ipa = novoapi_functions.load_novo70_phoneset()
|
||||
|
||||
|
||||
## ===== extract pronunciations written in novo70 only (not_in_novo70) =====
|
||||
|
||||
# As per Nederlandse phoneset_aki.xlsx recieved from David
|
||||
# [ɔː] oh / ohr
|
||||
# [ɪː] ih / ihr
|
||||
# [iː] iy
|
||||
# [œː] uh
|
||||
# [ɛː] eh
|
||||
# [w] wv in IPA written as ʋ.
|
||||
david_suggestion = ['ɔː', 'ɪː', 'iː', 'œː', 'ɛː', 'w']
|
||||
|
||||
|
||||
## read pronunciation variants.
|
||||
stimmen_transcription_ = pd.ExcelFile(default.stimmen_transcription_xlsx)
|
||||
df = pd.read_excel(stimmen_transcription_, 'frequency')
|
||||
transcription_ipa = list(df['IPA'])
|
||||
#stimmen_transcription_ = pd.ExcelFile(default.stimmen_transcription_xlsx)
|
||||
#df = pd.read_excel(stimmen_transcription_, 'frequency')
|
||||
#transcription_ipa = list(df['IPA'])
|
||||
|
||||
# transcription mistake?
|
||||
transcription_ipa = [ipa.replace(';', 'ː') for ipa in transcription_ipa if not ipa=='pypɪl' and not pd.isnull(ipa)]
|
||||
transcription_ipa = [ipa.replace('ˑ', '') for ipa in transcription_ipa] # only one case.
|
||||
|
||||
not_in_novo70 = []
|
||||
all_in_novo70 = []
|
||||
for ipa in transcription_ipa:
|
||||
ipa = ipa.replace(':', 'ː')
|
||||
ipa = convert_phone_set.split_ipa(ipa)
|
||||
stimmen_test_dir = r'c:\OneDrive\Research\rug\_data\stimmen_test'
|
||||
df = stimmen_functions.load_transcriptions_novo70(stimmen_test_dir)
|
||||
|
||||
# list of phones not in novo70 phoneset.
|
||||
not_in_novo70_ = [phone for phone in ipa
|
||||
if not phone in phoneset_ipa and not phone in david_suggestion]
|
||||
not_in_novo70_ = [phone.replace('sp', '') for phone in not_in_novo70_]
|
||||
not_in_novo70_ = [phone.replace(':', '') for phone in not_in_novo70_]
|
||||
not_in_novo70_ = [phone.replace('ː', '') for phone in not_in_novo70_]
|
||||
|
||||
|
||||
if len(not_in_novo70_) == 0:
|
||||
all_in_novo70.append(''.join(ipa))
|
||||
## transcription mistake?
|
||||
#transcription_ipa = [ipa.replace(';', 'ː') for ipa in transcription_ipa if not ipa=='pypɪl' and not pd.isnull(ipa)]
|
||||
#transcription_ipa = [ipa.replace('ˑ', '') for ipa in transcription_ipa] # only one case.
|
||||
|
||||
#translation_key.get(phone, phone)
|
||||
not_in_novo70.extend(not_in_novo70_)
|
||||
not_in_novo70_list = list(set(not_in_novo70))
|
||||
#not_in_novo70 = []
|
||||
#all_in_novo70 = []
|
||||
#for ipa in transcription_ipa:
|
||||
# ipa = ipa.replace(':', 'ː')
|
||||
# ipa = convert_phone_set.split_ipa(ipa)
|
||||
|
||||
# # list of phones not in novo70 phoneset.
|
||||
# not_in_novo70_ = [phone for phone in ipa
|
||||
# if not phone in phoneset_ipa and not phone in david_suggestion]
|
||||
# not_in_novo70_ = [phone.replace('sp', '') for phone in not_in_novo70_]
|
||||
# not_in_novo70_ = [phone.replace(':', '') for phone in not_in_novo70_]
|
||||
# not_in_novo70_ = [phone.replace('ː', '') for phone in not_in_novo70_]
|
||||
|
||||
# if len(not_in_novo70_) == 0:
|
||||
# all_in_novo70.append(''.join(ipa))
|
||||
|
||||
# #translation_key.get(phone, phone)
|
||||
# not_in_novo70.extend(not_in_novo70_)
|
||||
#not_in_novo70_list = list(set(not_in_novo70))
|
||||
|
||||
|
||||
## check which phones used in stimmen but not in novo70
|
||||
@ -85,41 +84,43 @@ not_in_novo70_list = list(set(not_in_novo70))
|
||||
# [ʊ] 'ʊ'(1) --> can be ʏ (uh)??
|
||||
# [χ] --> can be x??
|
||||
|
||||
def search_phone_ipa(x, phone_list):
|
||||
x_in_item = []
|
||||
for ipa in phone_list:
|
||||
ipa_original = ipa
|
||||
ipa = ipa.replace(':', 'ː')
|
||||
ipa = convert_phone_set.split_ipa(ipa)
|
||||
if x in ipa and not x+':' in ipa:
|
||||
x_in_item.append(ipa_original)
|
||||
return x_in_item
|
||||
#def search_phone_ipa(x, phone_list):
|
||||
# x_in_item = []
|
||||
# for ipa in phone_list:
|
||||
# ipa_original = ipa
|
||||
# ipa = ipa.replace(':', 'ː')
|
||||
# ipa = convert_phone_set.split_ipa(ipa)
|
||||
# if x in ipa and not x+':' in ipa:
|
||||
# x_in_item.append(ipa_original)
|
||||
# return x_in_item
|
||||
#search_phone_ipa('ø', transcription_ipa)
|
||||
|
||||
|
||||
## ===== load all transcriptions (df) =====
|
||||
df = stimmen_functions.load_transcriptions()
|
||||
#df = stimmen_functions.load_transcriptions()
|
||||
word_list = [i for i in list(set(df['word'])) if not pd.isnull(i)]
|
||||
word_list = sorted(word_list)
|
||||
|
||||
|
||||
## check frequency of each pronunciation variants
|
||||
cols = ['word', 'ipa', 'frequency']
|
||||
df_samples = pd.DataFrame(index=[], columns=cols)
|
||||
for ipa in all_in_novo70:
|
||||
ipa = ipa.replace('ː', ':')
|
||||
samples = df[df['ipa'] == ipa]
|
||||
word = list(set(samples['word']))[0]
|
||||
samples_Series = pd.Series([word, ipa, len(samples)], index=df_samples.columns)
|
||||
df_samples = df_samples.append(samples_Series, ignore_index=True)
|
||||
#cols = ['word', 'ipa', 'frequency']
|
||||
#df_samples = pd.DataFrame(index=[], columns=cols)
|
||||
#for ipa in all_in_novo70:
|
||||
# ipa = ipa.replace('ː', ':')
|
||||
# samples = df[df['ipa'] == ipa]
|
||||
# word = list(set(samples['word']))[0]
|
||||
# samples_Series = pd.Series([word, ipa, len(samples)], index=df_samples.columns)
|
||||
# df_samples = df_samples.append(samples_Series, ignore_index=True)
|
||||
|
||||
# each word
|
||||
df_per_word = pd.DataFrame(index=[], columns=df_samples.keys())
|
||||
#df_per_word = pd.DataFrame(index=[], columns=df_samples.keys())
|
||||
|
||||
for word in word_list:
|
||||
df_samples_ = df_samples[df_samples['word']==word]
|
||||
df_samples_ = df_samples_[df_samples_['frequency']>2]
|
||||
df_per_word = df_per_word.append(df_samples_, ignore_index=True)
|
||||
#for word in word_list:
|
||||
word = word_list[2]
|
||||
df_ = df[df['word']==word]
|
||||
np.unique(list(df_['ipa']))
|
||||
#df_samples_ = df_samples_[df_samples_['frequency']>2]
|
||||
#df_per_word = df_per_word.append(df_samples_, ignore_index=True)
|
||||
#df_per_word.to_excel(os.path.join(default.stimmen_dir, 'pronunciation_variants_novo70.xlsx'), encoding="utf-8")
|
||||
|
||||
|
||||
|
@ -14,18 +14,20 @@ def multi_character_tokenize(line, multi_character_tokens):
|
||||
line = line[1:]
|
||||
|
||||
|
||||
def split_word(word, multi_character_phones):
|
||||
def split_word(word, phoneset):
|
||||
"""
|
||||
split a line by given phoneset.
|
||||
|
||||
Args:
|
||||
word (str): a word written in given phoneset.
|
||||
multi_character_phones (list): the list of multicharacter phones which is considered as one phone. this can be obtained with phoneset definition such as fame_ipa.py.
|
||||
#multi_character_phones (list): the list of multicharacter phones which is considered as one phone. this can be obtained with phoneset definition such as fame_ipa.py.
|
||||
phoneset (list): the list of phones.
|
||||
|
||||
Returns:
|
||||
(word_seperated) (list): the word splitted in given phoneset.
|
||||
|
||||
"""
|
||||
multi_character_phones = extract_multi_character_phones(phoneset)
|
||||
return [phone
|
||||
for phone in multi_character_tokenize(word.strip(), multi_character_phones)
|
||||
]
|
||||
@ -43,4 +45,14 @@ def convert_phoneset(word_list, translation_key):
|
||||
def phone_reduction(phones, reduction_key):
|
||||
multi_character_tokenize(wo.strip(), multi_character_phones)
|
||||
return [reduction_key.get(i, i) for i in phones
|
||||
if not i in phones_to_be_removed]
|
||||
if not i in phones_to_be_removed]
|
||||
|
||||
|
||||
def extract_multi_character_phones(phoneset):
|
||||
"""
|
||||
Args:
|
||||
phoneset (list):
|
||||
"""
|
||||
multi_character_phones = [i for i in phoneset if len(i) > 1]
|
||||
multi_character_phones.sort(key=len, reverse=True)
|
||||
return multi_character_phones
|
@ -345,6 +345,7 @@ def fix_lexicon(lexicon_file):
|
||||
|
||||
for i in lex[lex['word'].str.startswith('\'')].index.values:
|
||||
lex.iat[i, 0] = lex.iat[i, 0].replace('\'', '\\\'')
|
||||
|
||||
# to_csv does not work with space seperator. therefore all tabs should manually be replaced.
|
||||
#lex.to_csv(lexicon_file, index=False, header=False, encoding="utf-8", sep=' ', quoting=csv.QUOTE_NONE, escapechar='\\')
|
||||
lex.to_csv(lexicon_file, index=False, header=False, sep='\t', encoding='utf-8')
|
||||
@ -369,7 +370,8 @@ def ipa2asr(ipa):
|
||||
def ipa2htk(ipa):
|
||||
curr_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
translation_key_ipa2asr = np.load(os.path.join(curr_dir, 'phoneset', 'fame_ipa2asr.npy')).item(0)
|
||||
|
||||
#translation_key_ipa2asr = np.load(r'c:\Users\Aki\source\repos\acoustic_model\acoustic_model\phoneset\fame_ipa2asr.npy').item(0)
|
||||
|
||||
ipa_splitted = convert_phoneset.split_word(ipa, fame_ipa.multi_character_phones)
|
||||
ipa_splitted = fame_ipa.phone_reduction(ipa_splitted)
|
||||
asr_splitted = convert_phoneset.convert_phoneset(ipa_splitted, translation_key_ipa2asr)
|
||||
|
@ -11,54 +11,59 @@ 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
|
||||
from htk import pyhtk
|
||||
#from scripts import run_command
|
||||
|
||||
|
||||
## ======================= user define =======================
|
||||
# procedure
|
||||
combine_all = 1
|
||||
|
||||
make_lexicon = 0
|
||||
make_label = 0 # it takes roughly 4800 sec on Surface pro 2.
|
||||
make_mlf = 0
|
||||
extract_features = 0
|
||||
flat_start = 0
|
||||
train_model_without_sp = 0
|
||||
add_sp = 0
|
||||
train_model_with_re_aligned_mlf = 1
|
||||
flat_start = 1
|
||||
train_monophone_without_sp = 1
|
||||
add_sp = 1
|
||||
train_monophone_with_re_aligned_mlf = 1
|
||||
increase_mixture = 1
|
||||
train_triphone = 0
|
||||
|
||||
train_triphone_tied = 0
|
||||
|
||||
|
||||
# pre-defined values.
|
||||
dataset_list = ['devel', 'test', 'train']
|
||||
feature_size = 39
|
||||
feature_size = 30
|
||||
improvement_threshold = 0.3
|
||||
|
||||
hmmdefs_name = 'hmmdefs'
|
||||
proto_name = 'proto'
|
||||
|
||||
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')
|
||||
|
||||
sil_hed = os.path.join(config_dir, 'sil.hed')
|
||||
prototype = os.path.join(config_dir, proto_name)
|
||||
phonelist_full_txt = os.path.join(config_dir, 'phonelist_full.txt')
|
||||
tree_hed = os.path.join(config_dir, 'tree.hed')
|
||||
quests_hed = os.path.join(config_dir, 'quests.hed')
|
||||
|
||||
model_dir = os.path.join(default.htk_dir, 'model')
|
||||
model0_dir = os.path.join(model_dir, 'hmm0')
|
||||
model1_dir = os.path.join(model_dir, 'hmm1')
|
||||
model1sp_dir = os.path.join(model_dir, 'hmm1sp')
|
||||
model1sp2_dir = os.path.join(model_dir, 'hmm1sp2')
|
||||
model_mono0_dir = os.path.join(model_dir, 'mono0')
|
||||
model_mono1_dir = os.path.join(model_dir, 'mono1')
|
||||
model_mono1sp_dir = os.path.join(model_dir, 'mono1sp')
|
||||
model_mono1sp2_dir = os.path.join(model_dir, 'mono1sp2')
|
||||
model_tri1_dir = os.path.join(model_dir, 'tri1')
|
||||
model_tri1tied_dir = os.path.join(model_dir, 'tri1tied')
|
||||
|
||||
# directories / files to be made.
|
||||
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')
|
||||
@ -69,9 +74,21 @@ fh.make_new_directory(label_dir, existing_dir='leave')
|
||||
|
||||
|
||||
## training
|
||||
hcompv_scp_train = os.path.join(tmp_dir, 'train.scp')
|
||||
mlf_file_train = os.path.join(label_dir, 'train_phone.mlf')
|
||||
mlf_file_train_aligned = os.path.join(label_dir, 'train_phone_aligned.mlf')
|
||||
if combine_all:
|
||||
hcompv_scp_train = os.path.join(tmp_dir, 'all.scp')
|
||||
mlf_file_train = os.path.join(label_dir, 'all_phone.mlf')
|
||||
mlf_file_train_word = os.path.join(label_dir, 'all_word.mlf')
|
||||
mlf_file_train_with_sp = os.path.join(label_dir, 'all_phone_with_sp.mlf')
|
||||
mlf_file_train_aligned = os.path.join(label_dir, 'all_phone_aligned.mlf')
|
||||
triphone_mlf = os.path.join(label_dir, 'all_triphone.mlf')
|
||||
else:
|
||||
hcompv_scp_train = os.path.join(tmp_dir, 'train.scp')
|
||||
mlf_file_train = os.path.join(label_dir, 'train_phone.mlf')
|
||||
mlf_file_train_word = os.path.join(label_dir, 'train_word.mlf')
|
||||
mlf_file_train_with_sp = os.path.join(label_dir, 'train_phone_with_sp.mlf')
|
||||
mlf_file_train_aligned = os.path.join(label_dir, 'train_phone_aligned.mlf')
|
||||
triphone_mlf = os.path.join(label_dir, 'train_triphone.mlf')
|
||||
hcompv_scp_train_updated = hcompv_scp_train.replace('.scp', '_updated.scp')
|
||||
|
||||
## testing
|
||||
htk_stimmen_dir = os.path.join(default.htk_dir, 'stimmen')
|
||||
@ -99,11 +116,19 @@ if make_lexicon:
|
||||
# http://electroblaze.blogspot.nl/2013/03/understanding-htk-error-messages.html
|
||||
print('>>> fixing the lexicon...')
|
||||
fame_functions.fix_lexicon(lexicon_htk)
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
## adding sp to the lexicon for HTK.
|
||||
print('>>> adding sp to the lexicon...')
|
||||
with open(lexicon_htk) as f:
|
||||
lines = f.read().split('\n')
|
||||
with open(lexicon_htk_with_sp, 'wb') as f:
|
||||
f.write(bytes(' sp\n'.join(lines), 'ascii'))
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
|
||||
## intialize the instance for HTK.
|
||||
chtk = pyhtk.HTK(config_dir, fame_asr.phoneset_htk, lexicon_htk, feature_size)
|
||||
chtk = pyhtk.HTK(config_dir, fame_asr.phoneset_htk, lexicon_htk_with_sp, feature_size)
|
||||
|
||||
|
||||
## ======================= make label files =======================
|
||||
@ -139,7 +164,7 @@ if make_label:
|
||||
shutil.move(dictionary_file, os.path.join(label_dir_, filename + '.dic'))
|
||||
|
||||
label_file = os.path.join(label_dir_, filename + '.lab')
|
||||
chtk.create_label_file(sentence_htk, label_file)
|
||||
chtk.make_label_file(sentence_htk, label_file)
|
||||
else:
|
||||
os.remove(dictionary_file)
|
||||
|
||||
@ -161,16 +186,18 @@ if make_mlf:
|
||||
os.remove(empty_dic_file)
|
||||
|
||||
for dataset in dataset_list:
|
||||
#wav_dir_ = os.path.join(default.fame_dir, 'fame', 'wav', dataset)
|
||||
feature_dir_ = os.path.join(feature_dir, dataset)
|
||||
label_dir_ = os.path.join(label_dir, dataset)
|
||||
mlf_word = os.path.join(label_dir, dataset + '_word.mlf')
|
||||
mlf_phone = os.path.join(label_dir, dataset + '_phone.mlf')
|
||||
mlf_phone_with_sp = os.path.join(label_dir, dataset + '_phone_with_sp.mlf')
|
||||
|
||||
print(">>> generating a word level mlf file for {}...".format(dataset))
|
||||
chtk.label2mlf(label_dir_, mlf_word)
|
||||
|
||||
print(">>> generating a phone level mlf file for {}...".format(dataset))
|
||||
chtk.mlf_word2phone(mlf_phone, mlf_word)
|
||||
chtk.mlf_word2phone(mlf_phone, mlf_word, with_sp=False)
|
||||
chtk.mlf_word2phone(mlf_phone_with_sp, mlf_word, with_sp=True)
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
@ -181,7 +208,7 @@ if extract_features:
|
||||
timer_start = time.time()
|
||||
print('==== extract features on dataset {} ===='.format(dataset))
|
||||
|
||||
wav_dir_ = os.path.join(default.fame_dir, 'fame', 'wav', dataset)
|
||||
wav_dir_ = os.path.join(default.fame_dir, 'fame', 'wav', dataset)
|
||||
label_dir_ = os.path.join(label_dir, dataset)
|
||||
feature_dir_ = os.path.join(feature_dir, dataset)
|
||||
fh.make_new_directory(feature_dir_, existing_dir='delete')
|
||||
@ -201,8 +228,8 @@ if extract_features:
|
||||
+ os.path.join(feature_dir_, os.path.basename(lab_file).replace('.lab', '.mfc'))
|
||||
for lab_file in lab_list]
|
||||
|
||||
if os.path.exists(empty_mfc_file):
|
||||
os.remove(empty_mfc_file)
|
||||
#if os.path.exists(empty_mfc_file):
|
||||
# os.remove(empty_mfc_file)
|
||||
with open(hcopy_scp.name, 'wb') as f:
|
||||
f.write(bytes('\n'.join(feature_list), 'ascii'))
|
||||
|
||||
@ -219,45 +246,97 @@ if extract_features:
|
||||
with open(hcompv_scp, 'wb') as f:
|
||||
f.write(bytes('\n'.join(mfc_list) + '\n', 'ascii'))
|
||||
|
||||
print(">>> extracting features on stimmen...")
|
||||
chtk.wav2mfc(os.path.join(htk_stimmen_dir, 'hcopy.scp'))
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
|
||||
## ======================= flat start monophones =======================
|
||||
if combine_all:
|
||||
# script files.
|
||||
fh.concatenate(
|
||||
os.path.join(tmp_dir, 'devel.scp'),
|
||||
os.path.join(tmp_dir, 'test.scp'),
|
||||
hcompv_scp_train
|
||||
)
|
||||
fh.concatenate(
|
||||
hcompv_scp_train,
|
||||
os.path.join(tmp_dir, 'train.scp'),
|
||||
hcompv_scp_train
|
||||
)
|
||||
|
||||
# phone level mlfs.
|
||||
fh.concatenate(
|
||||
os.path.join(label_dir, 'devel_phone.mlf'),
|
||||
os.path.join(label_dir, 'test_phone.mlf'),
|
||||
mlf_file_train
|
||||
)
|
||||
fh.concatenate(
|
||||
mlf_file_train,
|
||||
os.path.join(label_dir, 'train_phone.mlf'),
|
||||
mlf_file_train
|
||||
)
|
||||
|
||||
# phone level mlfs with sp.
|
||||
fh.concatenate(
|
||||
os.path.join(label_dir, 'devel_phone_with_sp.mlf'),
|
||||
os.path.join(label_dir, 'test_phone_with_sp.mlf'),
|
||||
mlf_file_train_with_sp
|
||||
)
|
||||
fh.concatenate(
|
||||
mlf_file_train_with_sp,
|
||||
os.path.join(label_dir, 'train_phone_with_sp.mlf'),
|
||||
mlf_file_train_with_sp
|
||||
)
|
||||
|
||||
|
||||
# word level mlfs.
|
||||
fh.concatenate(
|
||||
os.path.join(label_dir, 'devel_word.mlf'),
|
||||
os.path.join(label_dir, 'test_word.mlf'),
|
||||
mlf_file_train_word
|
||||
)
|
||||
fh.concatenate(
|
||||
mlf_file_train_word,
|
||||
os.path.join(label_dir, 'train_word.mlf'),
|
||||
mlf_file_train_word
|
||||
)
|
||||
|
||||
|
||||
## ======================= flat start monophones =======================
|
||||
if flat_start:
|
||||
timer_start = time.time()
|
||||
print('==== flat start ====')
|
||||
fh.make_new_directory(model0_dir, existing_dir='leave')
|
||||
fh.make_new_directory(model_mono0_dir, existing_dir='leave')
|
||||
|
||||
chtk.flat_start(hcompv_scp_train, model0_dir)
|
||||
chtk.flat_start(hcompv_scp_train, model_mono0_dir)
|
||||
|
||||
# create macros.
|
||||
vFloors = os.path.join(model0_dir, 'vFloors')
|
||||
# make macros.
|
||||
vFloors = os.path.join(model_mono0_dir, 'vFloors')
|
||||
if os.path.exists(vFloors):
|
||||
chtk.create_macros(vFloors)
|
||||
chtk.make_macros(vFloors)
|
||||
|
||||
# allocate mean & variance to all phones in the phone list
|
||||
print('>>> allocating mean & variance to all phones in the phone list...')
|
||||
chtk.create_hmmdefs(
|
||||
os.path.join(model0_dir, proto_name),
|
||||
os.path.join(model0_dir, 'hmmdefs')
|
||||
)
|
||||
chtk.make_hmmdefs(model_mono0_dir)
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
|
||||
## ======================= train model without short pause =======================
|
||||
if train_model_without_sp:
|
||||
print('==== train model without sp ====')
|
||||
if train_monophone_without_sp:
|
||||
print('==== train monophone without sp ====')
|
||||
|
||||
timer_start = time.time()
|
||||
niter = chtk.re_estimation_until_saturated(
|
||||
model1_dir,
|
||||
model0_dir, improvement_threshold, hcompv_scp_train,
|
||||
model_mono1_dir,
|
||||
model_mono0_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,
|
||||
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))
|
||||
@ -272,74 +351,216 @@ if add_sp:
|
||||
|
||||
# make model with sp.
|
||||
print('>>> adding sp state to the last model in the previous step...')
|
||||
fh.make_new_directory(model1sp_dir, existing_dir='leave')
|
||||
niter = chtk.get_niter_max(model1_dir)
|
||||
modeln_dir_pre = os.path.join(model1_dir, 'iter'+str(niter))
|
||||
modeln_dir = os.path.join(model1sp_dir, 'iter0')
|
||||
chtk.add_sp(modeln_dir_pre, modeln_dir)
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
fh.make_new_directory(model_mono1sp_dir, existing_dir='leave')
|
||||
niter = chtk.get_niter_max(model_mono1_dir)
|
||||
modeln_dir_pre = os.path.join(model_mono1_dir, 'iter'+str(niter))
|
||||
modeln_dir = os.path.join(model_mono1sp_dir, 'iter0')
|
||||
|
||||
chtk.add_sp(modeln_dir_pre, modeln_dir)
|
||||
|
||||
print('>>> re-estimation...')
|
||||
niter = chtk.re_estimation_until_saturated(
|
||||
model1sp_dir, modeln_dir, improvement_threshold, hcompv_scp_train,
|
||||
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,
|
||||
lexicon_file=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
|
||||
mlf_file=mlf_file_train_with_sp,
|
||||
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_model_with_re_aligned_mlf:
|
||||
print('==== traina 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(model1sp_dir)
|
||||
modeln_dir = os.path.join(model1sp_dir, 'iter'+str(niter))
|
||||
niter = chtk.get_niter_max(model_mono1sp_dir)
|
||||
modeln_dir = os.path.join(model_mono1sp_dir, 'iter'+str(niter))
|
||||
chtk.make_aligned_label(
|
||||
os.path.join(modeln_dir, 'macros'),
|
||||
os.path.join(modeln_dir, 'hmmdefs'),
|
||||
mlf_file_train_aligned,
|
||||
os.path.join(label_dir, 'train_word.mlf'),
|
||||
mlf_file_train_word,
|
||||
hcompv_scp_train)
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
chtk.fix_mlf(mlf_file_train_aligned)
|
||||
|
||||
print('>>> updating the script file... ')
|
||||
chtk.update_script_file(
|
||||
mlf_file_train_aligned,
|
||||
mlf_file_train_with_sp,
|
||||
hcompv_scp_train,
|
||||
hcompv_scp_train_updated)
|
||||
|
||||
print('>>> re-estimation... ')
|
||||
timer_start = time.time()
|
||||
fh.make_new_directory(model1sp2_dir, existing_dir='leave')
|
||||
niter = chtk.get_niter_max(model1sp_dir)
|
||||
fh.make_new_directory(model_mono1sp2_dir, existing_dir='leave')
|
||||
niter = chtk.get_niter_max(model_mono1sp_dir)
|
||||
niter = chtk.re_estimation_until_saturated(
|
||||
model1sp2_dir,
|
||||
os.path.join(model1sp_dir, 'iter'+str(niter)),
|
||||
model_mono1sp2_dir,
|
||||
os.path.join(model_mono1sp_dir, 'iter'+str(niter)),
|
||||
improvement_threshold,
|
||||
hcompv_scp_train,
|
||||
hcompv_scp_train_updated,
|
||||
os.path.join(htk_stimmen_dir, 'mfc'),
|
||||
'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'),
|
||||
mlf_file=mlf_file_train_aligned,
|
||||
lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
|
||||
model_type='monophone_with_sp'
|
||||
)
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
|
||||
## ======================= increase mixture =======================
|
||||
if increase_mixture:
|
||||
print('==== increase mixture ====')
|
||||
timer_start = time.time()
|
||||
for nmix in [2, 4, 8, 16]:
|
||||
if nmix == 2:
|
||||
modeln_dir_ = model_mono1sp2_dir
|
||||
else:
|
||||
modeln_dir_ = os.path.join(model_dir, 'mono'+str(nmix_))
|
||||
modeln_dir = os.path.join(model_dir, 'mono'+str(nmix))
|
||||
|
||||
print('mixture: {}'.format(nmix))
|
||||
fh.make_new_directory(modeln_dir, existing_dir='delete')
|
||||
niter = chtk.get_niter_max(modeln_dir_)
|
||||
chtk.increase_mixture(
|
||||
os.path.join(modeln_dir_, 'iter'+str(niter), 'hmmdefs'),
|
||||
nmix,
|
||||
os.path.join(modeln_dir, 'iter0'),
|
||||
model_type='monophone_with_sp')
|
||||
shutil.copy2(os.path.join(modeln_dir_, 'iter'+str(niter), 'macros'),
|
||||
os.path.join(modeln_dir, 'iter0', 'macros'))
|
||||
|
||||
#improvement_threshold = -10
|
||||
niter = chtk.re_estimation_until_saturated(
|
||||
modeln_dir,
|
||||
os.path.join(modeln_dir_, 'iter0'),
|
||||
improvement_threshold,
|
||||
hcompv_scp_train_updated,
|
||||
os.path.join(htk_stimmen_dir, 'mfc'),
|
||||
'mfc',
|
||||
os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
|
||||
mlf_file=mlf_file_train_aligned,
|
||||
lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
|
||||
model_type='monophone_with_sp'
|
||||
)
|
||||
nmix_ = nmix
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
|
||||
## ======================= train triphone =======================
|
||||
print('>>> making triphone list... ')
|
||||
chtk.make_triphonelist(
|
||||
mlf_file_train_aligned,
|
||||
triphone_mlf)
|
||||
|
||||
if train_triphone:
|
||||
triphone_mlf = os.path.join(default.htk_dir, 'label', 'train_triphone.mlf')
|
||||
macros = os.path.join(model_dir, 'hmm1_tri', 'iter0', 'macros')
|
||||
hmmdefs = os.path.join(model_dir, 'hmm1_tri', 'iter0', 'hmmdefs')
|
||||
model_out_dir = os.path.join(model_dir, 'hmm1_tri', 'iter1')
|
||||
run_command([
|
||||
'HERest', '-B',
|
||||
'-C', config_train,
|
||||
'-I', triphone_mlf,
|
||||
'-t', '250.0', '150.0', '1000.0',
|
||||
'-s', 'stats'
|
||||
'-S', hcompv_scp_train,
|
||||
'-H', macros,
|
||||
'-H', hmmdefs,
|
||||
'-M', model_out_dir,
|
||||
os.path.join(config_dir, 'triphonelist.txt')
|
||||
])
|
||||
print('==== train triphone model ====')
|
||||
timer_start = time.time()
|
||||
|
||||
print('>>> init triphone model... ')
|
||||
niter = chtk.get_niter_max(model_mono1sp2_dir)
|
||||
fh.make_new_directory(os.path.join(model_tri1_dir, 'iter0'), existing_dir='leave')
|
||||
chtk.init_triphone(
|
||||
os.path.join(model_mono1sp2_dir, 'iter'+str(niter)),
|
||||
os.path.join(model_tri1_dir, 'iter0')
|
||||
)
|
||||
|
||||
print('>>> re-estimation... ')
|
||||
## I wanted to train until satulated:
|
||||
#niter = chtk.re_estimation_until_saturated(
|
||||
# model_tri1_dir,
|
||||
# os.path.join(model_tri1_dir, 'iter0'),
|
||||
# improvement_threshold,
|
||||
# hcompv_scp_train_updated,
|
||||
# os.path.join(htk_stimmen_dir, 'mfc'),
|
||||
# 'mfc',
|
||||
# os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
|
||||
# mlf_file=triphone_mlf,
|
||||
# lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
|
||||
# model_type='triphone'
|
||||
# )
|
||||
#
|
||||
# but because the data size is limited, some triphone cannot be trained and received the error:
|
||||
# ERROR [+8231] GetHCIModel: Cannot find hmm [i:-]r[+???]
|
||||
# therefore only two times re-estimation is performed.
|
||||
output_dir = model_tri1_dir
|
||||
for niter in range(1, 4):
|
||||
hmm_n = 'iter' + str(niter)
|
||||
hmm_n_pre = 'iter' + str(niter-1)
|
||||
_modeln_dir = os.path.join(output_dir, hmm_n)
|
||||
_modeln_dir_pre = os.path.join(output_dir, hmm_n_pre)
|
||||
|
||||
fh.make_new_directory(_modeln_dir, 'leave')
|
||||
chtk.re_estimation(
|
||||
os.path.join(_modeln_dir_pre, 'hmmdefs'),
|
||||
_modeln_dir,
|
||||
hcompv_scp_train_updated,
|
||||
mlf_file=triphone_mlf,
|
||||
macros=os.path.join(_modeln_dir_pre, 'macros'),
|
||||
model_type='triphone')
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
||||
|
||||
|
||||
## ======================= train tied-state triphones =======================
|
||||
if train_triphone_tied:
|
||||
print('==== train tied-state triphones ====')
|
||||
timer_start = time.time()
|
||||
|
||||
print('>>> making lexicon for triphone... ')
|
||||
chtk.make_lexicon_triphone(phonelist_full_txt, lexicon_htk_triphone)
|
||||
chtk.combine_phonelists(phonelist_full_txt)
|
||||
|
||||
print('>>> making a tree header... ')
|
||||
fame_phonetics.make_quests_hed(quests_hed)
|
||||
stats = os.path.join(r'c:\OneDrive\Research\rug\experiments\acoustic_model\fame\htk\model\tri1\iter3', 'stats')
|
||||
chtk.make_tree_header(tree_hed, quests_hed, stats, config_dir)
|
||||
|
||||
print('>>> init triphone model... ')
|
||||
niter = chtk.get_niter_max(model_tri1_dir)
|
||||
fh.make_new_directory(os.path.join(model_tri1tied_dir, 'iter0'), existing_dir='leave')
|
||||
chtk.init_triphone(
|
||||
os.path.join(model_tri1_dir, 'iter'+str(niter)),
|
||||
os.path.join(model_tri1tied_dir, 'iter0'),
|
||||
tied=True)
|
||||
|
||||
# I wanted to train until satulated:
|
||||
#niter = chtk.re_estimation_until_saturated(
|
||||
# model_tri1tied_dir,
|
||||
# os.path.join(model_tri1tied_dir, 'iter0'),
|
||||
# improvement_threshold,
|
||||
# hcompv_scp_train_updated,
|
||||
# os.path.join(htk_stimmen_dir, 'mfc'),
|
||||
# 'mfc',
|
||||
# os.path.join(htk_stimmen_dir, 'word_lattice.ltc'),
|
||||
# mlf_file=triphone_mlf,
|
||||
# lexicon=os.path.join(htk_stimmen_dir, 'lexicon_recognition.dic'),
|
||||
# model_type='triphone'
|
||||
# )
|
||||
#
|
||||
# but because the data size is limited, some triphone cannot be trained and received the error:
|
||||
# ERROR [+8231] GetHCIModel: Cannot find hmm [i:-]r[+???]
|
||||
# therefore only 3 times re-estimation is performed.
|
||||
output_dir = model_tri1tied_dir
|
||||
for niter in range(1, 4):
|
||||
hmm_n = 'iter' + str(niter)
|
||||
hmm_n_pre = 'iter' + str(niter-1)
|
||||
_modeln_dir = os.path.join(output_dir, hmm_n)
|
||||
_modeln_dir_pre = os.path.join(output_dir, hmm_n_pre)
|
||||
|
||||
fh.make_new_directory(_modeln_dir, 'leave')
|
||||
chtk.re_estimation(
|
||||
os.path.join(_modeln_dir_pre, 'hmmdefs'),
|
||||
_modeln_dir,
|
||||
hcompv_scp_train_updated,
|
||||
mlf_file=triphone_mlf,
|
||||
macros=os.path.join(_modeln_dir_pre, 'macros'),
|
||||
model_type='triphone')
|
||||
|
||||
print("elapsed time: {}".format(time.time() - timer_start))
|
@ -109,30 +109,30 @@ np.save(os.path.join('phoneset', 'fame_ipa2asr.npy'), translation_key_ipa2asr)
|
||||
|
||||
|
||||
## check which letters are not coded in ascii.
|
||||
print('asr phones which cannot be coded in ascii:\n')
|
||||
for i in fame_asr.phoneset_short:
|
||||
try:
|
||||
i_encoded = i.encode("ascii")
|
||||
#print("{0} --> {1}".format(i, i.encode("ascii")))
|
||||
except UnicodeEncodeError:
|
||||
print(">>> {}".format(i))
|
||||
#print('asr phones which cannot be coded in ascii:\n')
|
||||
#for i in fame_asr.phoneset_short:
|
||||
# try:
|
||||
# i_encoded = i.encode("ascii")
|
||||
# #print("{0} --> {1}".format(i, i.encode("ascii")))
|
||||
# except UnicodeEncodeError:
|
||||
# print(">>> {}".format(i))
|
||||
|
||||
print("letters in the scripts which is not coded in ascii:\n")
|
||||
for dataset in ['train', 'devel', 'test']:
|
||||
timer_start = time.time()
|
||||
#print("letters in the scripts which is not coded in ascii:\n")
|
||||
#for dataset in ['train', 'devel', 'test']:
|
||||
# timer_start = time.time()
|
||||
|
||||
script_list = os.path.join(default.fame_dir, 'data', dataset, 'text')
|
||||
with open(script_list, "rt", encoding="utf-8") as fin:
|
||||
scripts = fin.read().split('\n')
|
||||
# script_list = os.path.join(default.fame_dir, 'data', dataset, 'text')
|
||||
# with open(script_list, "rt", encoding="utf-8") as fin:
|
||||
# scripts = fin.read().split('\n')
|
||||
|
||||
for line in scripts:
|
||||
sentence = ' '.join(line.split(' ')[1:])
|
||||
sentence_htk = fame_functions.word2htk(sentence)
|
||||
# for line in scripts:
|
||||
# sentence = ' '.join(line.split(' ')[1:])
|
||||
# sentence_htk = fame_functions.word2htk(sentence)
|
||||
|
||||
#if len(re.findall(r'[âêôûč\'àéèúćäëïöü]', sentence))==0:
|
||||
try:
|
||||
sentence_htk = bytes(sentence_htk, 'ascii')
|
||||
except UnicodeEncodeError:
|
||||
print(sentence)
|
||||
print(sentence_htk)
|
||||
# #if len(re.findall(r'[âêôûč\'àéèúćäëïöü]', sentence))==0:
|
||||
# try:
|
||||
# sentence_htk = bytes(sentence_htk, 'ascii')
|
||||
# except UnicodeEncodeError:
|
||||
# print(sentence)
|
||||
# print(sentence_htk)
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
## this script should be used only by Aki Kunikoshi.
|
||||
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import argparse
|
||||
import json
|
||||
|
||||
from novoapi.backend import session
|
||||
|
||||
import os
|
||||
#os.chdir(r'C:\Users\Aki\source\repos\acoustic_model\acoustic_model')
|
||||
import defaultfiles as default
|
||||
import convert_phoneset
|
||||
|
||||
|
||||
def load_phonset():
|
||||
translation_key_ipa2novo70 = dict()
|
||||
translation_key_novo702ipa = dict()
|
||||
|
||||
def load_novo70_phoneset():
|
||||
#phonelist_novo70_ = pd.ExcelFile(default.phonelist_novo70_xlsx)
|
||||
#df = pd.read_excel(phonelist_novo70_, 'list')
|
||||
## *_simple includes columns which has only one phone in.
|
||||
@ -23,21 +22,23 @@ def load_phonset():
|
||||
# print('{0}:{1}'.format(ipa, novo70))
|
||||
# translation_key[ipa] = novo70
|
||||
#phonelist_novo70 = np.unique(list(df['novo70_simple']))
|
||||
novo70_phoneset = pd.read_csv(default.novo70_phoneset, delimiter='\t', header=None, encoding="utf-8")
|
||||
novo70_phoneset.rename(columns={0: 'novo70', 1: 'ipa', 2: 'description'}, inplace=True)
|
||||
|
||||
phoneset_ipa = []
|
||||
phoneset_novo70 = []
|
||||
with open(default.novo70_phoneset, "rt", encoding="utf-8") as fin:
|
||||
lines = fin.read()
|
||||
lines = lines.split('\n')
|
||||
for line in lines:
|
||||
words = line.split('\t')
|
||||
if len(words) > 1:
|
||||
novo70 = words[0]
|
||||
ipa = words[1]
|
||||
phoneset_ipa.append(ipa)
|
||||
phoneset_novo70.append(novo70)
|
||||
translation_key_ipa2novo70[ipa] = novo70
|
||||
translation_key_novo702ipa[novo70] = ipa
|
||||
#phoneset_ipa = []
|
||||
#phoneset_novo70 = []
|
||||
#with open(default.novo70_phoneset, "rt", encoding="utf-8") as fin:
|
||||
# lines = fin.read()
|
||||
# lines = lines.split('\n')
|
||||
# for line in lines:
|
||||
# words = line.split('\t')
|
||||
# if len(words) > 1:
|
||||
# novo70 = words[0]
|
||||
# ipa = words[1]
|
||||
# phoneset_ipa.append(ipa)
|
||||
# phoneset_novo70.append(novo70)
|
||||
# translation_key_ipa2novo70[ipa] = novo70
|
||||
# translation_key_novo702ipa[novo70] = ipa
|
||||
|
||||
# As per Nederlandse phoneset_aki.xlsx recieved from David
|
||||
# [ɔː] oh / ohr # from ipa->novo70, only oh is used.
|
||||
@ -47,15 +48,26 @@ def load_phonset():
|
||||
# [ɛː] eh
|
||||
# [w] wv in IPA written as ʋ.
|
||||
extra_ipa = ['ɔː', 'ɪː', 'iː', 'œː', 'ɛː', 'ʋ']
|
||||
extra_novo70 = ['oh', 'ih', 'iy', 'uh', 'eh', 'wv']
|
||||
for ipa, novo70 in zip(extra_ipa, extra_novo70):
|
||||
phoneset_ipa.append(ipa)
|
||||
phoneset_novo70.append(novo70)
|
||||
extra_novo70 = ['oh', 'ih', 'iy', 'uh', 'eh', 'wv']
|
||||
|
||||
phoneset_ipa = list(novo70_phoneset['ipa'])
|
||||
phoneset_ipa.extend(extra_ipa)
|
||||
phoneset_ipa = [i.replace('ː', ':') for i in phoneset_ipa]
|
||||
|
||||
phoneset_novo70 = list(novo70_phoneset['novo70'])
|
||||
phoneset_novo70.extend(extra_novo70)
|
||||
phoneset_novo70 = [i.replace('ː', ':') for i in phoneset_novo70]
|
||||
|
||||
translation_key_ipa2novo70 = dict()
|
||||
translation_key_novo702ipa = dict()
|
||||
for ipa, novo70 in zip(phoneset_ipa, phoneset_novo70):
|
||||
#phoneset_ipa.append(ipa)
|
||||
#phoneset_novo70.append(novo70)
|
||||
translation_key_ipa2novo70[ipa] = novo70
|
||||
translation_key_novo702ipa[novo70] = ipa
|
||||
|
||||
translation_key_novo702ipa['ohr'] = 'ɔː'
|
||||
translation_key_novo702ipa['ihr'] = 'ɪː'
|
||||
translation_key_novo702ipa['ohr'] = 'ɔ:'
|
||||
translation_key_novo702ipa['ihr'] = 'ɪ:'
|
||||
|
||||
phoneset_ipa = np.unique(phoneset_ipa)
|
||||
phoneset_novo70 = np.unique(phoneset_novo70)
|
||||
@ -63,25 +75,6 @@ def load_phonset():
|
||||
return phoneset_ipa, phoneset_novo70, translation_key_ipa2novo70, translation_key_novo702ipa
|
||||
|
||||
|
||||
def multi_character_tokenize(line, multi_character_tokens):
|
||||
"""
|
||||
Tries to match one of the tokens in multi_character_tokens at each position of line,
|
||||
starting at position 0,
|
||||
if so tokenizes and eats that token. Otherwise tokenizes a single character.
|
||||
|
||||
Copied from forced_alignment.convert_phone_set.py
|
||||
"""
|
||||
while line != '':
|
||||
for token in multi_character_tokens:
|
||||
if line.startswith(token) and len(token) > 0:
|
||||
yield token
|
||||
line = line[len(token):]
|
||||
break
|
||||
else:
|
||||
yield line[:1]
|
||||
line = line[1:]
|
||||
|
||||
|
||||
def split_ipa(line):
|
||||
"""
|
||||
Split a line by IPA phones.
|
||||
@ -89,13 +82,16 @@ def split_ipa(line):
|
||||
:param string line: one line written in IPA.
|
||||
:return string lineSeperated: the line splitted in IPA phone.
|
||||
"""
|
||||
phoneset_ipa, _, _, _ = load_novo70_phoneset()
|
||||
#multi_character_phones = [i for i in phoneset_ipa if len(i) > 1]
|
||||
#multi_character_phones.sort(key=len, reverse=True)
|
||||
#multi_character_phones = [
|
||||
# # IPAs in CGN.
|
||||
# u'ʌu', u'ɛi', u'œy', u'aː', u'eː', u'iː', u'oː', u'øː', u'ɛː', u'œː', u'ɔː', u'ɛ̃ː', u'ɑ̃ː', u'ɔ̃ː', u'œ̃', u'ɪː'
|
||||
# ]
|
||||
#return [phone for phone in multi_character_tokenize(line.strip(), multi_character_phones)]
|
||||
|
||||
multi_character_phones = [
|
||||
# IPAs in CGN.
|
||||
u'ʌu', u'ɛi', u'œy', u'aː', u'eː', u'iː', u'oː', u'øː', u'ɛː', u'œː', u'ɔː', u'ɛ̃ː', u'ɑ̃ː', u'ɔ̃ː', u'œ̃', u'ɪː'
|
||||
]
|
||||
|
||||
return [phone for phone in multi_character_tokenize(line.strip(), multi_character_phones)]
|
||||
return convert_phoneset.split_word(line, phoneset_ipa)
|
||||
|
||||
|
||||
def split_novo70(line):
|
||||
@ -104,30 +100,33 @@ def split_novo70(line):
|
||||
:param string line: one line written in novo70.
|
||||
:return string lineSeperated: the line splitted by novo70 phones.
|
||||
"""
|
||||
_, phoneset_novo70, _, _ = load_phonset()
|
||||
multi_character_phones = [p for p in phoneset_novo70 if len(p) > 1]
|
||||
multi_character_phones = sorted(multi_character_phones, key=len, reverse=True)
|
||||
_, phoneset_novo70, _, _ = load_novo70_phoneset()
|
||||
#multi_character_phones = [p for p in phoneset_novo70 if len(p) > 1]
|
||||
#multi_character_phones = sorted(multi_character_phones, key=len, reverse=True)
|
||||
multi_character_phones = convert_phoneset.extract_multi_character_phones(phoneset_novo70)
|
||||
|
||||
return ['sp' if phone == ' ' else phone
|
||||
for phone in multi_character_tokenize(line.strip(), multi_character_phones)]
|
||||
|
||||
|
||||
def novo702ipa(tokens):
|
||||
pronunciation = []
|
||||
_, _, _, translation_key = load_phonset()
|
||||
for phone in split_novo70(tokens):
|
||||
pronunciation.append(translation_key.get(phone, phone))
|
||||
return ' '.join(pronunciation)
|
||||
def novo702ipa(line):
|
||||
#pronunciation = []
|
||||
_, _, _, translation_key = load_novo70_phoneset()
|
||||
#for phone in split_novo70(tokens):
|
||||
# pronunciation.append(translation_key.get(phone, phone))
|
||||
#return ' '.join(pronunciation)
|
||||
return ' '.join(convert_phoneset.convert_phoneset(split_novo70(line), translation_key))
|
||||
|
||||
|
||||
# numbering of novo70 should be checked.
|
||||
def ipa2novo70(tokens):
|
||||
pronunciation = []
|
||||
_, _, translation_key, _ = load_phonset()
|
||||
for phone in split_ipa(tokens):
|
||||
pronunciation.append(translation_key.get(phone, phone))
|
||||
return ' '.join(pronunciation)
|
||||
|
||||
def ipa2novo70(line):
|
||||
#pronunciation = []
|
||||
_, _, translation_key, _ = load_novo70_phoneset()
|
||||
#for phone in split_ipa(tokens):
|
||||
# pronunciation.append(translation_key.get(phone, phone))
|
||||
#return ' '.join(pronunciation)
|
||||
return ' '.join(convert_phoneset.convert_phoneset(split_ipa(line), translation_key))
|
||||
|
||||
|
||||
def make_grammar(word, pronunciation_ipa):
|
||||
"""
|
||||
@ -174,6 +173,9 @@ def forced_alignment(wav_file, word, pronunciation_ipa):
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--user", default='martijn.wieling')
|
||||
p.add_argument("--password", default='xxxxxx')
|
||||
|
||||
|
||||
|
||||
args = p.parse_args()
|
||||
|
||||
rec = session.Recognizer(grammar_version="1.0", lang="nl", snodeid=101, user=args.user, password=args.password, keepopen=True) # , modeldir=modeldir)
|
||||
@ -194,6 +196,25 @@ def result2pronunciation(result, word):
|
||||
return pronunciation_ipa, pronunciation_novo70, llh
|
||||
|
||||
|
||||
def phones_not_in_novo70(ipa):
|
||||
""" extract phones which is not in novo70 phoneset. """
|
||||
|
||||
phoneset_ipa, _, _, _ = load_novo70_phoneset()
|
||||
|
||||
# As per Nederlandse phoneset_aki.xlsx recieved from David
|
||||
# [ɔː] oh / ohr
|
||||
# [ɪː] ih / ihr
|
||||
# [iː] iy
|
||||
# [œː] uh
|
||||
# [ɛː] eh
|
||||
# [w] wv in IPA written as ʋ.
|
||||
david_suggestion = ['ɔː', 'ɪː', 'iː', 'œː', 'ɛː', 'w']
|
||||
|
||||
return [phone for phone in split_ipa(ipa)
|
||||
if not phone in phoneset_ipa and not phone in david_suggestion]
|
||||
|
||||
|
||||
if __name__ == 'main':
|
||||
pronunciation_ipa = ['rø:s', 'mɑn', 'mɑntsjə']
|
||||
grammar = make_grammar('reus', pronunciation_ipa)
|
||||
#grammar = make_grammar('reus', pronunciation_ipa)
|
||||
phoneset_ipa, phoneset_novo70, translation_key_ipa2novo70, translation_key_novo702ipa = load_novo70_phoneset()
|
@ -80,8 +80,11 @@ def phone_reduction(phones):
|
||||
Args:
|
||||
phones (list): list of phones.
|
||||
"""
|
||||
if sum([phone in phones for phone in phones_to_be_removed]) != 0:
|
||||
print('input includes phone(s) which is not defined in fame_asr.')
|
||||
print('those phone(s) are removed.')
|
||||
return [reduction_key.get(i, i) for i in phones
|
||||
if not i in phones_to_be_removed]
|
||||
if i not in phones_to_be_removed]
|
||||
|
||||
phoneset_short = list(set(phone_reduction(phoneset)))
|
||||
phoneset_short.sort()
|
||||
@ -96,7 +99,7 @@ translation_key_asr2htk = {
|
||||
'ṷ': 'u_',
|
||||
|
||||
# on the analogy of German umlaut, 'e' is used.
|
||||
'ö': 'oe', 'ö:': 'oe:',
|
||||
'ö': 'oe', 'ö:': 'oe:', ''
|
||||
'ü': 'ue', 'ü:': 'ue:',
|
||||
|
||||
# on the analogy of Chinese...
|
||||
|
@ -61,7 +61,7 @@ phoneset = [
|
||||
'ɔⁿ',
|
||||
'ɔ:',
|
||||
'ɔ:ⁿ',
|
||||
#'ɔ̈', # not included in lex.ipa
|
||||
'ɔ̈', # not included in lex.ipa
|
||||
'ɔ̈.',
|
||||
'ɔ̈:',
|
||||
|
||||
|
197
acoustic_model/phoneset/fame_phonetics.py
Normal file
197
acoustic_model/phoneset/fame_phonetics.py
Normal file
@ -0,0 +1,197 @@
|
||||
import sys
|
||||
import os
|
||||
os.chdir(r'C:\Users\Aki\source\repos\acoustic_model\acoustic_model')
|
||||
|
||||
import fame_functions
|
||||
from phoneset import fame_ipa, fame_asr
|
||||
import convert_phoneset
|
||||
|
||||
|
||||
## general
|
||||
stop = 'p, b, t, d, k, g'
|
||||
nasal = 'm, n, ŋ'
|
||||
fricative = 's, z, f, v, h, x, j'
|
||||
liquid = 'l, r'
|
||||
vowel = 'a, a:, e:, i, i:, i̯, o, o:, u, u:, ṷ, ö, ö:, ü, ü:, ɔ, ɔ:, ɔ̈, ə, ɛ, ɛ:, ɪ, ɪ:'
|
||||
|
||||
## consonant
|
||||
c_front = 'p, b, m, f, v'
|
||||
c_central = 't, d, n, s, z, l, r'
|
||||
c_back = 'k, g, ŋ, h, x, j'
|
||||
|
||||
fortis = 'p, t, k, f, s'
|
||||
lenis = 'b, d, g, v, z, j'
|
||||
neither_fortis_nor_lenis = 'm, n, ŋ, h, l, r, x'
|
||||
|
||||
coronal = 't, d, n, s, z, l, r, j'
|
||||
non_coronal = 'p, b, m, k, g, ŋ, f, v, h, x'
|
||||
|
||||
anterior = 'p, b, m, t, d, n, f, v, s, z, l'
|
||||
non_anterior = 'k, g, ŋ, h, x, j, r'
|
||||
|
||||
continuent = 'm, n, ŋ, f, v, s, z, h, l, r'
|
||||
non_continuent = 'p, b, t, d, k, g, x, j'
|
||||
|
||||
strident = 's, z, j'
|
||||
non_strident = 'f, v, h'
|
||||
unstrident = 'p, b, t, d, m, n, ŋ, k, g, r, x'
|
||||
|
||||
glide = 'h, l, r'
|
||||
syllabic = 'm, l, ŋ'
|
||||
|
||||
unvoiced = 'p, t, k, s, f, x, h'
|
||||
voiced = 'b, d, g, z, v, m, n, ŋ, l, r, j'
|
||||
|
||||
#affricate: ???
|
||||
non_affricate = 's, z, f, v'
|
||||
|
||||
voiced_stop = 'b, d, g'
|
||||
unvoiced_stop = 'p, t, k'
|
||||
front_stop = 'p, b'
|
||||
central_stop = 't, d'
|
||||
back_stop = 'k, g'
|
||||
|
||||
voiced_fricative = 'z, v'
|
||||
unvoiced_fricative = 's, f'
|
||||
front_fricative = 'f, v'
|
||||
central_fricative = 's, z'
|
||||
back_fricative = 'j'
|
||||
|
||||
|
||||
## vowel
|
||||
v_front = 'i, i:, i̯, ɪ, ɪ:, e:, ə, ɛ, ɛ:, a, a:'
|
||||
v_central = 'ə, ɛ, ɛ:, a, a:'
|
||||
v_back = 'u, u:, ü, ü:, ṷ, ɔ, ɔ:, ɔ̈, ö, ö:, o, o:'
|
||||
|
||||
long = 'a:, e:, i:, o:, u:, ö:, ü:, ɔ:, ɛ:, ɪ:'
|
||||
short = 'a, i, i̯, o, u, ṷ, ö, ü, ɔ, ɔ̈, ə, ɛ, ɪ'
|
||||
|
||||
#Dipthong: ???
|
||||
#Front-Start: ???
|
||||
#Fronting: ???
|
||||
|
||||
high = 'i, i:, i̯, ɪ, ɪ: u, u:, ṷ, ə, e:, o, o:, ö, ö:, ü, ü:'
|
||||
medium = 'e:, ə, ɛ, ɛ:, ɔ, ɔ:, ɔ̈, o, o:, ö, ö:'
|
||||
low = 'a, a:, ɛ, ɛ:, ɔ, ɔ:, ɔ̈'
|
||||
|
||||
rounded = 'a, a:, o, o:, u, u:, ṷ, ö, ö:, ü, ü:, ɔ, ɔ:, ɔ̈'
|
||||
unrounded = 'i, i:, i̯, e:, ə, ɛ, ɛ:, ɪ, ɪ:'
|
||||
|
||||
i_vowel = 'i, i:, i̯, ɪ, ɪ:'
|
||||
e_vowel = 'e:,ə, ɛ, ɛ:'
|
||||
a_vowel = 'a, a:'
|
||||
o_vowel = 'o, o:, ö, ö:, ɔ, ɔ:, ɔ̈'
|
||||
u_vowel = 'u, u:, ṷ, ü, ü:'
|
||||
|
||||
## htk phoneset
|
||||
phoneset = fame_asr.phoneset_htk
|
||||
|
||||
## convert ipa group to htk format for quests.hed.
|
||||
def _ipa2quest(R_or_L, ipa_text):
|
||||
assert R_or_L in ['R', 'L'], print('the first argument should be either R or L.')
|
||||
ipa_list = ipa_text.replace(' ', '').split(',')
|
||||
if R_or_L == 'R':
|
||||
quests_list = ['*+' + fame_functions.ipa2htk(ipa) for ipa in ipa_list]
|
||||
else:
|
||||
quests_list = [fame_functions.ipa2htk(ipa) + '-*' for ipa in ipa_list]
|
||||
return ','.join(quests_list)
|
||||
|
||||
|
||||
def make_quests_hed(quest_hed):
|
||||
def _add_quests_item(R_or_L, item_name_, ipa_text):
|
||||
assert R_or_L in ['R', 'L'], print('the first argument should be either R or L.')
|
||||
item_name = R_or_L + '_' + item_name_
|
||||
with open(quest_hed, 'ab') as f:
|
||||
f.write(bytes('QS "' + item_name + '"\t{ ' + _ipa2quest(R_or_L, ipa_text) + ' }\n', 'ascii'))
|
||||
|
||||
if os.path.exists(quest_hed):
|
||||
os.remove(quest_hed)
|
||||
|
||||
for R_or_L in ['R', 'L']:
|
||||
_add_quests_item(R_or_L, 'NonBoundary', '*')
|
||||
_add_quests_item(R_or_L, 'Silence', 'sil')
|
||||
|
||||
_add_quests_item(R_or_L, 'Stop', stop)
|
||||
_add_quests_item(R_or_L, 'Nasal', nasal)
|
||||
_add_quests_item(R_or_L, 'Fricative', fricative)
|
||||
_add_quests_item(R_or_L, 'Liquid', liquid)
|
||||
_add_quests_item(R_or_L, 'Vowel', vowel)
|
||||
|
||||
_add_quests_item(R_or_L, 'C-Front', c_front)
|
||||
_add_quests_item(R_or_L, 'C-Central', c_central)
|
||||
_add_quests_item(R_or_L, 'C-Back', c_back)
|
||||
|
||||
_add_quests_item(R_or_L, 'V-Front', v_front)
|
||||
_add_quests_item(R_or_L, 'V-Central', v_central)
|
||||
_add_quests_item(R_or_L, 'V-Back', v_back)
|
||||
|
||||
_add_quests_item(R_or_L, 'Front', c_front + v_front)
|
||||
_add_quests_item(R_or_L, 'Central', c_central + v_central)
|
||||
_add_quests_item(R_or_L, 'Back', c_front + v_back)
|
||||
|
||||
_add_quests_item(R_or_L, 'Fortis', fortis)
|
||||
_add_quests_item(R_or_L, 'Lenis', lenis)
|
||||
_add_quests_item(R_or_L, 'UnFortLenis', neither_fortis_nor_lenis)
|
||||
|
||||
_add_quests_item(R_or_L, 'Coronal', coronal)
|
||||
_add_quests_item(R_or_L, 'NonCoronal', non_coronal)
|
||||
|
||||
_add_quests_item(R_or_L, 'Anterior', anterior)
|
||||
_add_quests_item(R_or_L, 'NonAnterior', non_anterior)
|
||||
|
||||
_add_quests_item(R_or_L, 'Continuent', continuent)
|
||||
_add_quests_item(R_or_L, 'NonContinuent', non_continuent)
|
||||
|
||||
_add_quests_item(R_or_L, 'Strident', strident)
|
||||
_add_quests_item(R_or_L, 'NonStrident', non_strident)
|
||||
_add_quests_item(R_or_L, 'UnStrident', unstrident)
|
||||
|
||||
_add_quests_item(R_or_L, 'Glide', glide)
|
||||
_add_quests_item(R_or_L, 'Syllabic', syllabic)
|
||||
|
||||
_add_quests_item(R_or_L, 'Unvoiced-Cons', unvoiced)
|
||||
_add_quests_item(R_or_L, 'Voiced-Cons', voiced)
|
||||
_add_quests_item(R_or_L, 'Unvoiced-All', unvoiced + ', sil')
|
||||
|
||||
_add_quests_item(R_or_L, 'Long', long)
|
||||
_add_quests_item(R_or_L, 'Short', short)
|
||||
|
||||
#_add_quests_item(R_or_L, 'Dipthong', xxx)
|
||||
#_add_quests_item(R_or_L, 'Front-Start', xxx)
|
||||
#_add_quests_item(R_or_L, 'Fronting', xxx)
|
||||
|
||||
_add_quests_item(R_or_L, 'High', high)
|
||||
_add_quests_item(R_or_L, 'Medium', medium)
|
||||
_add_quests_item(R_or_L, 'Low', low)
|
||||
|
||||
_add_quests_item(R_or_L, 'Rounded', rounded)
|
||||
_add_quests_item(R_or_L, 'UnRounded', unrounded)
|
||||
|
||||
#_add_quests_item(R_or_L, 'Affricative', rounded)
|
||||
_add_quests_item(R_or_L, 'NonAffricative', non_affricate)
|
||||
|
||||
_add_quests_item(R_or_L, 'IVowel', i_vowel)
|
||||
_add_quests_item(R_or_L, 'EVowel', e_vowel)
|
||||
_add_quests_item(R_or_L, 'AVowel', a_vowel)
|
||||
_add_quests_item(R_or_L, 'OVowel', o_vowel)
|
||||
_add_quests_item(R_or_L, 'UVowel', u_vowel)
|
||||
|
||||
_add_quests_item(R_or_L, 'Voiced-Stop', voiced_stop)
|
||||
_add_quests_item(R_or_L, 'UnVoiced-Stop', unvoiced_stop)
|
||||
|
||||
_add_quests_item(R_or_L, 'Front-Stop', front_stop)
|
||||
_add_quests_item(R_or_L, 'Central-Stop', central_stop)
|
||||
_add_quests_item(R_or_L, 'Back-Stop', back_stop)
|
||||
|
||||
_add_quests_item(R_or_L, 'Voiced-Fric', voiced_fricative)
|
||||
_add_quests_item(R_or_L, 'UnVoiced-Fric', unvoiced_fricative)
|
||||
|
||||
_add_quests_item(R_or_L, 'Front-Fric', front_fricative)
|
||||
_add_quests_item(R_or_L, 'Central-Fric', central_fricative)
|
||||
_add_quests_item(R_or_L, 'Back-Fric', back_fricative)
|
||||
|
||||
for p in phoneset:
|
||||
_add_quests_item(R_or_L, p, p)
|
||||
|
||||
return
|
||||
|
@ -7,6 +7,7 @@ import pandas as pd
|
||||
import convert_xsampa2ipa
|
||||
import defaultfiles as default
|
||||
import fame_functions
|
||||
import novoapi_functions
|
||||
|
||||
|
||||
def _load_transcriptions():
|
||||
@ -67,6 +68,19 @@ def load_transcriptions_clean(clean_wav_dir):
|
||||
return df_clean
|
||||
|
||||
|
||||
def load_transcriptions_novo70(clean_wav_dir):
|
||||
""" extract rows of which ipa is written in novo70 phonset. """
|
||||
df = load_transcriptions_clean(clean_wav_dir)
|
||||
|
||||
df_novo70 = pd.DataFrame(index=[], columns=list(df.keys()))
|
||||
for index, row in df.iterrows():
|
||||
not_in_novo70 = novoapi_functions.phones_not_in_novo70(row['ipa'])
|
||||
if len(not_in_novo70) == 0:
|
||||
df_novo70 = df_novo70.append(row, ignore_index=True)
|
||||
|
||||
return df_novo70
|
||||
|
||||
|
||||
def add_row_htk(df):
|
||||
""" df['htk'] is made from df['ipa'] and added. """
|
||||
htk = []
|
||||
|
Reference in New Issue
Block a user