Esempio n. 1
0
 def process(self, line):
     """
     Process a line from an SCP file, generate an MlfBlock Event from the
     filename, and call the sendee with it
     """        
     # print line
     fname = line.strip()
     # We silently skip any blank or whitespace-only lines
     if len(fname) == 0:
         return
     if self._prefix_subst is not None and fname.startswith(self._prefix_subst[0]):
         fname = fname.replace(self._prefix_subst[0], self._prefix_subst[1], 1)
     with open(fname, 'rb') as f:
         (data, (kind, qualifiers), samp_period) = read_htk_audio_file(f)
     self.send(HTKAudioBlockEvent(fname, (kind, qualifiers, samp_period), data))
Esempio n. 2
0
 def process(self, line):
     """
     Process a line from an SCP file, generate an MlfBlock Event from the
     filename, and call the sendee with it
     """
     # print line
     fname = line.strip()
     # We silently skip any blank or whitespace-only lines
     if len(fname) == 0:
         return
     if self._prefix_subst is not None and fname.startswith(
             self._prefix_subst[0]):
         fname = fname.replace(self._prefix_subst[0], self._prefix_subst[1],
                               1)
     with open(fname, 'rb') as f:
         (data, (kind, qualifiers), samp_period) = read_htk_audio_file(f)
     self.send(
         HTKAudioBlockEvent(fname, (kind, qualifiers, samp_period), data))
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()