"guard_zone_width": 0.5, }, "output_file": "experiment_speed_11_17_results.json", } # Placeholder to hold all the results sim_results = {"config": config, "room_info": [], "data": []} if __name__ == "__main__": np.random.seed(config["seed"]) min_sources = np.min(config["n_sources_list"]) max_sources = np.max(config["n_sources_list"]) audio_files = sampling(config["n_repeat"], min_sources, config["samples_metadata"]) ref_mic = config["separation_params"]["ref_mic"] for room_id, file_list in enumerate(audio_files): audio = wav_read_center(file_list) # Get a random room and simulate room, rt60 = random_room_builder(audio, max_sources, **config["room_params"]) premix = room.simulate(return_premix=True) sim_results["room_info"].append( { "dim": room.shoebox_dim.tolist(), "rt60": rt60, "id": room_id, "samples": file_list,
def exp1_gen_args(config): np.random.seed(config["seed"]) # sub-seeds sub_seeds = [] for r in range(config["repeat"]): sub_seeds.append(int(np.random.randint(2 ** 32))) # maximum number of sources and microphones in the simulation if config["n_targets"] == "determined": n_sources = np.max(config["n_mics"]) else: n_sources = np.max(config["n_interferers"]) + np.max(config["n_targets"]) n_mics = np.max(config["n_mics"]) room_file = Path(config["room_cache_file"]) regenerate_rooms = True # assume we need to start over # now check the content of the cache if it exists if room_file.exists(): with open(room_file, "r") as f: room_cache = json.load(f) # if the content of the config file changes, we should generate again if not ( room_cache["seed"] != config["seed"] or room_cache["room_params"] != config["room_params"] or len(room_cache["rooms"]) != config["repeat"] ): regenerate_rooms = False if not regenerate_rooms: # use the content of the cache print("Use the rooms in the cache") rooms = room_cache["rooms"] rt60s = room_cache["rt60s"] else: # generate all the rooms print("Generate the rooms and measure rt60") # choose all the files in advance gen_files_seed = int(np.random.randint(2 ** 32, dtype=np.uint32)) all_wav_files = sampling( config["repeat"], n_sources, config["samples_list"], gender_balanced=True, seed=gen_files_seed, ) # generates all the rooms in advance too rooms = [] rt60s = [] for i in range(config["repeat"]): room_params, rt60 = random_room_definition( n_sources, n_mics, seed=i, **config["room_params"] ) # add the speech signal files to use room_params["wav"] = all_wav_files[r] rt60s.append(rt60) rooms.append(room_params) # cache the rooms with open(room_file, "w") as f: json.dump( { "seed": config["seed"], "room_params": config["room_params"], "rooms": rooms, "rt60s": rt60s, }, f, ) print("Done generating the rooms") # now generates all the other argument combinations args = [] for sinr in config["sinr"]: for n_interf in config["n_interferers"]: for n_mics in config["n_mics"]: # in the determined case, n_mics == n_targets if config["n_targets"] == "determined": n_targets_lst = [n_mics] else: n_targets_lst = config["n_targets"] for n_targets in n_targets_lst: for dist_ratio in config["dist_crit_ratio"]: for r in range(config["repeat"]): # bundle all the room parameters for the simulation room_params = rooms[r] args.append( ( sinr, n_targets, n_interf, n_mics, dist_ratio, room_params, sub_seeds[r], ) ) return args
) target_locs = semi_circle_layout( [4.1, 3.755, 1.1], np.pi / 2, 2.0, n_sources_target, rot=0.743 * np.pi ) # interferer_locs = grid_layout([3., 5.5], n_sources - n_sources_target, offset=[6.5, 1., 1.7]) interferer_locs = random_layout( [3.0, 5.5, 1.5], n_sources - n_sources_target, offset=[6.5, 1.0, 0.5], ) source_locs = np.concatenate((target_locs, interferer_locs), axis=1) # Prepare the signals wav_files = sampling( 1, n_sources, f"{samples_dir}/metadata.json", gender_balanced=True, seed=args.seed, )[0] signals = wav_read_center(wav_files, seed=123) # Create the room itself room = pra.ShoeBox(room_dim, fs=fs, absorption=absorption, max_order=max_order) # Place a source of white noise playing for 5 s for sig, loc in zip(signals, source_locs.T): room.add_source(loc, signal=sig) # Place the microphone array room.add_microphone_array(pra.MicrophoneArray(mic_locs, fs=room.fs))
def exp2_gen_args(config): # infer a few arguments room_dim = config["room"]["room_kwargs"]["p"] mic_array_center = np.array(config["room"]["mic_array_location_m"]) mic_array = mic_array_center[None, :] + np.array( config["room"]["mic_array_geometry_m"] ) mic_array = mic_array.T critical_distance = config["room"]["critical_distance_m"] # master seed np.random.seed(config["seed"]) # choose all the files in advance gen_files_seed = int(np.random.randint(2 ** 32, dtype=np.uint32)) all_wav_files = sampling( config["repeat"], np.max(config["n_targets"]) + np.max(config["n_interferers"]), config["samples_list"], gender_balanced=True, seed=gen_files_seed, ) # sub-seeds sub_seeds = [] for r in range(config["repeat"]): sub_seeds.append(int(np.random.randint(2 ** 32))) # create all distinct interferers locations interferers_locs = [] for n in range(config["repeat"]): interferers_locs.append( random_locations( np.max(config["n_interferers"]), room_dim, mic_array_center, min_dist=critical_distance, ).tolist() ) # create all distinct target locations target_locs = {} for r in range(config["repeat"]): # pick rotation random_rot = np.random.rand() * 2 * np.pi target_locs[r] = {} for n in config["n_targets"]: target_locs[r][n] = {} for dist_ratio in config["dist_crit_ratio"]: dist_mic_target = dist_ratio * critical_distance target_locs[r][n][dist_ratio] = choose_target_locations( n, mic_array_center, dist_mic_target ).tolist() args = [] for sinr in config["sinr"]: for n_targets in config["n_targets"]: for n_interf in config["n_interferers"]: for n_mics in config["n_mics"]: for dist_ratio in config["dist_crit_ratio"]: for r in range(config["repeat"]): assert ( n_mics == mic_array.shape[1] ), "n_mics and number of microphones used should match" # bundle all the room parameters for the simulation room_params = { "room_kwargs": config["room"]["room_kwargs"], "mic_array": mic_array.tolist(), "sources": np.concatenate( ( target_locs[r][n_targets][dist_ratio], interferers_locs[r], ), axis=1, ).tolist(), "wav": all_wav_files[r][: n_targets + n_interf], } args.append( ( sinr, n_targets, n_interf, n_mics, dist_ratio, room_params, sub_seeds[r], ) ) return args
critical_distance = config["room"]["critical_distance_m"] # all source locations target_locs = choose_target_locations(n_sources_target, mic_array_center, dist_ratio * critical_distance) interferers_locs = random_locations(args.interf, room_dim, mic_array_center, min_dist=critical_distance) source_locs = np.concatenate((target_locs, interferers_locs), axis=1) # Prepare the signals wav_files = sampling( 1, n_sources, f"{samples_dir}/metadata.json", gender_balanced=True, seed=np.random.randint(2**32), )[0] signals = wav_read_center(wav_files, seed=123) # Create the room itself room = pra.ShoeBox(**config["room"]["room_kwargs"]) # Place a source of white noise playing for 5 s for sig, loc in zip(signals, source_locs.T): room.add_source(loc, signal=sig) # Place the microphone array room.add_microphone_array(pra.MicrophoneArray(mic_locs, fs=room.fs))