CleanSong commited on
Commit
a0afde1
·
verified ·
1 Parent(s): 75b3985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
8
  import torchaudio
9
  import torch
10
 
 
11
 
12
  # ================================
13
  # CONFIG
@@ -16,6 +17,12 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
16
  MODEL = "htdemucs" # best quality vocal separation
17
 
18
 
 
 
 
 
 
 
19
  # ================================
20
  # SPLIT FUNCTION
21
  # ================================
@@ -61,8 +68,8 @@ def split_vocals(audio_file):
61
  vocals_dst = str(Path(work_dir) / "vocals.wav")
62
  background_dst = str(Path(work_dir) / "background.wav")
63
 
64
- shutil.copy2(vocals_src, vocals_dst)
65
- shutil.copy2(background_src, background_dst)
66
 
67
  print(f"[Demucs] ✅ Done. Vocals: {vocals_dst}")
68
  return vocals_dst, background_dst, "✅ Split complete!"
 
8
  import torchaudio
9
  import torch
10
 
11
+ import soundfile as sf
12
 
13
  # ================================
14
  # CONFIG
 
17
  MODEL = "htdemucs" # best quality vocal separation
18
 
19
 
20
+ def resave(src, dst):
21
+ wav, sr = torchaudio.load(str(src))
22
+ data = wav.numpy().T
23
+ sf.write(dst, data, sr)
24
+
25
+
26
  # ================================
27
  # SPLIT FUNCTION
28
  # ================================
 
68
  vocals_dst = str(Path(work_dir) / "vocals.wav")
69
  background_dst = str(Path(work_dir) / "background.wav")
70
 
71
+ resave(vocals_src, vocals_dst)
72
+ resave(background_src, background_dst)
73
 
74
  print(f"[Demucs] ✅ Done. Vocals: {vocals_dst}")
75
  return vocals_dst, background_dst, "✅ Split complete!"