def import_data(audio, label, rootpath, output_path): data_file = '%s/features/BEATLES_TUT/%s.pickle' % ( output_path, os.path.splitext(os.path.basename(audio))[0]) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print audio, 'cached!' else: try: X_c, X_t, B = features(audio) Y, T, L = align_segmentation(label, B) Data = { 'features': (X_c, X_t), 'beats': B, 'filename': audio, 'segment_times': T, 'segment_labels': L, 'segments': Y } print audio, 'processed!' with open(data_file, 'w') as f: pickle.dump(Data, f) except Exception as e: print audio, 'failed!' print e Data = None return Data
def import_data(song, rootpath, output_path): data_file = '%s/features/SALAMI/%s.pickle' % (output_path, os.path.splitext(os.path.basename(song))[0]) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) Y, T, L = align_segmentation(get_annotation(song, rootpath), Data['beats']) Data['segment_times'] = T Data['segment_labels'] = L Data['segments'] = Y print song, 'cached!' else: try: X_c, X_t, B = features(song) Y, T, L = align_segmentation(get_annotation(song, rootpath), B) Data = {'features': (X_c, X_t), 'beats': B, 'filename': song, 'segment_times': T, 'segment_labels': L, 'segments': Y} print song, 'processed!' with open(data_file, 'w') as f: pickle.dump( Data, f ) except Exception as e: print song, 'failed!' print e Data = None return Data
def import_data(song, rootpath, output_path): data_file = '%s/features/SALAMI/%s.pickle' % ( output_path, os.path.splitext(os.path.basename(song))[0]) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print song, 'cached!' else: try: X, B = features(song) Y, T, L = align_segmentation(get_annotation(song, rootpath), B) Data = { 'features': X, 'beats': B, 'filename': song, 'segment_times': T, 'segment_labels': L, 'segments': Y } print song, 'processed!' with open(data_file, 'w') as f: pickle.dump(Data, f) except Exception as e: print song, 'failed!' print e Data = None return Data
def import_data(audio, label, rootpath, output_path): data_file = '%s/features/BEATLES/%s.pickle' % (output_path, os.path.splitext(os.path.basename(audio))[0]) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print audio, 'cached!' else: try: X, B = features(audio) Y, T, L = align_segmentation(label, B) Data = {'features': X, 'beats': B, 'filename': audio, 'segment_times': T, 'segment_labels': L, 'segments': Y} print audio, 'processed!' with open(data_file, 'w') as f: pickle.dump( Data, f ) except Exception as e: print audio, 'failed!' print e Data = None return Data
def load_features(wav_file): """Loads the audio features (or reads them if already precomputed).""" print '- ', os.path.basename(wav_file) features_file = wav_file.replace(".wav", "-feats.pk") if not os.path.isfile(features_file): X, beats = segmenter.features(wav_file) with open(features_file, "w") as f: pickle.dump((X, beats), f) else: with open(features_file, "r") as f: X, beats = pickle.load(f) return X, beats
def import_data(file_struct, rootpath, output_path, annot_beats): msaf.utils.ensure_dir(output_path) msaf.utils.ensure_dir(os.path.join(output_path, "features")) data_file = '%s/features/%s_annotbeatsE%d.pickle' % \ (output_path, os.path.splitext( os.path.basename(file_struct.audio_file))[0], annot_beats) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print file_struct.audio_file, 'cached!' else: X, dur = features(file_struct, annot_beats) pcp_obj = Features.select_features("pcp", file_struct, annot_beats, framesync=False) B = pcp_obj.frame_times[:pcp_obj.features.shape[0]] if X is None: return X Y, T, L = align_segmentation( get_annotation(file_struct.audio_file, rootpath), B, file_struct.audio_file) if Y is None: return Y Data = { 'features': X, 'beats': B, 'filename': file_struct.audio_file, 'segment_times': T, 'segment_labels': L, 'segments': Y } print file_struct.audio_file, 'processed!' with open(data_file, 'w') as f: pickle.dump(Data, f) return Data
def import_data(song, rootpath, output_path, annot_beats): msaf.utils.ensure_dir(output_path) msaf.utils.ensure_dir(os.path.join(output_path, "features")) data_file = '%s/features/%s_annotbeatsE%d.pickle' % \ (output_path, os.path.splitext(os.path.basename(song))[0], annot_beats) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print song, 'cached!' else: #try: X, B, dur = features(song, annot_beats) #plt.imshow(X, interpolation="nearest", aspect="auto"); plt.show() if X is None: return X Y, T, L = align_segmentation(get_annotation(song, rootpath), B, song) if Y is None: return Y Data = { 'features': X, 'beats': B, 'filename': song, 'segment_times': T, 'segment_labels': L, 'segments': Y } print song, 'processed!' with open(data_file, 'w') as f: pickle.dump(Data, f) #except Exception as e: # print song, 'failed!' # print e # Data = None return Data
def import_data(song, rootpath, output_path, annot_beats): msaf.utils.ensure_dir(output_path) msaf.utils.ensure_dir(os.path.join(output_path, "features")) data_file = '%s/features/%s_annotbeatsE%d.pickle' % \ (output_path, os.path.splitext(os.path.basename(song))[0], annot_beats) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print song, 'cached!' else: #try: X, B, dur = features(song, annot_beats) #plt.imshow(X, interpolation="nearest", aspect="auto"); plt.show() if X is None: return X Y, T, L = align_segmentation(get_annotation(song, rootpath), B, song) if Y is None: return Y Data = {'features': X, 'beats': B, 'filename': song, 'segment_times': T, 'segment_labels': L, 'segments': Y} print song, 'processed!' with open(data_file, 'w') as f: pickle.dump(Data, f) #except Exception as e: # print song, 'failed!' # print e # Data = None return Data
def import_data(file_struct, rootpath, output_path, annot_beats): msaf.utils.ensure_dir(output_path) msaf.utils.ensure_dir(os.path.join(output_path, "features")) data_file = '%s/features/%s_annotbeatsE%d.pickle' % \ (output_path, os.path.splitext( os.path.basename(file_struct.audio_file))[0], annot_beats) if os.path.exists(data_file): with open(data_file, 'r') as f: Data = pickle.load(f) print file_struct.audio_file, 'cached!' else: X, dur = features(file_struct, annot_beats) pcp_obj = Features.select_features("pcp", file_struct, annot_beats, framesync=False) B = pcp_obj.frame_times[:pcp_obj.features.shape[0]] if X is None: return X Y, T, L = align_segmentation( get_annotation(file_struct.audio_file, rootpath), B, file_struct.audio_file) if Y is None: return Y Data = {'features': X, 'beats': B, 'filename': file_struct.audio_file, 'segment_times': T, 'segment_labels': L, 'segments': Y} print file_struct.audio_file, 'processed!' with open(data_file, 'w') as f: pickle.dump(Data, f) return Data
annotation = J.sections.create_annotation() make_metadata(annotation) for tag, bounds in zip(labels, levels): add_level(annotation, tag, make_intervals(bounds, beats)) return J if __name__ == '__main__': parameters = segmenter.process_arguments() # Load the features print '- ', os.path.basename(parameters['input_song']) X, beats = segmenter.features(parameters['input_song']) # Load the boundary transformation W_bound = segmenter.load_transform(parameters['transform_boundary']) print '\tapplying boundary transformation...' X_bound = W_bound.dot(X) # Find the segment boundaries print '\tpredicting segments...' kmin, kmax = segmenter.get_num_segs(beats[-1]) levels, labels = get_all_levels(X_bound, kmin, kmax) J = make_jams(levels, labels, beats) with open(parameters['output_file'], 'w') as f: json.dump(J, f, indent=2)