def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) var = np.load('{}'.format(var_path)) vv = [] for i, v in enumerate(var): vv.append(v[i]) var = np.array(vv) lf0_mean = np.array([lf0_mean[:, 0], lf0_mean[:, 1], lf0_mean[:, 2]]) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov)) B = PoGUtility.cal_sum_of_mean_part(var, lf0_w, lf0_cov, lf0_mean) A = PoGUtility.cal_sum_of_weight_part(var, lf0_w, lf0_cov) lf0 = np.dot(inv(A), B) print lf0.shape np.save(outfilepath, lf0) sys.exit() pass
def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] syllable_base_path = config['syllable_base_path'] syllable_var_path = config['syllable_var_path'] original = config['original'] koriyama_gen = config['koriyama_gen'] figure_path = config['figure_path'] ph_in_syl_object_path = config['phone_in_syllable_object_path'] stress = config['stress'] original_vuv = config['original_vuv'] p_in_s_file = Utility.load_obj(ph_in_syl_object_path) vuv = np.load('{}/class.npy'.format(config['vuv_path'])) if mask == 'original': vuv = original_vuv #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) var = np.load('{}'.format(var_path)) if len(lf0_cov) > len(vuv): for i in range(len(lf0_cov) - len(vuv)): vuv.append(-1, axis=0) elif len(lf0_cov) < len(vuv): vuv = vuv[0:len(lf0_cov)] lf0_var = np.sum(var, axis=0) lf0_mean = np.array([lf0_mean[:, 0], lf0_mean[:, 1], lf0_mean[:, 2]]) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov), vuv) frame_B = alpha * PoGUtility.cal_sum_of_mean_part(lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part( lf0_var, lf0_w, lf0_cov) L = linalg.cholesky(frame_A, lower=True) lf0 = linalg.cho_solve((L, True), frame_B) lf0[lf0 < 1] = np.nan np.save(outfilepath, lf0) pass
def cal_for_frame_level(var_path, vuv, lf0_cov, lf0_mean, alpha): var = np.load('{}'.format(var_path)) if len(lf0_cov) > len(vuv): for i in range(len(lf0_cov) - len(vuv)): vuv.append(-1, axis=0) elif len(lf0_cov) < len(vuv): vuv = vuv[0:len(lf0_cov)] lf0_var = np.sum(var, axis=0) lf0_mean = np.array([lf0_mean[:, 0], lf0_mean[:, 1], lf0_mean[:, 2]]) lf0_w = PoGUtility.generate_W_for_GPR_generate_features( len(lf0_cov), vuv) frame_B = alpha * PoGUtility.cal_sum_of_mean_part( lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part( lf0_var, lf0_w, lf0_cov) return (frame_A, frame_B)
def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] syllable_base_path = config['syllable_base_path'] syllable_var_path = config['syllable_var_path'] original = config['original'] koriyama_gen = config['koriyama_gen'] figure_path = config['figure_path'] ph_in_syl_object_path = config['phone_in_syllable_object_path'] stress = config['stress'] original_vuv = config['original_vuv'] p_in_s_file = Utility.load_obj(ph_in_syl_object_path) vuv = np.load('{}/class.npy'.format(config['vuv_path'])) # vuv = original_vuv #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) var = np.load('{}'.format(var_path)) if len(lf0_cov) > len(vuv): for i in range(len(lf0_cov) - len(vuv)): vuv.append(-1, axis=0) elif len(lf0_cov) < len(vuv): vuv = vuv[0:len(lf0_cov)] lf0_var = np.sum(var, axis=0) lf0_mean = np.array([lf0_mean[:, 0], lf0_mean[:, 1], lf0_mean[:, 2]]) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov), vuv) frame_B = alpha * PoGUtility.cal_sum_of_mean_part(lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part( lf0_var, lf0_w, lf0_cov) L = linalg.cholesky(frame_A, lower=True) lf0 = linalg.cho_solve((L, True), frame_B) # lf0 = lf0_gen_with_vuv(lf0, vuv) print lf0.shape frame_lf0_nomask = np.copy(lf0) # lf0 = lf0_gen_with_vuv(lf0, vuv) lf0[lf0 < 1] = np.nan frame_lf0 = np.copy(lf0) #----------Syllable level--------# dur_list, names = PoGUtility.gen_dur_and_name_list(label_path, name) # print np.sum(dur_list) if np.sum(dur_list) < len(original): dur_list[0] = dur_list[0] + len(original) - np.sum(dur_list) # print np.sum(dur_list) syl_mean = np.load('{}/mean.npy'.format(syllable_base_path)) syl_cov = np.load('{}/cov.npy'.format(syllable_base_path)) s_mean = syl_mean var = np.load('{}'.format(syllable_var_path)) syl_var = np.sum(var, axis=0) temp_mean = [] for i in range(len(syl_mean[0])): temp_mean.append(syl_mean[:, i]) syl_mean = np.array(temp_mean) syl_w = PoGUtility.generate_DCT_W_without_consonant_on_stress( len(lf0_cov), dur_list, num_coeff, p_in_s_file, stress) syl_B = beta * PoGUtility.cal_sum_of_mean_part(syl_var, syl_w, syl_cov, syl_mean) syl_A = beta * PoGUtility.cal_sum_of_weight_part(syl_var, syl_w, syl_cov) #----------Combine Model--------# L = linalg.cholesky(frame_A + syl_A, lower=True) lf0 = linalg.cho_solve((L, True), frame_B + syl_B) # print lf0.shape lf0[lf0 < 1] = np.nan PlotUtility.plot([lf0, original, frame_lf0_nomask], ['Multi', 'original', 'Single'], '{}/{}_no_mask.eps'.format(figure_path, name)) lf0 = lf0_gen_with_vuv(lf0, vuv) lf0[lf0 < 1] = np.nan frame_lf0 = lf0_gen_with_vuv(frame_lf0, vuv) frame_lf0[frame_lf0 < 1] = np.nan np.save(outfilepath, lf0) print min(lf0) PlotUtility.plot([lf0, original, frame_lf0], ['Multi', 'original', 'Single'], '{}/{}_multi.eps'.format(figure_path, name)) #----------Combine Model--------# o = [] for data_dct, dur in zip(s_mean, dur_list): i_dct = PoGUtility.generate_inverse_DCT(data_dct, dur) o = o + i_dct o = np.concatenate((np.zeros(len(original) - len(o)), np.array(o)), axis=0) o = lf0_gen_with_vuv(o, vuv) o[o <= 1] = np.nan # print o.shape PlotUtility.plot([o, original, lf0, frame_lf0], ['dct', 'original', 'Multi', 'frame_lf0'], '{}/{}_dct.eps'.format(figure_path, name)) pass
def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] syllable_base_path = config['syllable_base_path'] syllable_var_path = config['syllable_var_path'] #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) print lf0_cov var = np.load('{}'.format(var_path)) vv = [] for i, v in enumerate(var): vv.append(v[i]) lf0_var = np.array(vv) lf0_mean = np.array([lf0_mean[:, 0], lf0_mean[:, 1], lf0_mean[:, 2]]) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov)) frame_B = alpha * PoGUtility.cal_sum_of_mean_part(lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part( lf0_var, lf0_w, lf0_cov) #----------Syllable level--------# dur_list, names = PoGUtility.gen_dur_and_name_list(label_path, name) # print dur_list # print names syl_mean = np.load('{}/mean.npy'.format(syllable_base_path)) syl_cov = np.load('{}/cov.npy'.format(syllable_base_path)) print syl_cov var = np.load('{}'.format(syllable_var_path)) # print var vv = [] for i, v in enumerate(var): vv.append(v[i]) syl_var = np.array(vv) temp_mean = [] for i in range(len(syl_mean[0])): temp_mean.append(syl_mean[:, i]) syl_mean = np.array(temp_mean) syl_w = PoGUtility.generate_DCT_W(len(lf0_cov), dur_list, num_coeff) syl_B = beta * PoGUtility.cal_sum_of_mean_part(syl_var, syl_w, syl_cov, syl_mean) syl_A = beta * PoGUtility.cal_sum_of_weight_part(syl_var, syl_w, syl_cov) # print syl_B Utility.write_to_file_line_by_line('./syl_B.txt', syl_B) Utility.write_to_file_line_by_line('./syl_A.txt', syl_A) #----------Combine Model--------# lf0 = np.dot(inv(frame_A + syl_A), (frame_B + syl_B)) print lf0.shape print lf0 np.save(outfilepath, lf0) Utility.write_to_file_line_by_line('./temp.txt', lf0) sys.exit() pass
def cal_suprasegmental(level, config, coeff_end_position, coeff_start_position=0, use_consonant=False, const=1.0): syllable_label_path = config['label_path'] name = config['name'] original = config['original'] base_path = config['base_path'] var_path = config['var_path'] number_of_frame = config['number_of_frame'] num_coeff = config['num_coeff'] stress_list = config['stress_list'] vuv = np.load('{}/class.npy'.format(config['vuv_path'])) tone = config['tone'] stress_type = config['stress_type'] ph_in_syl_object_path = config['phone_in_syllable_object_path'] p_in_s_file = Utility.load_obj(ph_in_syl_object_path) if level == 'syllable': dur_list, names = PoGUtility.gen_dur_and_name_list( syllable_label_path, name) elif level == 'phone': dur_list, names = PoGUtility.gen_dur_and_name_list_for_phone( syllable_label_path, name, config['ph_duration_path']) if np.sum(dur_list) < len(original): dur_list[0] = dur_list[0] + len(original) - np.sum(dur_list) mean = np.load('{}/mean.npy'.format(base_path)) cov = np.load('{}/cov.npy'.format(base_path)) # Reshape var var = np.load('{}'.format(var_path)) var = np.sum(var, axis=0) # Reshape mean temp_mean = [] for i in range(len(mean[0])): temp_mean.append(mean[:, i]) mean = np.array(temp_mean) w = JointModule.generate_DCT_W(number_of_frame, dur_list, num_coeff, stress_list, vuv, tone, stress_type, p_in_s_file, use_consonant=use_consonant) w = w[coeff_start_position:coeff_end_position] # s_B = const * PoGUtility.cal_sum_of_mean_part(var, w, cov, mean) # s_A = const * PoGUtility.cal_sum_of_weight_part(var, w, cov) s_B = PoGUtility.cal_sum_of_mean_part(var, w, cov, mean) s_A = PoGUtility.cal_sum_of_weight_part(var, w, cov) return (s_A, s_B)
def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] syllable_base_path = config['syllable_base_path'] syllable_var_path = config['syllable_var_path'] original = config['original'] koriyama_gen = config['koriyama_gen'] figure_path = config['figure_path'] vuv = np.load('{}/class.npy'.format(config['vuv_path'])) #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) var = np.load('{}'.format(var_path)) lf0_var = np.sum(var, axis=0) lf0_mean = np.array( [ lf0_mean[:,0], lf0_mean[:,1], lf0_mean[:,2] ] ) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov), vuv) frame_B = alpha * PoGUtility.cal_sum_of_mean_part(lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part(lf0_var, lf0_w, lf0_cov) L = linalg.cholesky(frame_A, lower=True) lf0 = linalg.cho_solve((L, True) , frame_B) lf0 = lf0_gen_with_vuv(lf0, vuv) print lf0.shape lf0[lf0<0] = np.nan frame_lf0 = lf0 #----------Syllable level--------# dur_list, names = PoGUtility.gen_dur_and_name_list(label_path, name) # print np.sum(dur_list) if np.sum(dur_list) < len(original): dur_list[0] = dur_list[0] + len(original)-np.sum(dur_list) # print np.sum(dur_list) syl_mean = np.load('{}/mean.npy'.format(syllable_base_path)) syl_cov = np.load('{}/cov.npy'.format(syllable_base_path)) s_mean = syl_mean var = np.load('{}'.format(syllable_var_path)) syl_var = np.sum(var, axis=0) temp_mean = [] for i in range( len(syl_mean[0]) ): temp_mean.append( syl_mean[:,i] ) syl_mean = np.array(temp_mean) syl_w = PoGUtility.generate_DCT_W_with_vuv(len(lf0_cov), dur_list, num_coeff, vuv) syl_B = beta * PoGUtility.cal_sum_of_mean_part(syl_var, syl_w, syl_cov, syl_mean) syl_A = beta * PoGUtility.cal_sum_of_weight_part(syl_var, syl_w, syl_cov) # print syl_B # Utility.write_to_file_line_by_line('./syl_B.txt', syl_B) # Utility.write_to_file_line_by_line('./syl_A.txt', syl_A) #----------Combine Model--------# L = linalg.cholesky(frame_A + syl_A, lower=True) lf0 = linalg.cho_solve((L, True) , frame_B + syl_B) # lf0 = np.dot( # inv(frame_A + syl_A), # frame_B + syl_B # ) lf0 = lf0_gen_with_vuv(lf0, vuv) # print lf0.shape lf0[lf0<0] = np.nan np.save(outfilepath, lf0) PlotUtility.plot([lf0, original, frame_lf0], ['Multi', 'original', 'Single'], '{}/{}_multi.eps'.format(figure_path, name)) #----------Combine Model--------# o = [] for data_dct, dur in zip(s_mean, dur_list): i_dct = PoGUtility.generate_inverse_DCT(data_dct, dur) o = o + i_dct o = np.concatenate( (np.zeros(len(original)-len(o)), np.array(o)) , axis=0) o = lf0_gen_with_vuv(o, vuv) o[o<0] = np.nan # print o.shape PlotUtility.plot([o, original, lf0], ['dct', 'original', 'Multi'], '{}/{}_dct.eps'.format(figure_path, name)) pass