Exemple #1
0
def extract_mfcc(input_wav_dir, output_feature_file, output_feature_dir):
    # secure destination
    mkdir_for_file(output_feature_file)
    mkdir_for_dir(output_feature_dir)
    
    # extract mfcc in single file format and dir format
    import util
    mkdir_for_dir(default_temp_dir)
    util.make_feature(input_wav_dir, default_temp_dir)

    def write_feat(feat, feat_id, outfile):
        outfile.write(feat_id+'.wav\n')
        for i in range(feat.shape[0]):
            fline = '{:04d} {:04d} #' + ' {:f}'*feat.shape[1] +'\n'
            outfile.write(fline.format(i, i+1, *feat[i]))
        outfile.write('\n')
    
    with open(output_feature_file, 'w') as outfile:
        for f in sorted(os.listdir(default_temp_dir)):
            feat = util.read_feature(os.path.join(default_temp_dir, f))
            write_feat(feat, f[:-4], outfile)
    
    for f in sorted(os.listdir(default_temp_dir)):
        feat = util.read_feature(os.path.join(default_temp_dir, f))
        util.write_feature(feat, os.path.join(output_feature_dir, f))

    # cleanup, remove large files
    mkdir_for_dir(default_temp_dir)
Exemple #2
0
 def read_feature_dir(feature_dir):
     import util
     feat, feat_id = [], []
     for f in sorted(os.listdir(feature_dir)):
         feature = util.read_feature(os.path.join(feature_dir, f))
         feat.append(feature)
         feat_id.append(f[:-4])
     return feat, feat_id
Exemple #3
0
 def feature_dtw(self, query_index, inst_index):
     Q = self.feature_query(query_index, inst_index)
     similarity = []
     for ___ in range(len(self.query_mlf.wav_list)):
         similarity.append(float('Inf'))
     for w in range(len(self.query_mlf.wav_list)):
         f_file = self.feature_fold + self.query_mlf.wav_list[w] + '.mfc'
         D = util.read_feature(f_file)
         similarity[w] = util.warp(util.cos_dist(D, Q))
         # similarity[w] = util.warp(- np.dot(D,Q.T))
         print query_index, w, similarity[w]
     return similarity
Exemple #4
0
 def feature_query(self, query_index, inst_index):
     w_index, t_beg, t_end = self.query_answer[query_index][inst_index]
     # print self.feature_fold + self.query_mlf.wav_list[w_index]
     f_file = self.feature_fold + self.query_mlf.wav_list[w_index] + '.mfc'
     return util.read_feature(f_file)[t_beg:t_end]