vinni1484 commited on
Commit
6d0551b
1 Parent(s): e82beec

Add application file

Browse files
Files changed (3) hide show
  1. app.py +40 -0
  2. packages.txt +1 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from audio_separator import Separator
2
+ import subprocess
3
+ import os
4
+ import uuid
5
+ import streamlit as st
6
+ from pydub import AudioSegment
7
+
8
+ st.title("Karaoke")
9
+ url = st.text_area("Enter spotify song URL")
10
+ button = st.button("Process")
11
+
12
+ if button:
13
+ with st.spinner("Processing"):
14
+ uuid_str = str(uuid.uuid4())
15
+ cmd = f"spotdl {url} --output audio{uuid_str}"
16
+ subprocess.run(cmd, shell=True)
17
+ files = os.listdir(f"audio{uuid_str}")
18
+ audio_files = [
19
+ file for file in files if file.endswith((".mp3", ".wav", ".ogg"))
20
+ ]
21
+ old_path = os.path.join(f"audio{uuid_str}", audio_files[0])
22
+ new_path = os.path.join(f"audio{uuid_str}", "audio.mp3")
23
+ os.rename(old_path, new_path)
24
+
25
+ separator = Separator(
26
+ f"audio{uuid_str}/audio.mp3",
27
+ model_name="UVR-MDX-NET-Inst_HQ_3",
28
+ primary_stem_path=f"music{uuid_str}.wav",
29
+ output_single_stem="instrumental",
30
+ )
31
+ primary_stem_path = separator.separate()
32
+
33
+ sound = AudioSegment.from_wav(f"music{uuid_str}.wav")
34
+ sound.export("output.mp3", format="mp3", bitrate="192k")
35
+
36
+ os.remove(f"music{uuid_str}.wav")
37
+ os.remove(f"audio{uuid_str}/audio.mp3")
38
+ os.rmdir(f"audio{uuid_str}")
39
+
40
+ st.audio("output.mp3", format="audio/mp3")
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ audio-separator
2
+ pydub
3
+ spotdl