sudo-soldier commited on
Commit
c25ac20
·
verified ·
1 Parent(s): 419ec35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -41,12 +41,16 @@ def process_youtube_or_audio(url, recorded_audio, start_time, end_time):
41
  # Load audio file
42
  audio = AudioSegment.from_file(filename)
43
 
 
 
 
 
44
  # Ensure valid trimming times
45
- start_time = max(0, min(start_time, len(audio)))
46
- end_time = max(start_time, min(end_time, len(audio)))
47
 
48
  # Trim the audio
49
- trimmed_audio = audio[start_time:end_time]
50
 
51
  # Convert to MP3
52
  mp3_filename = f"downloads/{song_name}.mp3"
@@ -106,8 +110,8 @@ with gr.Blocks(css="""
106
  gr.HTML("<h3>Trim Audio (Optional)</h3>")
107
 
108
  with gr.Row():
109
- start_time = gr.Slider(0, 20000, value=0, label="Start Time (ms)")
110
- end_time = gr.Slider(1000, 20000, value=20000, label="End Time (ms)")
111
 
112
  with gr.Row():
113
  process_button = gr.Button("Create Ringtones", elem_classes="light-btn")
@@ -127,3 +131,4 @@ with gr.Blocks(css="""
127
 
128
  interface.launch(share=True)
129
 
 
 
41
  # Load audio file
42
  audio = AudioSegment.from_file(filename)
43
 
44
+ # Convert seconds to milliseconds for pydub
45
+ start_time_ms = start_time * 1000
46
+ end_time_ms = end_time * 1000
47
+
48
  # Ensure valid trimming times
49
+ start_time_ms = max(0, min(start_time_ms, len(audio)))
50
+ end_time_ms = max(start_time_ms, min(end_time_ms, len(audio)))
51
 
52
  # Trim the audio
53
+ trimmed_audio = audio[start_time_ms:end_time_ms]
54
 
55
  # Convert to MP3
56
  mp3_filename = f"downloads/{song_name}.mp3"
 
110
  gr.HTML("<h3>Trim Audio (Optional)</h3>")
111
 
112
  with gr.Row():
113
+ start_time = gr.Slider(0, 20, value=0, label="Start Time (seconds)")
114
+ end_time = gr.Slider(1, 20, value=20, label="End Time (seconds)")
115
 
116
  with gr.Row():
117
  process_button = gr.Button("Create Ringtones", elem_classes="light-btn")
 
131
 
132
  interface.launch(share=True)
133
 
134
+