Пример #1
0
def score_feature_sequences_gmm(in_file_list, htk_model_file, out_dir):
    '''
    Read an HTK model file defining a set of GMMs and score the input feature files
    based on these GMMs
    '''
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    # Read ASCII mmf file
    htk_mmf = open(htk_model_file, 'r')
    models, hmm_mgr, gmm_mgr = htkmmf.read_htk_mmf_file(htk_mmf,
                                                        log_domain=True)
    htk_mmf.close()

    # Read feature files and score
    in_list = open(in_file_list, 'r')
    for fl in in_list:
        fl = fl.rstrip('\r\n')
        print fl
        feature_file = open(fl, 'r')
        features = htkaudio.read_htk_audio_file(feature_file)
        feature_file.close()
        scores = []
        n_models = gmm_mgr.num_models
        for md in range(n_models):
            model_scores = gmm_mgr.get_model(md).score(features)
            scores.append(model_scores)

        score_file = os.path.join(
            out_dir,
            os.path.splitext(os.path.split(feature_file)[1])[0] + '.sco')
        n_frames = len(scores[0])
        sco_fl = open(score_file, 'w')
        for count in range(n_frames):
            for m_count in range(n_models):
                sco_fl.write('{} '.format(scores[m_count][count]))
            sco_fl.write('\n')
        sco_fl.close()

    in_list.close()
def score_feature_sequences_gmm(in_file_list, htk_model_file, out_dir):
    '''
    Read an HTK model file defining a set of GMMs and score the input feature files
    based on these GMMs
    '''
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    # Read ASCII mmf file
    htk_mmf = open(htk_model_file,'r')
    models, hmm_mgr, gmm_mgr  = htkmmf.read_htk_mmf_file(htk_mmf, log_domain=True)
    htk_mmf.close()

    # Read feature files and score
    in_list = open(in_file_list, 'r')
    for fl in in_list:
        fl = fl.rstrip('\r\n')
        print fl
        feature_file = open(fl,'r')
        features = htkaudio.read_htk_audio_file(feature_file)
        feature_file.close()
        scores = []
        n_models = gmm_mgr.num_models
        for md in range(n_models):
           model_scores = gmm_mgr.get_model(md).score(features)
           scores.append(model_scores)

        score_file = os.path.join(out_dir, os.path.splitext(os.path.split(feature_file)[1])[0]+'.sco')
        n_frames = len(scores[0])
        sco_fl = open(score_file,'w')
        for count in range(n_frames):
            for m_count in range(n_models):
                sco_fl.write('{} '.format(scores[m_count][count]))
            sco_fl.write('\n')
        sco_fl.close()

    in_list.close()
Пример #3
0
def htkmmf2native(htk_file_name, native_file_name):
     with open(htk_file_name) as f_in:
         models, hmm_mgr, gmm_mgr = read_htk_mmf_file(f_in)
     with open(native_file_name, 'wb') as f_out:
         write_acoustic_model(models, gmm_mgr, hmm_mgr, f_out)
Пример #4
0
def htkmmf2native(htk_file_name, native_file_name):
    with open(htk_file_name) as f_in:
        models, hmm_mgr, gmm_mgr = read_htk_mmf_file(f_in)
    with open(native_file_name, 'wb') as f_out:
        write_acoustic_model(models, gmm_mgr, hmm_mgr, f_out)