in scripts/make_dataset.py [0:0]
def gen_scene(self, scenario_num_of_speakers, scene_i, current_write_path):
S, sig_idx = self.fetch_signals(scenario_num_of_speakers)
print(sig_idx)
scenario_RT60 = round(np.random.uniform(low=0.1, high=1.0), 2)
x = round(np.random.uniform(low=4, high=7), 2)
y = round(np.random.uniform(low=4, high=7), 2)
secnario_room_dims = [x, y, 2.5]
H, H_anechoic = self.room_gen(secnario_room_dims, scenario_RT60)
Mixed = np.zeros_like(S[0])
conv_signals = np.zeros_like(S)
angles_name = '_'
for spk in range(scenario_num_of_speakers):
temp_sig = np.convolve(S[spk], H[spk], mode='full')
conv_signals[spk, :] = temp_sig[0: self.sec * self.sr]
Mixed = Mixed +conv_signals[spk, :]
angles_name = angles_name + str(int(self.speakers_angles[spk]))+'_'
angles_name = angles_name[:-1]
noise = self.fetch_noise()
snr = round(np.random.uniform(low=0, high=15), 2)
noise_gain = np.sqrt(10 ** (-snr/10) * np.std(Mixed) ** 2 / np.std(noise) ** 2)
noise = noise_gain * noise
Mixed = Mixed + noise
mix_file_name = os.path.join(current_write_path, 'mix')
if not os.path.exists(mix_file_name):
os.mkdir(mix_file_name)
filename = '_'.join(map(str, sig_idx))
name = os.path.join(mix_file_name, str(scene_i) + angles_name + '_RT60_' + str(
round(scenario_RT60, 2)) +
'_snr_' + str(snr) +
'_fileidx_' + filename + '.wav')
name = os.path.join(mix_file_name, str(scene_i) + angles_name + '_RT60_' + str(
round(scenario_RT60, 2)) + '_fileidx_' + filename + '.wav')
Mixed = Mixed / 1.2 / np.max(np.abs(Mixed))
print(name)
sf.write(name, Mixed, self.sr)
for spk in range(scenario_num_of_speakers):
target_file_name = os.path.join(current_write_path, 's' + str(spk+1))
if not os.path.exists(target_file_name):
os.mkdir(target_file_name)
name = os.path.join(target_file_name, str(scene_i) + angles_name + '_RT60_' + str(
round(scenario_RT60, 2)) +
'_snr_' + str(snr) +
'_fileidx_' + filename + '.wav')
name = os.path.join(target_file_name, str(scene_i) + angles_name + '_RT60_' + str(
round(scenario_RT60, 2)) + '_fileidx_' + filename + '.wav')
s = np.convolve(S[spk], H_anechoic[spk], mode='full')
s = s[0: self.sec * self.sr]
s = s / 1.2 / np.max(np.abs(s))
print(name)
sf.write(name, s, self.sr)