Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,37 +22,25 @@ from spleeter.separator import Separator
|
|
| 22 |
from spleeter.audio.adapter import AudioAdapter
|
| 23 |
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
# Initialize Spleeter separator
|
| 32 |
separator = Separator("spleeter:2stems", multiprocess=False)
|
| 33 |
audio_loader = AudioAdapter.default()
|
| 34 |
|
| 35 |
def separate_audio(audio_file):
|
| 36 |
"""
|
| 37 |
-
Separate
|
| 38 |
-
Returns filepaths for the separated stems and a status message.
|
| 39 |
"""
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Separate stems using Spleeter
|
| 44 |
-
pred = separator.separate(waveform)
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
tmp_dir =
|
| 48 |
vocals_path = os.path.join(tmp_dir, "vocals.wav")
|
| 49 |
-
instr_path = os.path.join(tmp_dir, "
|
| 50 |
-
|
| 51 |
-
audio_loader.save(vocals_path, pred["vocals"], sample_rate)
|
| 52 |
-
audio_loader.save(instr_path, pred["accompaniment"], sample_rate)
|
| 53 |
|
| 54 |
return vocals_path, instr_path, "Done!"
|
| 55 |
|
|
|
|
| 56 |
# Gradio interface
|
| 57 |
iface = gr.Interface(
|
| 58 |
fn=separate_audio,
|
|
|
|
| 22 |
from spleeter.audio.adapter import AudioAdapter
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Initialize Spleeter separator
|
| 26 |
separator = Separator("spleeter:2stems", multiprocess=False)
|
| 27 |
audio_loader = AudioAdapter.default()
|
| 28 |
|
| 29 |
def separate_audio(audio_file):
|
| 30 |
"""
|
| 31 |
+
Separate vocals and instrumental from input audio file using Spleeter.
|
|
|
|
| 32 |
"""
|
| 33 |
+
# Separate stems directly from file path
|
| 34 |
+
pred = separator.separate_to_file(audio_file, tempfile.mkdtemp(), codec="wav")
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# Spleeter saves to temp dir automatically
|
| 37 |
+
tmp_dir = os.path.dirname(pred[0]) # get directory where files are saved
|
| 38 |
vocals_path = os.path.join(tmp_dir, "vocals.wav")
|
| 39 |
+
instr_path = os.path.join(tmp_dir, "accompaniment.wav")
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
return vocals_path, instr_path, "Done!"
|
| 42 |
|
| 43 |
+
|
| 44 |
# Gradio interface
|
| 45 |
iface = gr.Interface(
|
| 46 |
fn=separate_audio,
|