gelpi01 commited on
Commit
6da82fc
verified
1 Parent(s): 74aeff9

Update audio_pipeline.py

Browse files
Files changed (1) hide show
  1. audio_pipeline.py +12 -5
audio_pipeline.py CHANGED
@@ -1,8 +1,10 @@
 
1
  import os
2
  import subprocess
3
  import sys
4
  import warnings
5
  import torch
 
6
 
7
  import librosa
8
  import numpy as np
@@ -41,6 +43,9 @@ def separar_audio_demucs_6stems(input_file: str, model: str = "htdemucs_6s") ->
41
  Devuelve la ruta al directorio donde est谩n los .wav resultantes.
42
  """
43
  out_root = os.path.join(BASE_STEMS_DIR, model)
 
 
 
44
  os.makedirs(out_root, exist_ok=True)
45
 
46
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -63,13 +68,14 @@ def separar_audio_demucs_6stems(input_file: str, model: str = "htdemucs_6s") ->
63
 
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
 
@@ -79,8 +85,9 @@ def limpiar_stems(stems_dir: str) -> None:
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
 
86
 
@@ -129,4 +136,4 @@ def reducir_ruido(input_file: str, output_file: str, noise_duration: float = 0.5
129
  # 4) Normalizaci贸n para mantener toda la gama din谩mica
130
  y_norm = normalize(y_denoised)
131
  # 5) Escritura en disco
132
- sf.write(output_file, y_norm, sr)
 
1
+ # audio_pipeline.py
2
  import os
3
  import subprocess
4
  import sys
5
  import warnings
6
  import torch
7
+ import shutil
8
 
9
  import librosa
10
  import numpy as np
 
43
  Devuelve la ruta al directorio donde est谩n los .wav resultantes.
44
  """
45
  out_root = os.path.join(BASE_STEMS_DIR, model)
46
+ # Limpia el directorio anterior para evitar stems obsoletos
47
+ if os.path.exists(out_root):
48
+ shutil.rmtree(out_root)
49
  os.makedirs(out_root, exist_ok=True)
50
 
51
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
68
 
69
  def limpiar_stems(stems_dir: str) -> None:
70
  """
71
+ Para cada stem original (*.wav excepto *_cleaned.wav):
72
  1) Aplica filtro pasa-altos
73
  2) Normaliza
74
  3) Guarda como *_cleaned.wav
75
  """
76
  for archivo in os.listdir(stems_dir):
77
+ # Solo archivos .wav que NO terminen en _cleaned.wav
78
+ if archivo.endswith(".wav") and not archivo.endswith("_cleaned.wav"):
79
  ruta_in = os.path.join(stems_dir, archivo)
80
  y, sr = librosa.load(ruta_in, sr=None)
81
 
 
85
  # 2) normalizaci贸n
86
  y_norm = normalize(y_hp)
87
 
88
+ # 3) guardar sin generar sufijos dobles
89
+ nombre, _ = os.path.splitext(archivo)
90
+ ruta_out = os.path.join(stems_dir, f"{nombre}_cleaned.wav")
91
  sf.write(ruta_out, y_norm, sr)
92
 
93
 
 
136
  # 4) Normalizaci贸n para mantener toda la gama din谩mica
137
  y_norm = normalize(y_denoised)
138
  # 5) Escritura en disco
139
+ sf.write(output_file, y_norm, sr)