Spaces:
Running
Running
Create vocal_separation.py
Browse files- vocal_separation.py +46 -0
vocal_separation.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from spleeter.separator import Separator
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Initialize Spleeter with the 5stems model (for vocals, harmony, adlibs, etc.)
|
6 |
+
separator = Separator('spleeter:5stems')
|
7 |
+
|
8 |
+
# Function to separate the audio into vocals, harmony, ad-libs, and accompaniment
|
9 |
+
def separate_vocals(input_audio):
|
10 |
+
output_dir = "output"
|
11 |
+
if not os.path.exists(output_dir):
|
12 |
+
os.makedirs(output_dir)
|
13 |
+
|
14 |
+
# Path for the uploaded audio file
|
15 |
+
audio_path = input_audio.name
|
16 |
+
separated_path = os.path.join(output_dir, 'separated')
|
17 |
+
|
18 |
+
# Separate the audio file
|
19 |
+
separator.separate(audio_path)
|
20 |
+
|
21 |
+
# Paths for the separated tracks
|
22 |
+
main_vocal_file = os.path.join(separated_path, 'vocals.wav')
|
23 |
+
harmony_vocal_file = os.path.join(separated_path, 'harmonics.wav')
|
24 |
+
adlib_vocal_file = os.path.join(separated_path, 'adlibs.wav')
|
25 |
+
accompaniment_file = os.path.join(separated_path, 'accompaniment.wav')
|
26 |
+
|
27 |
+
# Return the separated files
|
28 |
+
return main_vocal_file, harmony_vocal_file, adlib_vocal_file, accompaniment_file
|
29 |
+
|
30 |
+
# Gradio interface setup
|
31 |
+
def create_interface():
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
with gr.Row():
|
34 |
+
audio_input = gr.Audio(label="Upload Audio File", type="file")
|
35 |
+
main_vocal_output = gr.Audio(label="Main Vocals", type="file", interactive=False)
|
36 |
+
harmony_vocal_output = gr.Audio(label="Harmony Vocals", type="file", interactive=False)
|
37 |
+
adlib_vocal_output = gr.Audio(label="Ad-lib Vocals", type="file", interactive=False)
|
38 |
+
accompaniment_output = gr.Audio(label="Accompaniment", type="file", interactive=False)
|
39 |
+
|
40 |
+
# When the audio file is uploaded, separate the audio and return the files
|
41 |
+
audio_input.change(separate_vocals, inputs=audio_input, outputs=[main_vocal_output, harmony_vocal_output, adlib_vocal_output, accompaniment_output])
|
42 |
+
|
43 |
+
demo.launch()
|
44 |
+
|
45 |
+
# Run the Gradio interface
|
46 |
+
create_interface()
|