helloWorld199 commited on
Commit
c70fa17
1 Parent(s): f97a03d

Update src/main.py

Browse files
Files changed (1) hide show
  1. src/main.py +26 -1
src/main.py CHANGED
@@ -18,6 +18,8 @@ from pedalboard import Pedalboard, Reverb, Compressor, HighpassFilter
18
  from pedalboard.io import AudioFile
19
  from pydub import AudioSegment
20
 
 
 
21
  from mdx import run_mdx
22
  from rvc import Config, load_hubert, get_vc, rvc_infer
23
 
@@ -135,6 +137,27 @@ def convert_to_stereo(audio_path):
135
  else:
136
  return audio_path
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  def pitch_shift(audio_path, pitch_change):
140
  output_path = f'{os.path.splitext(audio_path)[0]}_p{pitch_change}.wav'
@@ -290,13 +313,15 @@ def song_cover_pipeline(main_vocals, backup_vocals, voice_model, pitch_change, k
290
  if backup_vocals == "":
291
  print("####### ENTRATO QUA, BACKUP VOCALS NON DATI IN INPUT ########")
292
  ai_vocals_mixed_path = convert_to_stereo(ai_vocals_mixed_path)
 
293
  return ai_vocals_mixed_path
294
 
295
  display_progress('[~] Combining AI Vocals and Instrumentals...', 0.9, is_webui, progress)
296
  combine_audio([ai_vocals_mixed_path, backup_vocals], ai_cover_path, main_gain, backup_gain, inst_gain, output_format)
297
 
298
  ai_cover_path = convert_to_stereo(ai_cover_path)
299
-
 
300
  return ai_cover_path
301
 
302
  except Exception as e:
 
18
  from pedalboard.io import AudioFile
19
  from pydub import AudioSegment
20
 
21
+ import pyloudnorm as pyln
22
+
23
  from mdx import run_mdx
24
  from rvc import Config, load_hubert, get_vc, rvc_infer
25
 
 
137
  else:
138
  return audio_path
139
 
140
+ def normalize_audio(input_audio_path, output_audio_path):
141
+ y1, sr1 = librosa.load(inpud_audio_path, mono = False)
142
+ meter = pyln.Meter(sr1)
143
+ lufs_left1 = meter.integrated_loudness(y1[0])
144
+ lufs_right1 = meter.integrated_loudness(y1[1])
145
+
146
+ y2, sr2 = librosa.load(output_audio_path, mono = False)
147
+ meter2 = pyln.Meter(sr2)
148
+ lufs_left2 = meter2.integrated_loudness(y2[0])
149
+ lufs_right2 = meter2.integrated_loudness(y2[1])
150
+
151
+ y2_normalized_left = pyln.normalize.loudness(y2[0], lufs_left2, lufs_left1)
152
+ y2_normalized_right = pyln.normalize.loudness(y2[0], lufs_right2, lufs_right1)
153
+
154
+ y2_normalized = np.stack((y2_normalized_left, y2_normalized_right), axis=0)
155
+
156
+ output_path = f"{output_audio_path}_normalized.wav"
157
+
158
+ sf.write(output_path, y2_normalized.T, sr2)
159
+
160
+ return output_path
161
 
162
  def pitch_shift(audio_path, pitch_change):
163
  output_path = f'{os.path.splitext(audio_path)[0]}_p{pitch_change}.wav'
 
313
  if backup_vocals == "":
314
  print("####### ENTRATO QUA, BACKUP VOCALS NON DATI IN INPUT ########")
315
  ai_vocals_mixed_path = convert_to_stereo(ai_vocals_mixed_path)
316
+ ai_vocals_mixed_path = normalize(main_vocals, ai_vocals_mixed_path)
317
  return ai_vocals_mixed_path
318
 
319
  display_progress('[~] Combining AI Vocals and Instrumentals...', 0.9, is_webui, progress)
320
  combine_audio([ai_vocals_mixed_path, backup_vocals], ai_cover_path, main_gain, backup_gain, inst_gain, output_format)
321
 
322
  ai_cover_path = convert_to_stereo(ai_cover_path)
323
+ ai_cover_path = normalize(main_vocals, ai_cover_path)
324
+
325
  return ai_cover_path
326
 
327
  except Exception as e: