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