def lf0_distortion_syn_is_gpr_format(org_path, syn_path): lf0_true_list = [] lf0_pred_list = [] for base in Utility.list_file(org_path): if base.startswith('.'): continue # if '12' in base: continue # Load Original original_file = os.path.join(org_path, base) original_vector = numpy.loadtxt( Utility.read_lf0_into_ascii(original_file)) # Load Synthesis synthesis_file = '{}/{}.npy'.format(syn_path, Utility.get_basefilename(base)) synthesis_vector = numpy.load(synthesis_file) synthesis_vector = synthesis_vector.reshape(len(synthesis_vector)) # print synthesis_vector # synthesis_vector = np.nan_to_num(synthesis_vector) synthesis_vector[np.where(synthesis_vector <= 0.0)] = UNDEF_VALUE # print synthesis_vector # sys.exit() for lf0_original, lf0_synthesis in zip(original_vector, synthesis_vector): if lf0_original == UNDEF_VALUE: continue if lf0_synthesis == UNDEF_VALUE: continue lf0_true_list.append(lf0_original) lf0_pred_list.append(lf0_synthesis) rmse = numpy.sqrt( sklearn.metrics.mean_squared_error( lf0_true_list, lf0_pred_list)) * 1200 / numpy.log(2) print('LF0 RMSE: {:f} in {} frames'.format(rmse, len(lf0_true_list))) pass
def gen_json_data(): outpath = '/home/h1/decha/Dropbox/python_workspace/Inter_speech_2016/playground/generate_json/latent_data/' obj = Utility.load_obj( '/home/h1/decha/Dropbox/Inter_speech_2016/Syllable_object/mix_object/current_version/all_vowel_type/syllable_object_01234.pickle' ) start_set, end_set = 'a', 'j' base_path = '/home/h1/decha/Dropbox/python_workspace/Inter_speech_2016/playground/list_file_for_preceeding_suceeding/list_gpr_file/' for sett in Utility.char_range(start_set, end_set): set_path = '{}/{}/'.format(base_path, sett) for f in Utility.list_file(set_path): if f.startswith('.'): continue file_path = '{}/{}'.format(set_path, f) out_list = [] for line in Utility.read_file_line_by_line(file_path): name = Utility.trim(line) # "duration" "syllable_context" duration = '' syllable_context = '' d = dict() if name == 'sil': syllable_context = 'sil-sil-sil-x' duration = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] elif name == 'pau': syllable_context = 'pau-pau-pau-x' duration = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] else: syl = obj.get_syllable_by_name_index(name) syllable_context = '{}-{}-{}-{}'.format( syl.consonant, syl.vowel, syl.final_consonant, syl.tone) duration = syl.single_space_latent.tolist() d['duration'] = duration d['syllable_context'] = syllable_context out_list.append(d) outfile_path = '{}/tscsd{}.json'.format(outpath, f) Utility.save_json(outfile_path, out_list)
def gen_tonal_part_duration(phone_level_label, pattern, start_set, end_set, outpath): for sett in Utility.char_range(start_set, end_set): set_path = '{}/{}/'.format(phone_level_label, sett) for f in Utility.list_file(set_path): if f.startswith('.'): continue file_path = '{}/{}'.format(set_path, f) phone_frame_list = [] syllable_count = 0 for line in Utility.read_file_line_by_line(file_path): match = re.match(pattern, line) if match: start_time = match.group('start_time') end_time = match.group('end_time') if match.group('phone_position_in_syllable') == 'x': continue phone_position_in_syllable = int(match.group('phone_position_in_syllable')) phone_number_in_syllable = int(match.group('phone_number_in_syllable')) frame = (float(end_time) - float(start_time))/50000 if phone_position_in_syllable == 1: phone_frame_list = [] phone_frame_list.append(frame) elif phone_position_in_syllable == phone_number_in_syllable: phone_frame_list.append(frame) if phone_number_in_syllable == 2: phone_frame_list.append(0) syllable_count+=1 print phone_frame_list outfile = '{}/{}/{}/{}_dur.npy'.format(outpath, sett, f.split('.')[0], syllable_count) print outfile Utility.make_directory('{}/{}/{}/'.format(outpath, sett, f.split('.')[0])) Utility.save_obj(phone_frame_list, outfile) elif phone_position_in_syllable == 2: phone_frame_list.append(frame) else: print 'Not match', f pass
def gen_file_list(): outpath = '/home/h1/decha/Dropbox/python_workspace/Inter_speech_2016/playground/list_file_for_preceeding_suceeding/list_gpr_file/' label_path = '/work/w2/decha/Data/GPR_data/label/03_GPR_syllable_level/full/tsc/sd/' start_set = 'a' end_set = 'j' for sett in Utility.char_range(start_set, end_set): set_path = '{}/{}/'.format(label_path, sett) out_set_path = '{}/{}/'.format(outpath, sett) Utility.make_directory(out_set_path) for f in Utility.list_file(set_path): if f.startswith('.'): continue file_path = '{}/{}'.format(set_path, f) count = 0 # print f file_number = f[6] + f[7] out_list = [] for line in Utility.read_file_line_by_line(file_path): # print Utility.trim(line) out = '' if 'sil-sil+sil/A:' in line: out = 'sil' elif 'pau-pau+pau/A:' in line: out = 'pau' else: count += 1 out = 'tscsd_gpr_{}{}_{}'.format(sett, file_number, count) # print out out_list.append(out) if len(out_list) != len(Utility.read_file_line_by_line(file_path)): print file_path out_file_name = '{}/{}{}.lab'.format(out_set_path, sett, file_number) # print out_file_name Utility.write_to_file_line_by_line(out_file_name, out_list)
def hmm_frame_to_mono_label(dur_path, mono_path, out_path): for dur_file in Utility.list_file(dur_path): if not 'dur' in dur_file: continue base = Utility.get_basefilename(dur_file) # print base dur = '{}/{}'.format(dur_path, dur_file) # print dur dur_list = get_dir_list_HMM(dur) # print dur_list mono = '{}/{}.lab'.format(mono_path, base) mono_list = load_mono(mono) out_file = '{}/{}.lab'.format(out_path, base) # print len(dur_list), len(mono_list) if len(dur_list) != len(mono_list): print base start = 0 out = [] for idx, d in enumerate(dur_list): # print dur_list[idx][0], mono_list[idx] o = '{}\t{}\t{}'.format(int(start), int(start + (dur_list[idx][0] * 10000000)), mono_list[idx]) out.append(o) start = start + (dur_list[idx][0] * 10000000) Utility.write_to_file_line_by_line(out_file, out) # sys.exit() pass
def read_mos(data_folder): all_score = dict() c_all_score = dict() count = dict() for score_file in Utility.list_file(data_folder): if score_file.startswith('.'): continue if not 'mos' in score_file: continue # print score_file score = Utility.load_json('{}/{}'.format(data_folder, score_file)) for s in score: # print score[s] for k in score[s]: # print k, score[s][k] if k in all_score: all_score[k] = all_score[k] + float(score[s][k]) # if k=='01_GPR_single_level/': # print float(score[s][k]), all_score[k] count[k] = count[k] + 1 c_all_score[k].append(float(score[s][k])) else: all_score[k] = float(score[s][k]) count[k] = 1 c_all_score[k] = [] c_all_score[k].append(float(score[s][k])) print '-----------------------------------------' for k in all_score: print k, all_score[k] print count[k] print all_score[k] / count[k] print 'Mean :', np.average(c_all_score[k]), 'Var :', np.var( c_all_score[k])
def run_gen(base_path, start_set, end_set, pattern, outpath): out = [] for sett in Utility.char_range(start_set, end_set): set_path = '{}/{}/'.format(base_path, sett) for f in Utility.list_file(set_path): if f.startswith('.'): continue file_path = '{}/{}'.format(set_path, f) # print file_path count = 0 # tscsd_gpr_g37_13 prefix = 'tscsd_gpr' lines = Utility.read_file_line_by_line(file_path) for idx, line in enumerate(lines): # print line match = re.match(pattern, line) if match: phone = match.group('curphone') # print phone if phone not in ['sil', 'pau']: count += 1 # print f name_index = '{}_{}{}_{}'.format( prefix, sett, f[6:8], count) if ('sil-sil+sil/A:' in lines[idx + 1]) | ( 'pau-pau+pau/A:' in lines[idx + 1]): print name_index out.append(name_index) print len(out) outpath_file = '{}/gpr_followed_by_sil_list.npy'.format(outpath) Utility.save_obj(out, outpath_file) pass
def find_stress_info(stress_path, name): spl = name.split('_') sett = spl[0][5] syl_index = spl[1] filename = spl[0] # print sett, syl_index for s in Utility.list_file(stress_path): if s[0] == sett: file_path = '{}/{}/{}.lab'.format(stress_path, s, filename) # print file_path lines = Utility.read_file_line_by_line(file_path) ss = lines[int(syl_index) - 1].split(' ') return Utility.trim(ss[3]) break
def lf0_distortion_syn_is_readable(org_path, syn_path): lf0_true_list = [] lf0_pred_list = [] for base in Utility.list_file(org_path): if base.startswith('.'): continue # Load Original original_file = os.path.join(org_path, base) original_vector = numpy.loadtxt( Utility.read_lf0_into_ascii(original_file)) # Load Synthesis synthesis_file = os.path.join(syn_path, base) synthesis_vector = numpy.loadtxt(synthesis_file) for lf0_original, lf0_synthesis in zip(original_vector, synthesis_vector): if lf0_original == Distortion.UNDEF_VALUE: continue if lf0_synthesis == Distortion.UNDEF_VALUE: continue lf0_true_list.append(lf0_original) lf0_pred_list.append(lf0_synthesis) # print len(lf0_true_list), len(lf0_pred_list) rmse = numpy.sqrt( sklearn.metrics.mean_squared_error( lf0_true_list, lf0_pred_list)) * 1200 / numpy.log(2) # print('LF0 RMSE: {:f} in {} frames'.format(rmse, len(lf0_true_list))) return (rmse, len(lf0_true_list)) pass
def read_pref_2_method(data_folder, met): all_score = dict() all_score['01'] = 0 all_score['10'] = 0 # met = ['01_wav_gpr_single_level/', '02_wav_gpr_multi_level/', '03_wav_gpr_pog/'] d = dict() d[met[0]] = '0' d[met[1]] = '1' for score_file in Utility.list_file(data_folder): if score_file.startswith('.'): continue if not 'pref' in score_file: continue # print score_file score = Utility.load_json('{}/{}'.format(data_folder, score_file)) # print score for s in score: # print s, score[s] for m in score[s]: # print m, score[s][m] if (met[0] in m) & (met[1] in m): if score[s][m] == met[0]: all_score['01'] = all_score['01'] + 1 else: all_score['10'] = all_score['10'] + 1 print '-----------------------------------------' for k in ['01', '10']: print k, all_score[k]
def cal_syllable_dur(dur_path, syl_dur_path, hmm=False): org_all, gen_all = [], [] file_count = 0 # print Utility.list_file(dur_path) for dur_file in Utility.list_file(dur_path): # print dur_file if hmm: if 'dur' not in dur_file: continue elif 'npy' not in dur_file: continue file_count = file_count + 1 basename = Utility.get_basefilename(dur_file) # print basename org_path = '{}/{}.lab'.format(syl_dur_path, basename) org_dur_list, num_phone = get_org_syllable_list(org_path) if not hmm: gen_dur = get_dur_list('{}/{}'.format(dur_path, dur_file)) else: gen_dur = get_dir_list_HMM('{}/{}'.format(dur_path, dur_file)) gen_syn_dur = [] idx = 0 # print len(num_phone) # print num_phone # print gen_dur summ = 0 for num in num_phone: # print num if num == 'x': gen_syn_dur.append(gen_dur[idx][0]) idx = idx + 1 else: syllable_duration = 0 summ = summ + int(num) for n in range(1, int(num) + 1): # print n, num syllable_duration = syllable_duration + gen_dur[idx][0] idx = idx + 1 # print syllable_duration gen_syn_dur.append(syllable_duration) # print len(num_phone), idx, len(gen_dur), summ if len(gen_syn_dur) != len(org_dur_list): print 'Not equal' print dur_path # print gen_syn_dur for idx, num in enumerate(num_phone): if num == 'x': continue org = org_dur_list[idx] * 1000 gen = gen_syn_dur[idx] * 1000 org_all.append(org) gen_all.append(gen) # print org, gen # break # RMSE for dur in syllable rmse = numpy.sqrt(sklearn.metrics.mean_squared_error(org_all, gen_all)) # print file_count print rmse pass
############################################################ if __name__ == '__main__': syl_dur_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/full_time_syllable_remove_silence/tsc/sd/j/' # path = '/work/w16/decha/decha_w16/spec_com_work_space/speech_param/450/01_GPR/' # path = '/work/w16/decha/decha_w16/spec_com_work_space/speech_param/450/02_GPR_with_multi_level/' # path = '/work/w16/decha/decha_w16/spec_com_work_space/speech_param/450/03_HMM/' path = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/mono_label/03_PoG/' mono_path = '{}/mono_label/'.format(path) outpath = '{}/mono_to_syl_dur/'.format(path) Utility.make_directory(outpath) for syl in Utility.list_file(syl_dur_path): print syl syl_path = '{}/{}'.format(syl_dur_path, syl) dur_list, num_phone = get_org_syllable_list(syl_path) mono_file = '{}/{}'.format(mono_path, syl) mono_list = Utility.read_file_line_by_line(mono_file) out_file = '{}/{}'.format(outpath, syl) # print num_phone load_dur_file(num_phone, mono_list, out_file) # sys.exit() ############################################################
def run(main_fig_path, out_path): vowel_type = ['v', 'vv', 'vn', 'vvn', 'vsg', 'vvsg'] # vowel_type = ['v', 'vv', 'vn', 'vvn', 'vsg', 'vvsg'] tones = ['0', '1', '2', '3', '4'] # vowel_type = ['vv'] # tones = ['1'] c = dict() c[-1] = 'black' c[0] = 'blue' c[1] = 'red' c[2] = 'green' c[3] = 'yellow' fig_per_line = 4 syllable_lists = dict() # for v in vowel_type: for v in ['vvv', 'vvvn', 'vvvsg']: for t in tones: if v == 'vvv': vv = ['v', 'vv'] elif v == 'vvvn': vv = ['vn', 'vvn'] elif v == 'vvvsg': vv = ['vsg', 'vvsg'] else: print 'wtf' dire = '{}/{}/'.format(out_path, v) Utility.make_directory(dire) latext_out_file = '{}/stress-list_vowel-type-{}_Tone-{}.tex'.format( dire, v, t) for vi in vv: path = '{}/{}/{}/'.format(main_fig_path, vi, t) files = Utility.list_file(path) file_list = [] # print files for f in files: # tscsd_manual_f17_22_tone_3_dur_15.025_syl_n-aa-m^_stress_0 if f.startswith('.'): continue pattern = re.compile( r"""(?P<name>.+)_tone.+dur_(?P<dur>.+)_syl.+_stress_(?P<stress>.+).eps""", re.VERBOSE) match = re.match(pattern, f) # print match if match: dur = float(match.group('dur')) stress = 'Unstress' if int(match.group('stress')) == 1: stress = 'Stress' file_list.append(('{}/{}'.format(path, f), dur, stress, match.group('name'))) else: print f Utility.sort_by_index(file_list, 1) # print file_list eps_list = [] caption_list = [] temp_eps = [] temp_cap = [] for fi in file_list: file_path = fi[0] dur = fi[1] stress = fi[2] name = fi[3] group = find_group(t, v, name) color = c[group] # if group != 0: # print v, t # print group, color # print '\\textcolor{{{}}}{{{}}}'.format(color,name) name = name.replace('_', '\_') # {\color{red} Panda } temp_eps.append(file_path) temp_cap.append('{{\color{{{}}} {} }}'.format(color, name)) if fig_per_line == len(temp_eps): eps_list.append(temp_eps) caption_list.append(temp_cap) temp_eps = [] temp_cap = [] eps_list.append(temp_eps) caption_list.append(temp_cap) # print len(eps_list) if len(eps_list) == 1: continue Latext_Tool.plot_all_data(eps_list, caption_list, latext_out_file) pass
# print iden if cur_position_syl == 'x': continue if ( cur_position_syl == cur_num_syl ) & ( ( cur_num_syl != '1' ) ): # print iden out.append(iden) pass out = [] if __name__ == '__main__': label_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/full_time/tsc/sd/' for sett in ['j']: label_set_path = '{}/{}/'.format(label_path, sett) for f in Utility.list_file(label_set_path): if f.startswith('.'): continue filepath = '{}/{}'.format(label_set_path, f) get_last_syllable(filepath, Utility.get_basefilename(f)) # sys.exit() Utility.save_obj(out, './potential_list.pkl') pass
input_dims = [10] # name_in_figure = 'LABEL_TYPE_STRESS_all' name_in_figure = 'LABEL_TYPE_STRESS_manual' # name_in_figure = 'LABEL_TYPE_STRESS_3D_COLORING_manual' for syst in base_path_list: # for v in Utility.list_file(syst): for v in vowel_type: if '.' in v: continue for dims in input_dims: delta_path = '{}/{}/input_dims_{}'.format(syst, v, dims) for d in Utility.list_file(delta_path): if 'alias' in d: continue if d.startswith('.'): continue for tone in Utility.list_file('{}/{}/'.format( delta_path, d)): if tone.startswith('.'): continue if '_1' not in tone: continue tone_path = '{}/{}/{}/'.format(delta_path, d, tone) name_index = Utility.load_obj( '{}/name_index.npy'.format(tone_path)) # print name_index # sys.exit() print 'Label for scan : Tone: {} , Vowel: , {}'.format(
def lf0_distortion_syn_is_gpr_format(org_path, syn_path, stress_list, mono_label): lf0_true_list = [] lf0_pred_list = [] lf0_true_stress_list = [] lf0_pred_stress_list = [] for base in Utility.list_file(org_path): if base.startswith('.'): continue b = Utility.get_basefilename(base) stress = np.load('{}/{}.npy'.format(stress_list, b)) mono_file = Utility.read_file_line_by_line('{}/{}.lab'.format( mono_label, b)) stress_index = np.array([]) for st, mono in zip(stress, mono_file): spl = mono.split(' ') start = int(spl[0]) / 50000 end = int(spl[1]) / 50000 if (st[0] == '1') & (st[1] == '{}'.format(tone)): stress_index = np.append(stress_index, np.arange(start, end), axis=0) # Load Original original_file = os.path.join(org_path, base) original_vector = numpy.loadtxt( Utility.read_lf0_into_ascii(original_file)) # Load Synthesis synthesis_file = '{}/{}.npy'.format(syn_path, Utility.get_basefilename(base)) synthesis_vector = numpy.load(synthesis_file) synthesis_vector = synthesis_vector.reshape(len(synthesis_vector)) # print synthesis_vector synthesis_vector = np.nan_to_num(synthesis_vector) synthesis_vector[np.where(synthesis_vector <= 0.0)] = UNDEF_VALUE # print synthesis_vector # sys.exit() for idx, (lf0_original, lf0_synthesis) in enumerate( zip(original_vector, synthesis_vector)): if lf0_original == UNDEF_VALUE: continue if lf0_synthesis == UNDEF_VALUE: continue lf0_true_list.append(lf0_original) lf0_pred_list.append(lf0_synthesis) if idx in stress_index: lf0_true_stress_list.append(lf0_original) lf0_pred_stress_list.append(lf0_synthesis) # rmse = numpy.sqrt(sklearn.metrics.mean_squared_error(lf0_true_list, lf0_pred_list)) * 1000 / numpy.log(2) rmse = numpy.sqrt( sklearn.metrics.mean_squared_error( lf0_true_list, lf0_pred_list)) * 1200 / numpy.log(2) print('All LF0 RMSE: {:f} in {} frames'.format(rmse, len(lf0_true_list))) rmse = numpy.sqrt( sklearn.metrics.mean_squared_error( lf0_true_stress_list, lf0_pred_stress_list)) * 1200 / numpy.log(2) print('Only stress LF0 RMSE: {:f} in {} frames'.format( rmse, len(lf0_true_stress_list))) pass
base_data_path = '/home/h1/decha/Dropbox/Inter_speech_2016/Syllable_object/Tonal_object/remove_all_silence_file/' base_path_list = [ '/work/w13/decha/Inter_speech_2016_workplace/Tonal_projection/06_Tonal_part_projection_noise_reduction-250-iters-opt/' ] vowel_type = ['vvv', 'vvvn','vvvsg'] #['v', 'vv','vn', 'vvn', 'vsg', 'vvsg'] input_dims = [10] name_in_figure = 'LABEL_TYPE_STRESS' for syst in base_path_list: # for v in ['vvv']: for v in Utility.list_file(syst): if '.' in v : continue for dims in input_dims: delta_path = '{}/{}/input_dims_{}'.format(syst, v, dims) for d in ['delta-True_delta-delta-True'] : #Utility.list_file(delta_path): if d.startswith('.'): continue for tone in Utility.list_file('{}/{}/'.format(delta_path, d)): if tone.startswith('.'): continue # if '01234' not in tone: continue tone_path = '{}/{}/{}/'.format(delta_path, d, tone) print tone_path object_data = '{}/{}/syllable_object_{}.pickle'.format(base_data_path, v, tone.split('_')[len(tone.split('_'))-1]) print object_data outpath = '{}/{}.eps'.format(tone_path, name_in_figure) print outpath
from tool_box.util.utility import Utility import numpy as np import matplotlib.pyplot as plt if __name__ == '__main__': ref_path = '/work/w16/decha/decha_w16/spec_com_work_space/Speech_synthesis/05_GPR_abcdefghijklmnopqrst/testrun/out/tsc/a-t/speech_param/a-t/demo/seed-00/M-1024/B-1024/num_iters-5/dur_old/param_mean/' pog_path = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/Result/alpha_1.0/a-i/tscsdj01_mean.npy' pog = np.load(pog_path).shape out_path = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/Using_result/450_dur/' pog_path = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/Result/alpha_1.0/a-i/' for f in Utility.list_file(pog_path): if f.startswith('.'): continue if 'mean' not in f: continue basename = Utility.get_basefilename(f) base = basename[0:len(basename) - 5] pog = np.load('{}/{}'.format(pog_path, f)).shape ref = np.load('{}/{}.npy'.format(ref_path, base)).shape Utility.copyFile('{}/{}'.format(pog_path, f), '{}/{}.npy'.format(out_path, base)) pass
'zero_var_path': zero_var_path } cal_lf0(config) # Start for distortion UNDEF_VALUE = -1.0e+10 stress_list = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/stress_list/j/' mono_label = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/mono_syllable_remove_silence/tsc/sd/j/' org_for_distortion = '/work/w2/decha/Data/GPR_speccom_data/lf0/tsc/sd/j/' syn_for_distortion = outpath if len(Utility.list_file(syn_for_distortion)) != 50: continue rmse = lf0_distortion_syn_is_gpr_format(org_for_distortion, syn_for_distortion, stress_list, mono_label) if rmse < old_rmse: # print 'Continue', old_rmse, rmse old_rmse = rmse else: # print 'Break', old_rmse, rmse break pass
# for s in Utility.char_range('a', 'z'): for s in Utility.char_range('j', 'j'): if s in ['k', 'n', 'q', 's']: continue print s full_set_path = '{}/{}/'.format(full_path, s) out_set_path = '{}/{}/'.format(out_path, s) out_set_full_path = '{}/{}/'.format(out_full_path, s) Utility.make_directory(out_set_path) Utility.make_directory(out_set_full_path) for f in Utility.list_file(full_set_path): if f.startswith('.'): continue base = Utility.get_basefilename(f) full_file = '{}/{}'.format(full_set_path, f) # print full_file out_file = '{}/{}'.format(out_set_path, f) # print out_file out_full_no_time_file = '{}/{}'.format(out_set_full_path, f) add_stress_to_full(full_file, out_file, out_full_no_time_file, base)
org_syn_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/full_time/tsc/sd/j/' file_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/full_time/tsc/sd/j/' syl_dist_path = '/work/w15/decha/decha_w15/Specom_w15/02_GPR_syllable_level_remove_silience/testrun/out/tsc/a-{}/infer/a-{}/demo/seed-00/M-1024/B-1024/num_iters-5/dur/predictive_distribution/'.format( end_set, end_set) ph_dist_path = '/work/w15/decha/decha_w15/Specom_w15/05b_GPR_for_duration/testrun/out/tsc/a-{}/infer/a-{}/demo/seed-00/M-1024/B-1024/num_iters-5/dur/predictive_distribution/'.format( end_set, end_set) # outpath = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/Result/alpha_{}_beta_{}/a-{}/'.format(alpha, beta, end_set) # Utility.make_directory(outpath) for f in Utility.list_file(file_path): label_file = '{}/{}'.format(file_path, f) w = PoGUtility.read_file_to_W(label_file) base = Utility.get_basefilename(f) syl_predictive_dist_path = '{}/{}/'.format(syl_dist_path, base) syllable_mean, syllable_cov = PoGUtility.read_mean_and_cov_of_predictive_distribution( syl_predictive_dist_path) ph_predictive_dist_path = '{}/{}/'.format(ph_dist_path, base) phone_mean, phone_cov = PoGUtility.read_mean_and_cov_of_predictive_distribution( ph_predictive_dist_path) print w.shape, syllable_mean.shape, syllable_cov.shape, phone_mean.shape, phone_cov.shape
def run_make_obj_for_an_utterance(full_path, dur_path, lf0_path): global syl_database pattern = re.compile( r"""(?P<start>.+)\s(?P<end>.+)\s(?P<consonant>.+)\-(?P<vowel>.+)\+(?P<finalconsonant>.+)/A:.+/B:.+\-(?P<tone>.+)\+.+/C:.+/E:.+""", re.VERBOSE) # print dur_path # print lf0_path dur_list = Utility.load_obj(dur_path) lf0_list = Utility.list_file(lf0_path) lf0_list = sort_dur_list_by_index(lf0_list) # print lf0_list for idx, line in enumerate(Utility.read_file_line_by_line(full_path)): c = idx + 1 # print line l = Utility.trim(line) match = re.match(pattern, line) if match: start = float(match.group('start')) end = float(match.group('end')) consonant = match.group('consonant') vowel = match.group('vowel') finalconsonant = match.group('finalconsonant') tone = match.group('tone') dur = dur_list[idx] lf0 = Utility.read_file_line_by_line('{}/{}'.format( lf0_path, lf0_list[idx])) lf0 = [float(i) for i in lf0] iden = '{}_{}'.format(Utility.get_basefilename(full_path), c) # print start, end, consonant, vowel, finalconsonant, tone, dur, lf0, iden syl = dict( ) #Syllable(iden, tone, consonant, vowel, finalconsonant, dur, lf0) syl['id'] = iden syl['tone'] = tone syl['consonant'] = consonant syl['vowel'] = vowel syl['finalconsonant'] = finalconsonant syl['dur'] = dur syl['raw_lf0'] = lf0 syl_database.append(syl) # sys.exit(0) else: raise TypeError("WTF") pass
def duration_distortion_from_numpy_list_syllable_level(org_path, syn_path): path = syn_path original_path = org_path ori = [] ph_list = [] syn = [] for f in Utility.list_file(path): if f.startswith('.'): continue if 'mean' not in f: continue syn_path = '{}/{}'.format(path, f) # print syn_path syn_list = numpy.load(syn_path) sl = list(syn_list.flatten()) base = Utility.get_basefilename(f) base = base[0:len(base) - 5] ori_path = '{}/{}.lab'.format(original_path, base) # print ori_path phone_num, dur_list = Distortion.load_ori_list_in_sec_and_num_phone_list( ori_path) s_out = [] sl_count = 0 for pn in phone_num: if pn is 'x': s_out.append(sl[sl_count]) sl_count = sl_count + 1 else: d = 0 for i in range(int(pn)): d = d + sl[sl_count] sl_count = sl_count + 1 s_out.append(d) ori.extend(dur_list) ph_list.extend(phone_num) syn.extend(s_out) # print len(ph_list), len(ori), len(syn) dur_true_list = [] dur_pred_list = [] for idx, p in enumerate(ph_list): if (p == 'x'): continue dur_true_list.append(1000 * ori[idx]) dur_pred_list.append(1000 * syn[idx]) if len(dur_true_list) != len(dur_pred_list): print "Not equal" rmse = numpy.sqrt( sklearn.metrics.mean_squared_error(dur_true_list, dur_pred_list)) print('Duration RMSE: {:f} in {} phones'.format( rmse, len(dur_true_list)))
plt.savefig(outfile) pass if __name__ == '__main__': org = '/work/w2/decha/Data/GPR_speccom_data/mono_to_syl_dur/' hmm = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/mono_label/01_GPR/mono_to_syl_dur/' gpr = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/mono_label/02_GPR_with_multi_level/mono_to_syl_dur/' gpr_with_multi_level = '/work/w25/decha/decha_w25/ICASSP_2017_workspace/mono_label/03_PoG/mono_to_syl_dur/' outpath = './dur_distortion_syl/' Utility.make_directory(outpath) for lab in Utility.list_file(org): print lab o = '{}/{}'.format(org, lab) h = '{}/{}'.format(hmm, lab) g = '{}/{}'.format(gpr, lab) gm = '{}/{}'.format(gpr_with_multi_level, lab) outfile = '{}/{}.eps'.format(outpath, Utility.get_basefilename(lab)) plot(o, h, g, gm, outfile) # sys.exit() pass
def dur_distortion(org_path, syn_path): dur_true_list = [] dur_pred_list = [] for base in Utility.list_file(org_path): if base.startswith('.'): continue basename = base.split('.') # print basename # Load Original org_file = os.path.join(org_path, '{}{}'.format(basename[0], '.lab')) org_duration_vector = Utility.read_file_line_by_line(org_file) syn_file = os.path.join(syn_path, '{}{}'.format(basename[0], '.dur')) syn_duration_vector_temp = Utility.read_file_line_by_line(syn_file) syn_duration_vector = [] for vec in syn_duration_vector_temp: if not "state" in vec: syn_duration_vector.append(vec) pattern = re.compile( r"""(?P<start>.+)\s(?P<end>.+)\s.+\-(?P<curphone>.+)\+.+/A:.+""", re.VERBOSE) syn_pattern = re.compile( r""".+\-(?P<phone>.+)\+.+/A:.+\sduration=(?P<duration>.+)\s\(frame\).+""", re.VERBOSE) #X-sil+ph/A:x_x-x_x+1_1/B:x-x+0/C:x_x-x_x+1_1/D:x-x+2/E:x-x+1/F:x_x-x_x+9_4/G:x_22_14/H:x_x-56_1+2_1.state[2]: duration=5 (frame), mean=4.609594e+00 if len(org_duration_vector) != len(syn_duration_vector): print "Not equal" for org, syn in zip(org_duration_vector, syn_duration_vector): match = re.match(pattern, org) if match.group('curphone') in ["sil", "pau"]: continue phone = match.group('curphone') duration = (int(match.group('end')) - int(match.group('start'))) / 50000 syn_match = re.match(syn_pattern, syn) syn_duration = int(syn_match.group('duration')) # print phone, duration, syn_match.group('phone') , syn_duration dur_true_list.append(1000 * duration * 0.005) dur_pred_list.append(1000 * syn_duration * 0.005) if len(dur_true_list) != len(dur_pred_list): print "Not equal" rmse = numpy.sqrt( sklearn.metrics.mean_squared_error(dur_true_list, dur_pred_list)) print('Duration RMSE: {:f} in {} phones'.format( rmse, len(dur_true_list)))
pass if __name__ == '__main__': full_path = '/home/h1/decha/Dropbox/Inter_speech_2016/Test_set/full/' outpath = '/work/w2/decha/Data/GPR_data/label/09_stress_manual_labeling/utt/tsc/sd/' start_set, end_set = 'i', 'i' for sett in Utility.char_range(start_set, end_set): set_path = '{}/{}/'.format(full_path, sett) out_set_path = '{}/{}/'.format(outpath, sett) Utility.make_directory(out_set_path) for f in Utility.list_file(set_path): if f.startswith('.'): continue base_name = Utility.get_basefilename(f).split('.')[0] out_file = '{}/{}.utt.yaml'.format(out_set_path, base_name) file_path = '{}/{}'.format(set_path, f) print out_file # sys.exit() gen_utt(file_path, out_file) # for line in Utility.read_file_line_by_line(file_path): # sys.exit() pass
sys.path.append('../../') sys.path.append('../') sys.path.append('/home/h1/decha/Dropbox/python_workspace/Inter_speech_2016/') import matplotlib.mlab as mlab from tool_box.util.utility import Utility import scipy.stats as stats from DataModel.Syllables.Syllable import Syllable from DataModel.Syllables.SyllableDatabaseManagement import SyllableDatabaseManagement import numpy as np import matplotlib.pyplot as plt if __name__ == '__main__': base_path = '/work/w13/decha/Inter_speech_2016_workplace/Tonal_projection/10_tone_classification/' for v in Utility.list_file(base_path): if '.' in v: continue for dims in Utility.list_file('{}/{}/'.format(base_path, v)): if '.' in dims: continue for delta in Utility.list_file('{}/{}/{}/'.format( base_path, v, dims)): if '.' in delta: continue for tone in Utility.list_file('{}/{}/{}/{}/'.format( base_path, v, dims, delta)): if '.' in tone: continue tone_path = '{}/{}/{}/{}/{}/'.format( base_path, v, dims, delta, tone) print tone_path gp_model = '{}/GP_model.npy'.format(tone_path) if Utility.is_file_exist(gp_model):
cmp_outpath = '{}/{}/'.format(out_path, s) lf0_out_path = '{}/{}/'.format(lf0_outpath, s) mcep_out_path = '{}/{}/'.format(mcep_outpath, s) bap_out_path = '{}/{}/'.format(bap_outpath, s) # Utility.make_directory(cmp_outpath) Utility.make_directory(lf0_out_path) Utility.make_directory(mcep_out_path) Utility.make_directory(bap_out_path) print s for f in Utility.list_file(mono_set_path): if f.startswith('.'): continue base = Utility.get_basefilename(f) # print base mono = Utility.read_file_line_by_line('{}/{}.lab'.format( mono_set_path, base)) mono_remove = Utility.read_file_line_by_line('{}/{}.lab'.format( mono_remove_silence_path, base)) # cmp_file = '{}/{}/{}.cmp'.format(cmp_path, s, base) # out_cmp_file = '{}/{}/{}.cmp'.format(out_path, s, base) mono_head = mono[0].split(' ')
'beta': '', 'gamma': '', 'basepath': single_path }, 'unstress_2': { 'beta': '0.3', 'gamma': '0.5', 'basepath': unstress_path }, 'unstress_3': { 'beta': '', 'gamma': '', 'basepath': single_path }, 'unstress_4': { 'beta': '1.1', 'gamma': '0.7', 'basepath': unstress_path } } for filename in Utility.list_file(mono_label): base = Utility.get_basefilename(filename) # print base original_file = np.load('{}/{}.npy'.format(single_path, base)) gen_all_method(base) pass
from tool_box.util.utility import Utility syllable_files_path = '/home/h1/decha/Dropbox/Inter_speech_2016/Training_data/03_GPR_syllable_level/full_time/tsc/sd/' set_list = Utility.char_range('a', 'j') pattern = re.compile( r"""(?P<time>.+\s.+)\s(?P<syllable>.+)/A:.+/S:.+/B:.+\-(?P<tone>.+)\+.+/C:.+\-(?P<index>.+)_.+\+.+/D:.+""", re.VERBOSE) out_p = '/work/w2/decha/Data/GPR_data/label/03_GPR_syllable_level/syllable_with_index/tsc/sd/' for s in set_list: target_path = '{}/{}/'.format(syllable_files_path, s) print target_path for f in Utility.list_file(target_path): if f.startswith('.'): continue new_file = [] Utility.make_directory('{}/{}/'.format(out_p, s)) out_path = '{}/{}/{}'.format(out_p, s, f) print out_path for line in Utility.read_file_line_by_line('{}/{}'.format( target_path, f)): # print line match = re.match(pattern, line) if match: time = match.group('time')