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)
for s in Utility.char_range('a', 'z'): set_label_path = '{}/{}/'.format(label_path, s) set_dct_path = '{}/{}/'.format(outpath, s) Utility.make_directory(set_dct_path) for x in range(1, 51): name = 'tscsd{}{}'.format(s, Utility.fill_zero(x, 2)) file_path = '{}/{}.lab'.format(set_label_path, name) if not Utility.is_file_exist(file_path): continue dur_list, names = PoGUtility.gen_dur_and_name_list_for_phone( file_path, name) # sys.exit() # if len(dur_list) != len(names): # print name, len(dur_list), len(names) dct_list = [] for n in names: case = 0 if n in syl_dict: if (tone == 'all') & (int(syl_dict[n]['stress']) == stress_dict[stress_type]):