nifty-coder commited on
Commit
638586a
·
1 Parent(s): 4497dc9

Fix dependencies: add torchcodec and libsndfile1

Browse files
Files changed (2) hide show
  1. __pycache__/main.cpython-314.pyc +0 -0
  2. main.py +16 -8
__pycache__/main.cpython-314.pyc CHANGED
Binary files a/__pycache__/main.cpython-314.pyc and b/__pycache__/main.cpython-314.pyc differ
 
main.py CHANGED
@@ -216,10 +216,9 @@ def run_demucs_and_extract(input_path: str, tmpdir: str) -> str:
216
  os.makedirs(output_dir, exist_ok=True)
217
 
218
  cmd = DEMUCS_CMD +["-o", output_dir, input_path]
219
- logger.info(f"Running demucs: {' '.join(cmd)}")
220
  try:
221
- result = subprocess.run(cmd, check=True, capture_output=True, text=True)
222
- logger.info(f"Demucs stdout: {result.stdout}")
223
  except subprocess.CalledProcessError as e:
224
  logger.error(f"Demucs failed code={e.returncode}")
225
  logger.error(f"Demucs stderr: {e.stderr}")
@@ -236,11 +235,12 @@ def run_demucs_and_extract(input_path: str, tmpdir: str) -> str:
236
  if f.endswith('.wav'):
237
  src = os.path.join(root, f)
238
  dst = os.path.join(mp3_dir, f.replace('.wav', '.mp3'))
239
- logger.info(f"Converting: {src} -> {dst}")
240
- subprocess.run([FFMPEG_PATH, "-y", "-i", src, "-codec:a", "libmp3lame", "-qscale:a", "2", dst], check=True)
 
241
  wav_count += 1
242
 
243
- logger.info(f"Demucs processing finished. Found and converted {wav_count} stems.")
244
  if wav_count == 0:
245
  raise Exception("Demucs produced no output files. Check if the model is installed and the input is valid.")
246
 
@@ -251,9 +251,17 @@ def run_demucs_and_extract(input_path: str, tmpdir: str) -> str:
251
  n = len(stems)
252
  labels = "".join(f"[{i}:a]" for i in range(n))
253
  subprocess.run([FFMPEG_PATH, "-y"] + [i for s in stems for i in ("-i", s)] +
254
- ["-filter_complex", f"{labels}amix=inputs={n}:normalize=0", "-c:a", "libmp3lame", "-qscale:a", "2", inst_path], check=True)
 
 
 
 
 
 
 
 
 
255
 
256
- logger.info(f"MP3 Directory contents: {os.listdir(mp3_dir)}")
257
  return mp3_dir
258
 
259
 
 
216
  os.makedirs(output_dir, exist_ok=True)
217
 
218
  cmd = DEMUCS_CMD +["-o", output_dir, input_path]
219
+ # Run demucs (suppress verbose output)
220
  try:
221
+ subprocess.run(cmd, check=True, capture_output=True, text=True)
 
222
  except subprocess.CalledProcessError as e:
223
  logger.error(f"Demucs failed code={e.returncode}")
224
  logger.error(f"Demucs stderr: {e.stderr}")
 
235
  if f.endswith('.wav'):
236
  src = os.path.join(root, f)
237
  dst = os.path.join(mp3_dir, f.replace('.wav', '.mp3'))
238
+ # Convert WAV to MP3 (suppress ffmpeg output)
239
+ subprocess.run([FFMPEG_PATH, "-y", "-i", src, "-codec:a", "libmp3lame", "-qscale:a", "2", dst],
240
+ check=True, capture_output=True, text=True)
241
  wav_count += 1
242
 
243
+ logger.info(f"Processed {wav_count} stems")
244
  if wav_count == 0:
245
  raise Exception("Demucs produced no output files. Check if the model is installed and the input is valid.")
246
 
 
251
  n = len(stems)
252
  labels = "".join(f"[{i}:a]" for i in range(n))
253
  subprocess.run([FFMPEG_PATH, "-y"] + [i for s in stems for i in ("-i", s)] +
254
+ ["-filter_complex", f"{labels}amix=inputs={n}:normalize=0", "-c:a", "libmp3lame", "-qscale:a", "2", inst_path],
255
+ check=True, capture_output=True, text=True)
256
+
257
+ # Add original audio to the output
258
+ original_mp3 = os.path.join(mp3_dir, 'original.mp3')
259
+ subprocess.run([
260
+ FFMPEG_PATH, "-y", "-i", input_path,
261
+ "-codec:a", "libmp3lame", "-qscale:a", "2",
262
+ original_mp3
263
+ ], check=True, capture_output=True, text=True)
264
 
 
265
  return mp3_dir
266
 
267