out_train_folder = osp.join(base_folder, 'audio', 'train', 'synthetic') if args.save_jams: out_folder_jams_train = out_train_folder else: out_folder_jams_train = None out_train_tsv = osp.join(base_folder, 'metadata', 'train', 'soundscapes', 'synthetic.tsv') list_jams_train = glob.glob(osp.join(train_folder, "*.jams")) fg_path_train = osp.join(base_folder, "audio", "train", "soundbank", "foreground") bg_path_train = osp.join(base_folder, 'audio', "train", "soundbank", "background") generate_files_from_jams(list_jams_train, out_train_folder, fg_path=fg_path_train, bg_path=bg_path_train, out_folder_jams=out_folder_jams_train) generate_tsv_from_jams(list_jams_train, out_train_tsv) # ######## # Eval # ######## # In the evaluation part, there multiple subsets which allows to check robustness of systems eval_folder = osp.join(base_folder, 'metadata', 'eval', "soundscapes") list_folders = [ osp.join(eval_folder, dI) for dI in os.listdir(eval_folder) if osp.isdir(osp.join(eval_folder, dI)) ] fg_path_eval = osp.join(base_folder, "audio", "eval", "soundbank", "foreground")
def test_generate_files_from_jams(): generate_files_from_jams( [os.path.join(absolute_dir_path, "material", "5.jams")], os.path.join(absolute_dir_path, "generated", "generated_from_jams"))
post_process_txt_labels(out_folder_30, output_folder=out_folder_30, output_tsv=out_tsv) # ### # Generate variation of the dataset by varying the FBSNR # ### # We create the same dataset with different background SNR # The foreground background snr ratio is between 0dB and 24dB (see utils snr_min (6dB) and snr_max (30dB)) out_folder_24 = osp.join(out_folder, "24dB") create_folder(out_folder_24) jams_to_modify = glob.glob(osp.join(out_folder_30, "*.jams")) # Put FBSNR to [0;24] range so reducing of 6 compared to [6;30] minus_6_snr = functools.partial(change_snr, db_change=-6) new_jams24 = modify_jams(jams_to_modify, minus_6_snr, out_folder_24) generate_files_from_jams(new_jams24, out_folder_24, out_folder_24) # Same for 15 out_folder_15 = osp.join(out_folder, "15dB") create_folder(out_folder_15) minus_15_snr = functools.partial(change_snr, db_change=-15) new_jams15 = modify_jams(jams_to_modify, minus_15_snr, out_folder_15) generate_files_from_jams(new_jams15, out_folder_15, out_folder_15) out_folder_0 = osp.join(out_folder, "0dB") create_folder(out_folder_0) minus_30_snr = functools.partial(change_snr, db_change=-30) new_jams0 = modify_jams(jams_to_modify, minus_30_snr, out_folder_0) generate_files_from_jams(new_jams0, out_folder_0, out_folder_0)
"one_event_train") meta_eval_folder = osp.join(dataset_root, "metadata", "eval") audio_train_folder = osp.join(dataset_root, "audio", "train", "one_event_train") audio_eval_folder = osp.join(dataset_root, "audio", "eval") list_jams = glob.glob(osp.join(meta_train_folder, "*.jams"))[:10] fg_path_train = osp.join(soundbank_root, "audio", "train", "soundbank", "foreground") bg_path_train = osp.join(soundbank_root, "audio", "train", "soundbank", "background") generate_files_from_jams(list_jams, audio_train_folder, fg_path=fg_path_train, bg_path=bg_path_train, overwrite_jams=args.overwrite_jams) # Eval # In the evaluation part, there multiple subsets which allows to check robustness of systems list_folders = [ osp.join(meta_eval_folder, dI) for dI in os.listdir(meta_eval_folder) if osp.isdir(osp.join(meta_eval_folder, dI)) ] fg_path_eval = osp.join(soundbank_root, "audio", "eval", "soundbank", "foreground") bg_path_eval = osp.join(soundbank_root, "audio", "eval", "soundbank", "background") for folder in list_folders:
soundbank_dir = args.soundbank fg_path_train = osp.join(soundbank_dir, "foreground") bg_path_train = osp.join(soundbank_dir, "background") out_audio_dir = args.out_audio_dir if out_audio_dir is None: out_audio_dir = jams_folder if args.save_jams: out_folder_jams = out_audio_dir else: out_folder_jams = None out_tsv = args.out_tsv if out_tsv is None: out_tsv = out_audio_dir.replace("audio", "metadata") + ".tsv" save_isolated = args.save_isolated # ######## # Generate # ####### generate_files_from_jams(list_jams, out_audio_dir, out_folder_jams=out_folder_jams, fg_path=fg_path_train, bg_path=bg_path_train, save_isolated_events=save_isolated) if out_tsv: generate_tsv_from_jams(list_jams, out_tsv)
# Replace duration line, needed to do the del add because of the type of data new_obs = jams_obj["annotations"][0].data[cnt]._replace( duration=time_trunc) del jams_obj["annotations"][0].data[cnt] jams_obj["annotations"][0].data.add(new_obs) return jams_obj if __name__ == '__main__': base_soundbank = osp.join("..", "..", "synthetic") for subset in ["train", "eval"]: soundbank_path = osp.join(base_soundbank, "audio", subset, "soundbank") fg_folder = osp.join(soundbank_path, "foreground/") bg_folder = osp.join(soundbank_path, "background") dataset_path = osp.join("..", "..", "dataset") jams_folder = osp.join(dataset_path, "audio", subset, f"one_event_generated") outfolder = osp.join(dataset_path, "audio", subset, f"one_event_generated_200ms") outtsv = osp.join(dataset_path, "metadata", subset, f"one_event_generated_200ms.tsv") list_jams = glob.glob(os.path.join(jams_folder, "*.jams")) new_jams = modify_jams(list_jams, get_part_audio, outfolder) generate_files_from_jams(new_jams, outfolder) generate_tsv_from_jams(new_jams, outtsv)