Exemple #1
0
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
Exemple #2
0
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']

    #----------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_mean, cccc = gen_mean_and_cov_of_dct_fake(names)

    syl_cov = np.load('{}/cov.npy'.format(syllable_base_path))

    print syl_cov

    var = np.load('{}'.format(syllable_var_path))
    vv = []
    for i, v in enumerate(var):
        vv.append(v[i])
    syl_var = np.array(vv)

    o = []
    for data_dct, dur in zip(syl_mean, dur_list):
        i_dct = PoGUtility.generate_inverse_DCT(data_dct, dur)
        # print i_dct
        o = o + i_dct

    o = np.array(o)
    o[o < 3] = np.nan
    print o.shape

    org = Utility.read_lf0_into_ascii(
        '/work/w2/decha/Data/GPR_speccom_data/data_before_remove_silence/lf0/tsc/sd/j/{}.lf0'
        .format(name))

    org[org < 0] = np.nan

    diff = len(org) - len(o)

    plt.plot(np.arange(len(o)) + diff, o, label='syn')
    plt.plot(range(len(org)), org, label='org')

    plt.legend()
    plt.savefig('./{}_dct_16_test.eps'.format(name))

    sys.exit()

    pass
Exemple #3
0
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
Exemple #4
0
def cal_PoG(config):

    base_path = config['base_path']
    label_path = config['label_path']
    name = config['name']
    outfilepath = config['outfilepath']

    lf0_mean = np.load('{}/mean.npy'.format(base_path))

    # print lf0_mean[1000]

    lf0_cov = np.load('{}/cov.npy'.format(base_path))

    dur_list, names = gen_dur_and_name_list(label_path, name)

    w = gen_W(len(lf0_mean), dur_list, num_coeff)

    syllable_mean, syllable_cov = gen_mean_and_cov_of_dct(names)

    print w.shape, syllable_mean.shape, syllable_cov.shape, lf0_mean.shape, lf0_cov.shape

    mean, cov = PoGUtility.cal_mean_variance_of_product_of_gaussian(
        w, syllable_mean, syllable_cov, lf0_mean, lf0_cov)

    # print mean.shape, cov.shape
    # print mean[1000]

    np.save('{}/mean.npy'.format(outfilepath), mean)
    np.save('{}/cov.npy'.format(outfilepath), cov)

    pass
def gen_W(number_of_frame, dur_list, num_coeff):

    w = np.zeros((num_coeff * len(dur_list), number_of_frame))

    offset_x = 0
    offset_y = 0

    for idx, d in enumerate(dur_list):

        if idx == (len(dur_list) - 1):
            d = number_of_frame - offset_x

        local_w = PoGUtility.generate_W_for_DCT(d, num_coeff)

        # print offset_x, offset_y, local_w.shape

        for i in range(num_coeff):
            w[offset_y + i][offset_x:offset_x + d] = local_w[i]

        offset_x = offset_x + d
        offset_y = offset_y + num_coeff

    return w

    pass
def cal_PoG(config):

    base_path = config['base_path']
    label_path = config['label_path']
    name = config['name']
    outfilepath = config['outfilepath']

    #--------Frame-------#

    lf0_mean = np.load('{}/mean.npy'.format(base_path))
    lf0_cov = np.load('{}/cov.npy'.format(base_path))

    print lf0_cov

    sys.exit()

    lf0_w = PoGUtility.generate_W_for_dynamic_feature_extraction(len(lf0_mean))

    #--------Syllable-------#

    dur_list, names = gen_dur_and_name_list(label_path, name)

    syllable_w = gen_W(len(lf0_mean), dur_list, num_coeff)
    syllable_mean, syllable_cov = gen_mean_and_cov_of_dct(names)

    #--------Calculation-------#

    print lf0_w.shape, lf0_mean.shape, lf0_cov.shape
    print syllable_w.shape, syllable_mean.shape, syllable_cov.shape, 

    # lf0_inv_P = PoGUtility.cal_invert_P(lf0_w, lf0_cov)
    # lf0_R = PoGUtility.cal_R(lf0_w, lf0_cov, lf0_mean)

    syllable_inv_P = PoGUtility.cal_invert_P(syllable_w, syllable_cov)
    syllable_R = PoGUtility.cal_R(syllable_w, syllable_cov, syllable_mean)

    # mean, cov = PoGUtility.cal_product_of_gaussian(lf0_R, lf0_inv_P, syllable_R, syllable_inv_P)

    # print mean
    # print cov

    sys.exit()

    # np.save('{}/mean.npy'.format(outfilepath), mean)
    # np.save('{}/cov.npy'.format(outfilepath), cov)

    pass
Exemple #7
0
    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)
        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]):
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
Exemple #10
0
    errors = dict()

    errors_list = []

    errors_tuple = []

    true = np.array([])
    dct_regen = np.array([])

    for coeff in [3, 4, 7]:

        for name in d:

            data = d[name]
            w = PoGUtility.generate_W_for_DCT(len(data), coeff)

            data_dct = PoGUtility.generate_DCT(data, coeff)
            data_dct = np.dot(w, data)

            i_dct = PoGUtility.generate_inverse_DCT(data_dct, len(data))

            true = np.concatenate((true, data))
            dct_regen = np.concatenate((dct_regen, i_dct))

            rmse = np.sqrt(sklearn.metrics.mean_squared_error(
                data, i_dct)) * 1200 / np.log(2)
            # print rmse
            errors[name] = rmse
            errors_list.append(rmse)
Exemple #11
0
        head_count, tail_count = find_head_and_tail(phone['raw_lf0'])

        raw = np.array(phone['raw_lf0'])[head_count : len(phone['raw_lf0'])-tail_count]
        # print raw

        if len(raw) < 10:
            continue
        else:
            if len(raw[raw<0]) != 0:
                # print raw
                raw = Utility.inteporate_lf0(raw)
                # print raw
            
            phone['clean_raw'] = raw
            phone_clean_dict[phone_id] = phone

            w = PoGUtility.generate_W_for_DCT(len(raw), coeff)
            data_dct = np.dot(w, raw)

            # print data_dct

            phone['dct'] = data_dct

            # sys.exit()

    print len(phone_clean_dict)
    Utility.save_obj(phone_clean_dict, new_phone_dict)

    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']

    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
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
Exemple #14
0
    def gen_W(number_of_frame,
              dur_list,
              num_coeff,
              stress_list,
              vuv,
              tone,
              stress_type,
              p_in_s_file,
              use_consonant=False):

        # print stress_list

        w = np.zeros((num_coeff * len(dur_list), number_of_frame))

        offset_x = 0
        offset_y = 0

        for idx, (d, p_in_s,
                  st) in enumerate(zip(dur_list, p_in_s_file, stress_list)):

            if idx == (len(dur_list) - 1):
                d = number_of_frame - offset_x

            if use_consonant:
                if len(p_in_s) == 0:
                    consonant = 0
                else:
                    consonant = int(float(p_in_s[0]) / float(50000.0))

                cur_vuv = vuv[offset_x + consonant:offset_x + d]
                head, tail = PoGUtility.find_head_and_tail(cur_vuv)

                if (((consonant + tail + head) > d) | (not (st[0] == '1')) |
                    (not (st[1] == '{}'.format(tone)))):
                    local_w = np.zeros((num_coeff, d))
                else:
                    # print 'panda'
                    voice_frame = d - consonant - tail - head
                    local_w = PoGUtility.generate_W_for_DCT(
                        voice_frame, num_coeff)
                    if head != 0:
                        local_w = np.concatenate((np.zeros(
                            (num_coeff, head), dtype='float'), local_w),
                                                 axis=1)
                    if tail != 0:
                        local_w = np.concatenate(
                            (local_w, np.zeros(
                                (num_coeff, tail), dtype='float')),
                            axis=1)
                    if consonant != 0:
                        local_w = np.concatenate((np.zeros(
                            (num_coeff, consonant), dtype='float'), local_w),
                                                 axis=1)

            else:
                cur_vuv = vuv[offset_x:offset_x + d]
                head, tail = PoGUtility.find_head_and_tail(cur_vuv)

                if not (st[0] == '1'):
                    st[0] = '0'

                if (((tail + head) > d) | (not (st[0] == str(stress_type))) |
                    (not (st[1] == '{}'.format(tone)))):
                    local_w = np.zeros((num_coeff, d))
                else:
                    # print 'panda'
                    voice_frame = d - tail - head
                    local_w = PoGUtility.generate_W_for_DCT(
                        voice_frame, num_coeff)

                    if head != 0:
                        local_w = np.concatenate((np.zeros(
                            (num_coeff, head), dtype='float'), local_w),
                                                 axis=1)
                    if tail != 0:
                        local_w = np.concatenate(
                            (local_w, np.zeros(
                                (num_coeff, tail), dtype='float')),
                            axis=1)

            for i in range(num_coeff):
                w[offset_y + i][offset_x:offset_x + d] = local_w[i]

            offset_x = offset_x + d
            offset_y = offset_y + num_coeff

        return w
Exemple #15
0
    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)
Exemple #16
0
    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

        mean, cov = PoGUtility.cal_mean_variance_of_product_of_gaussian(
            w, syllable_mean, syllable_cov, phone_mean, phone_cov)
Exemple #17
0
        label_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/mono/tsc/sd/'
        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(
                    file_path, name)

                if len(dur_list) != len(names):
                    print name

                # print names

                dct_list = []

                for n in names:
                    if n in syl_dict:
                        if incl_zero == 'not_include_zero_coeff':
                            dct_list.append(syl_dict[n][1:num_coeff])
                        else:
                            dct_list.append(syl_dict[n])
                    else:
from scipy.fftpack import dct, idct

import math

if __name__ == '__main__':

    syllable_dict = Utility.load_obj(
        '/work/w2/decha/Data/GPR_speccom_data/Interspeech2017/syllable_dictionary_data_with_delta_deltadelta.pkl'
    )

    for syl in syllable_dict:

        print syl

        lf0 = syllable_dict[syl][0]

        y = 0.0
        for n, f in enumerate(lf0):
            y = y + f * math.cos(math.pi * 0 * (2.0 * n + 1) /
                                 (2.0 * len(lf0)))

        W = PoGUtility.generate_W_for_DCT(len(lf0), len(lf0))

        lf0_dct = dct(lf0, norm='ortho')

        print lf0_dct

        sys.exit()

    pass