Ajuste de filtro pasa-altos a 40 Hz y eliminación de reducción de ruido en stems para más claridad
Browse files- audio_pipeline.py +10 -16
audio_pipeline.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
# audio_pipeline.py
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
import sys
|
|
@@ -66,26 +64,22 @@ def separar_audio_demucs_6stems(input_file: str, model: str = "htdemucs_6s") ->
|
|
| 66 |
def limpiar_stems(stems_dir: str) -> None:
|
| 67 |
"""
|
| 68 |
Para cada stem:
|
| 69 |
-
1)
|
| 70 |
-
2)
|
| 71 |
-
3)
|
| 72 |
-
4) Guarda como *_cleaned.wav
|
| 73 |
"""
|
| 74 |
for archivo in os.listdir(stems_dir):
|
| 75 |
if archivo.endswith(".wav"):
|
| 76 |
ruta_in = os.path.join(stems_dir, archivo)
|
| 77 |
y, sr = librosa.load(ruta_in, sr=None)
|
| 78 |
|
| 79 |
-
# 1)
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
# 2) paso alto
|
| 83 |
-
y_hp = highpass_filter(y_denoised, sr, cutoff=100.0)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
y_norm = normalize(y_hp)
|
| 87 |
|
| 88 |
-
#
|
| 89 |
ruta_out = ruta_in.replace(".wav", "_cleaned.wav")
|
| 90 |
sf.write(ruta_out, y_norm, sr)
|
| 91 |
|
|
@@ -122,8 +116,8 @@ def combinar_stems_sin_vocales(stems_dir: str) -> None:
|
|
| 122 |
def reducir_ruido(input_file: str, output_file: str, noise_duration: float = 0.5) -> None:
|
| 123 |
"""
|
| 124 |
Procesa un WAV completo:
|
| 125 |
-
1) Reduce ruido usando los primeros `noise_duration`
|
| 126 |
-
2)
|
| 127 |
3) Normaliza
|
| 128 |
4) Guarda en output_file
|
| 129 |
"""
|
|
@@ -131,7 +125,7 @@ def reducir_ruido(input_file: str, output_file: str, noise_duration: float = 0.5
|
|
| 131 |
noise = y[:int(sr * noise_duration)]
|
| 132 |
y_denoised = nr.reduce_noise(y=y, sr=sr, y_noise=noise)
|
| 133 |
|
| 134 |
-
y_hp = highpass_filter(y_denoised, sr, cutoff=
|
| 135 |
y_norm = normalize(y_hp)
|
| 136 |
|
| 137 |
sf.write(output_file, y_norm, sr)
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
import sys
|
|
|
|
| 64 |
def limpiar_stems(stems_dir: str) -> None:
|
| 65 |
"""
|
| 66 |
Para cada stem:
|
| 67 |
+
1) Aplica filtro pasa-altos
|
| 68 |
+
2) Normaliza
|
| 69 |
+
3) Guarda como *_cleaned.wav
|
|
|
|
| 70 |
"""
|
| 71 |
for archivo in os.listdir(stems_dir):
|
| 72 |
if archivo.endswith(".wav"):
|
| 73 |
ruta_in = os.path.join(stems_dir, archivo)
|
| 74 |
y, sr = librosa.load(ruta_in, sr=None)
|
| 75 |
|
| 76 |
+
# 1) filtro pasa-altos
|
| 77 |
+
y_hp = highpass_filter(y, sr, cutoff=40.0)
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
# 2) normalización
|
| 80 |
y_norm = normalize(y_hp)
|
| 81 |
|
| 82 |
+
# 3) guardar
|
| 83 |
ruta_out = ruta_in.replace(".wav", "_cleaned.wav")
|
| 84 |
sf.write(ruta_out, y_norm, sr)
|
| 85 |
|
|
|
|
| 116 |
def reducir_ruido(input_file: str, output_file: str, noise_duration: float = 0.5) -> None:
|
| 117 |
"""
|
| 118 |
Procesa un WAV completo:
|
| 119 |
+
1) Reduce ruido usando los primeros `noise_duration` seg
|
| 120 |
+
2) Filtra pasa-altos
|
| 121 |
3) Normaliza
|
| 122 |
4) Guarda en output_file
|
| 123 |
"""
|
|
|
|
| 125 |
noise = y[:int(sr * noise_duration)]
|
| 126 |
y_denoised = nr.reduce_noise(y=y, sr=sr, y_noise=noise)
|
| 127 |
|
| 128 |
+
y_hp = highpass_filter(y_denoised, sr, cutoff=40.0)
|
| 129 |
y_norm = normalize(y_hp)
|
| 130 |
|
| 131 |
sf.write(output_file, y_norm, sr)
|