Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import yt_dlp
|
4 |
from pydub import AudioSegment
|
5 |
import re
|
|
|
6 |
|
7 |
# Create downloads directory safely
|
8 |
if not os.path.exists("downloads"):
|
@@ -41,14 +42,18 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
41 |
audio = AudioSegment.from_file(filename)
|
42 |
audio.export(mp3_filename, format="mp3")
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
ringtone_audio = ringtone_audio[:20000] # 20 seconds
|
49 |
-
ringtone_audio.export(ringtone_filename_m4r, format="aac") # Export as AAC for M4R
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
except Exception as e:
|
54 |
print(f"Error: {e}")
|
@@ -92,3 +97,4 @@ with gr.Blocks(css="""
|
|
92 |
interface.launch(share=True)
|
93 |
|
94 |
|
|
|
|
3 |
import yt_dlp
|
4 |
from pydub import AudioSegment
|
5 |
import re
|
6 |
+
import subprocess
|
7 |
|
8 |
# Create downloads directory safely
|
9 |
if not os.path.exists("downloads"):
|
|
|
42 |
audio = AudioSegment.from_file(filename)
|
43 |
audio.export(mp3_filename, format="mp3")
|
44 |
|
45 |
+
# Use ffmpeg to convert mp3 to m4a
|
46 |
+
m4a_filename = f"downloads/{song_name}.m4a"
|
47 |
+
if not os.path.exists(m4a_filename):
|
48 |
+
subprocess.run(['ffmpeg', '-i', mp3_filename, '-vn', '-acodec', 'aac', '-b:a', '192k', m4a_filename])
|
|
|
|
|
49 |
|
50 |
+
# Trim the first 20 seconds
|
51 |
+
m4r_filename = f"downloads/{song_name}.m4r"
|
52 |
+
if not os.path.exists(m4r_filename):
|
53 |
+
# Rename the .m4a to .m4r
|
54 |
+
os.rename(m4a_filename, m4r_filename)
|
55 |
+
|
56 |
+
return mp3_filename, m4r_filename
|
57 |
|
58 |
except Exception as e:
|
59 |
print(f"Error: {e}")
|
|
|
97 |
interface.launch(share=True)
|
98 |
|
99 |
|
100 |
+
|