def test_short_background_fg_events(): foreground_fd = os.path.join(absolute_dir_path, "material", "soundbank", "foreground") background_fd = os.path.join(absolute_dir_path, "material", "soundbank", "background") sc = Scaper(10, foreground_fd, background_fd, random_state=2020) sc.sr = 16000 sc.add_background( ("const", "label"), ("const", os.path.join(background_fd, "label", "noise-free-sound-0055.wav")), ("const", 0)) fname = "test_bg_fg" fpath = os.path.join(absolute_dir_path, "generated", "short_bg_scaper", fname) sc.add_event( ("const", "label"), ("const", os.path.join(foreground_fd, "label", "26104_0.wav")), ("const", 0), ("const", 5), ("const", 5), ("const", 6), ("const", 0), ("const", 1)) sc.generate(f"{fpath}.wav", f"{fpath}.jams") audio_g, sr_g = soundfile.read(f"{fpath}.wav") audio_s, sr_s = soundfile.read( os.path.join(absolute_dir_path, "material", "scaper", f"{fname}.wav")) print(f"audio gen: {audio_g}") print(f"audio source: {audio_s}") print(f"shapes, source: {audio_s.shape}, gen: {audio_g.shape}") assert audio_g.shape == audio_s.shape
def __test_gini_from_event_times(event_time_list, expected_gini, hop_size=0.01): print(event_time_list) # create scaper sc = Scaper(10.0, FG_PATH, BG_PATH) # add background sc.add_background(label=('choose', []), source_file=('choose', []), source_time=('const', 0)) # add foreground events based on the event time list # always use siren file since it is 26 s long, so we can choose the # event duration flexibly for onset, offset in event_time_list: sc.add_event(label=('const', 'siren'), source_file=('const', SIREN_FILE), source_time=('const', 0), event_time=('const', onset), event_duration=('const', offset - onset), snr=('uniform', 6, 30), pitch_shift=('uniform', -3, 3), time_stretch=None) jam = sc._instantiate() ann = jam.annotations[0] gini = polyphony_gini(ann, hop_size=hop_size) print(gini, expected_gini) assert np.allclose([gini], [expected_gini], atol=1e-5)