key_s2, feat_s2 = compute_spectrum(s2_wav[i]) assert key_mix == key_s1 and key_s1 == key_s2 mask_s1 = ibm(feat_s1, feat_s2, use_log, use_power) mask_s2 = 1 - mask_s1 key_wav, wav = readwav(mix_wav[i]) enhance_s1 = apply_mask(feat_mix, mask_s1, use_log, use_power) enhance_s2 = apply_mask(feat_mix, mask_s2, use_log, use_power) # Reconstruction wav_s1 = overlap_and_add(enhance_s1, wav, sample_rate, frame_length, frame_shift, window_type, preemphasis, use_log, use_power, square_root_window) wav_s2 = overlap_and_add(enhance_s2, wav, sample_rate, frame_length, frame_shift, window_type, preemphasis, use_log, use_power, square_root_window) wavwrite(wav_s1, sample_rate, recons_dir + "/" + key_wav + "_1.wav") wavwrite(wav_s2, sample_rate, recons_dir + "/" + key_wav + "_2.wav") f_mix_wav.close() f_s1_wav.close() f_s2_wav.close() # SI-SDR eval_si_sdr(ori_dir, os.path.dirname(recons_dir)) # SDR.sources eval_sdr_sources(ori_dir, os.path.dirname(recons_dir)) # SDR.v4 eval_sdr(ori_dir, os.path.dirname(recons_dir))
key, path = line.strip().split() wav, frame_rate = wavread(path) return key, wav for i in range(len(mix_wav)): key_mix, wav_mix = readwav(mix_wav[i]) key_s1, wav_s1 = readwav(s1_wav[i]) key_s2, wav_s2 = readwav(s2_wav[i]) assert key_mix == key_s1 and key_s1 == key_s2 mask_s1 = ibm(wav_s1, wav_s2) mask_s2 = 1.0 - mask_s1 enhance_s1 = apply_mask(wav_mix, mask_s1) enhance_s2 = apply_mask(wav_mix, mask_s2) wavwrite(enhance_s1, SAMPLE_RATE, recons_dir + "/" + key_mix + "_1.wav") wavwrite(enhance_s2, SAMPLE_RATE, recons_dir + "/" + key_mix + "_2.wav") f_mix_wav.close() f_s1_wav.close() f_s2_wav.close() # SI-SDR eval_si_sdr(ori_dir, os.path.dirname(recons_dir)) # SDR.sources eval_sdr_sources(ori_dir, os.path.dirname(recons_dir)) # SDR.v4 eval_sdr(ori_dir, os.path.dirname(recons_dir))