jhtonyKoo commited on
Commit
ddb80f4
1 Parent(s): f9a28ee

Update inference/style_transfer.py

Browse files
Files changed (1) hide show
  1. inference/style_transfer.py +13 -0
inference/style_transfer.py CHANGED
@@ -22,6 +22,7 @@ sys.path.append(os.path.join(os.path.dirname(currentdir), "mixing_style_transfer
22
  from networks import FXencoder, TCNModel
23
  from data_loader import *
24
  import librosa
 
25
 
26
 
27
 
@@ -170,8 +171,20 @@ class Mixing_Style_Transfer_Inference:
170
  # save output of each instrument
171
  if self.args.save_each_inst:
172
  sf.write(os.path.join(cur_out_dir, f"{cur_inst_name}_{output_name_tag}.wav"), fin_data_out_inst.transpose(-1, -2), self.args.sample_rate, 'PCM_16')
 
173
  # remix
174
  fin_data_out_mix = sum(inst_outputs)
 
 
 
 
 
 
 
 
 
 
 
175
  fin_output_path = os.path.join(cur_out_dir, f"mixture_{output_name_tag}.wav")
176
  sf.write(fin_output_path, fin_data_out_mix.transpose(-1, -2), self.args.sample_rate, 'PCM_16')
177
 
 
22
  from networks import FXencoder, TCNModel
23
  from data_loader import *
24
  import librosa
25
+ import pyloudnorm
26
 
27
 
28
 
 
171
  # save output of each instrument
172
  if self.args.save_each_inst:
173
  sf.write(os.path.join(cur_out_dir, f"{cur_inst_name}_{output_name_tag}.wav"), fin_data_out_inst.transpose(-1, -2), self.args.sample_rate, 'PCM_16')
174
+
175
  # remix
176
  fin_data_out_mix = sum(inst_outputs)
177
+
178
+ # loudness adjusting for mastering purpose
179
+ meter = pyloudnorm.Meter(44100)
180
+ loudness_out = meter.integrated_loudness(fin_data_out_mix.transpose(-1, -2))
181
+ reference_aud = load_wav_segment(reference_track_path, axis=1)
182
+ loudness_ref = meter.integrated_loudness(reference_aud)
183
+ # adjust output loudness to that of the reference
184
+ fin_data_out_mix = pyloudnorm.normalize.loudness(fin_data_out_mix, loudness_out, loudness_ref)
185
+ fin_data_out_mix = np.clip(fin_data_out_mix, -1., 1.)
186
+
187
+ # save output
188
  fin_output_path = os.path.join(cur_out_dir, f"mixture_{output_name_tag}.wav")
189
  sf.write(fin_output_path, fin_data_out_mix.transpose(-1, -2), self.args.sample_rate, 'PCM_16')
190