Spaces:
Running
Running
Update src/audio_effects.py
Browse files- src/audio_effects.py +16 -6
src/audio_effects.py
CHANGED
|
@@ -28,6 +28,14 @@ def combine_audio(vocal_path, instrumental_path, output_path, vocal_gain, instru
|
|
| 28 |
combined = vocal.overlay(instrumental)
|
| 29 |
combined.export(output_path, format=output_format)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def add_audio_effects(vocal_audio_path, instrumental_audio_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping, reverb_width,
|
| 32 |
low_shelf_gain, high_shelf_gain, compressor_ratio, compressor_threshold, noise_gate_threshold, noise_gate_ratio,
|
| 33 |
noise_gate_attack, noise_gate_release, chorus_rate_hz, chorus_depth, chorus_centre_delay_ms, chorus_feedback,
|
|
@@ -36,6 +44,10 @@ def add_audio_effects(vocal_audio_path, instrumental_audio_path, reverb_rm_size,
|
|
| 36 |
if not vocal_audio_path or not instrumental_audio_path:
|
| 37 |
raise ValueError("Оба пути к аудиофайлам должны быть заполнены.")
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
display_progress(0.2, "Применение аудиоэффектов к вокалу...", progress)
|
| 40 |
board = Pedalboard(
|
| 41 |
[
|
|
@@ -49,19 +61,17 @@ def add_audio_effects(vocal_audio_path, instrumental_audio_path, reverb_rm_size,
|
|
| 49 |
]
|
| 50 |
)
|
| 51 |
|
| 52 |
-
vocal_output_path =
|
| 53 |
-
with AudioFile(
|
| 54 |
with AudioFile(vocal_output_path, 'w', f.samplerate, 2) as o:
|
| 55 |
while f.tell() < f.frames:
|
| 56 |
chunk = f.read(int(f.samplerate))
|
| 57 |
-
chunk = np.tile(chunk, (2, 1)).T
|
| 58 |
effected = board(chunk, f.samplerate, reset=False)
|
| 59 |
o.write(effected)
|
| 60 |
|
| 61 |
display_progress(0.5, "Объединение вокала и инструментальной части...", progress)
|
| 62 |
output_dir = os.path.join(BASE_DIR, 'processed_output')
|
| 63 |
-
|
| 64 |
-
os.makedirs(output_dir)
|
| 65 |
combined_output_path = os.path.join(output_dir, f'AiCover_combined.{output_format}')
|
| 66 |
|
| 67 |
if os.path.exists(combined_output_path):
|
|
@@ -71,4 +81,4 @@ def add_audio_effects(vocal_audio_path, instrumental_audio_path, reverb_rm_size,
|
|
| 71 |
|
| 72 |
display_progress(1.0, "Готово!", progress)
|
| 73 |
|
| 74 |
-
return combined_output_path
|
|
|
|
| 28 |
combined = vocal.overlay(instrumental)
|
| 29 |
combined.export(output_path, format=output_format)
|
| 30 |
|
| 31 |
+
def convert_to_stereo(input_path, output_path):
|
| 32 |
+
y, sr = librosa.load(input_path, sr=None, mono=False)
|
| 33 |
+
if y.ndim == 1:
|
| 34 |
+
y = np.vstack([y, y])
|
| 35 |
+
elif y.ndim > 2:
|
| 36 |
+
y = y[:2, :]
|
| 37 |
+
sf.write(output_path, y.T, sr, format='WAV')
|
| 38 |
+
|
| 39 |
def add_audio_effects(vocal_audio_path, instrumental_audio_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping, reverb_width,
|
| 40 |
low_shelf_gain, high_shelf_gain, compressor_ratio, compressor_threshold, noise_gate_threshold, noise_gate_ratio,
|
| 41 |
noise_gate_attack, noise_gate_release, chorus_rate_hz, chorus_depth, chorus_centre_delay_ms, chorus_feedback,
|
|
|
|
| 44 |
if not vocal_audio_path or not instrumental_audio_path:
|
| 45 |
raise ValueError("Оба пути к аудиофайлам должны быть заполнены.")
|
| 46 |
|
| 47 |
+
# Convert vocal file to stereo if necessary
|
| 48 |
+
stereo_vocal_path = 'Vocal_Stereo.wav'
|
| 49 |
+
convert_to_stereo(vocal_audio_path, stereo_vocal_path)
|
| 50 |
+
|
| 51 |
display_progress(0.2, "Применение аудиоэффектов к вокалу...", progress)
|
| 52 |
board = Pedalboard(
|
| 53 |
[
|
|
|
|
| 61 |
]
|
| 62 |
)
|
| 63 |
|
| 64 |
+
vocal_output_path = os.path.join(BASE_DIR, 'Vocal_Effects.wav')
|
| 65 |
+
with AudioFile(stereo_vocal_path) as f:
|
| 66 |
with AudioFile(vocal_output_path, 'w', f.samplerate, 2) as o:
|
| 67 |
while f.tell() < f.frames:
|
| 68 |
chunk = f.read(int(f.samplerate))
|
|
|
|
| 69 |
effected = board(chunk, f.samplerate, reset=False)
|
| 70 |
o.write(effected)
|
| 71 |
|
| 72 |
display_progress(0.5, "Объединение вокала и инструментальной части...", progress)
|
| 73 |
output_dir = os.path.join(BASE_DIR, 'processed_output')
|
| 74 |
+
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
| 75 |
combined_output_path = os.path.join(output_dir, f'AiCover_combined.{output_format}')
|
| 76 |
|
| 77 |
if os.path.exists(combined_output_path):
|
|
|
|
| 81 |
|
| 82 |
display_progress(1.0, "Готово!", progress)
|
| 83 |
|
| 84 |
+
return combined_output_path
|