def dataset_modification(config_path, output_path):

    data_config_path = '{}/data.yaml'.format(config_path)

    data = Utility.yaml_load(data_config_path)

    dataset = data['subset']

    print dataset

    for i in xrange(5, 20, 4):
        
        if training_set[i-1] == 'i': 
            continue

        subset = training_set[0:i]
        # print subset
        # print len(subset), len(subset)*50

        dataset[ '{}-{}'.format(subset[0], subset[len(subset)-1]) ] = subset

    # print dataset
    # print data

    Utility.yaml_save('{}/data.yaml'.format(output_path), data)

    pass
Example #2
0
    def get_context_list_of_a_phone(filepath, target_phone):
        yaml_file = Utility.yaml_load(filepath)
        #         print yaml_file['preprocess']
        print 'Target phone : {}'.format(target_phone)
        for event in yaml_file['context_events']:
            name = event['name']
            args = event['value_getter']['event_feature']['args']
            type = None
            if len(args) > 1:
                type = args[1]['args'][0]

#             print type

            if type == 'entity':
                d = "{}".format(args[0])
                d = d.split(',')
                for ph in d:
                    if '\'{}\''.format(target_phone) in ph:
                        ph = '{}'.format(ph)
                        ph = ph.split('[')[-1].split(']')[0]
                        #                         print ph
                        #                         if int(ph) == 1:
                        if 'begin' in name:
                            if ph == '{}'.format(1):
                                print name, ph

#                 print d

#             break

#         Utility.print_yaml_formatted(yaml_file['context_events'][2])
#         Utility.print_yaml_formatted(yaml_file['context_events'][2]['name'])
#         Utility.print_yaml_formatted(yaml_file['context_events'][2]['value_getter']['event_feature']['args'][0]['uua'])
        pass
def change_exp(config_path, output_path, subset):

    exp = Utility.yaml_load( '{}/experiment.yaml'.format(config_path) )

    exp['data_set']['optim_dur'] = 'a-{}'.format(subset[len(subset)-1])
    exp['data_set']['train'] = 'a-{}'.format(subset[len(subset)-1])

    print exp

    Utility.yaml_save('{}/experiment.yaml'.format(output_path), exp)

    pass
def run_gen_mono(utt_set):

    set_path = '{}/{}/'.format(utterance_path, utt_set)

    set_syllable_base_path = '{}/{}/'.format(syllable_base, utt_set)

    out_set_path = '{}/{}/'.format(output_path, utt_set)
    Utility.make_directory(out_set_path)

    for i in xrange(1, 51):
        utt_file = Utility.yaml_load('{}/tscsd{}{}.utt.yaml'.format(
            set_path, utt_set, Utility.fill_zero(i, 2)))
        # print utt_file

        out_file = '{}/tscsd{}{}.lab'.format(out_set_path, utt_set,
                                             Utility.fill_zero(i, 2))

        stress_list = []
        recursion(utt_file, stress_list)

        syllable_time_label = Utility.read_file_line_by_line(
            '{}/tscsd{}{}.lab'.format(set_syllable_base_path, utt_set,
                                      Utility.fill_zero(i, 2)))
        # print stress_list, len(stress_list)
        # print len(syllable_time_label)
        if len(syllable_time_label) != len(stress_list):
            print utt_set, i
            # print 'Error'
            # sys.exit()

        out = []
        for idx, line in enumerate(syllable_time_label):
            # print line, stress_list[idx]
            o = '{}::{}'.format(
                Utility.trim(line).replace('-', '_').replace('+', '_'),
                stress_list[idx])
            # print o
            out.append(o)

        Utility.write_to_file_line_by_line(out_file, out)

        # sys.exit()

    pass
        Utility.make_directory(set_out_path)

        if Utility.is_dir_exists(set_stress_path) & Utility.is_dir_exists(set_utt_base_path):
            print ch

            for i in xrange(1, 51):

                name = 'tscsd{}{}'.format(ch, Utility.fill_zero(i, 2))

                yaml_filename = '{}/{}.utt.yaml'.format(set_utt_base_path, name )
                if not Utility.is_file_exist(yaml_filename):
                    continue

                full_file = '{}/{}.lab'.format(set_syllable_full_path, name)

                count = [0]
                yaml = Utility.yaml_load(yaml_filename)
                add_stress(yaml, count, name)

                if not (len(Utility.read_file_line_by_line(full_file)) == count[0] ):
                    print 'Not equal'
                    print name, len(Utility.read_file_line_by_line(full_file)), count[0]

                out_file = '{}/{}.utt.yaml'.format(set_out_path, name)
                Utility.yaml_save(out_file, yaml)

    print 'all no {} names '.format(coun_no)

    pass
Example #6
0

def get_syllable_list_from_syl_based_utterance_object(utt, syl_list=[]):

    for u in utt:
        # print u
        if u['unit'] == 'syllable':
            syl = '{}-{}-{}-{}'.format(u['consonant'], u['vowel'],
                                       u['final_consonant'], u['tone_type'])
            syl_list.append(syl)
        else:
            get_syllable_list_from_syl_based_utterance_object(
                u['inners'], syl_list=syl_list)

    pass


if __name__ == '__main__':

    utt_path = '/home/h1/decha/Dropbox/Inter_speech_2016/Training_data/03_GPR_syllable_level/utt/tsc/sd/a/tscsda01.utt.yaml'

    utt = Utility.yaml_load(utt_path)

    syl_list = []
    get_syllable_list_from_syl_based_utterance_object(utt, syl_list=syl_list)

    print syl_list

    # Utility.print_yaml_formatted(utt)

    pass