Spaces:
Sleeping
Sleeping
shubham13spd commited on
Commit ·
da545bb
1
Parent(s): 56c3e3d
add app
Browse files- app.py +45 -0
- package.txt +1 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pydub import AudioSegment
|
| 3 |
+
|
| 4 |
+
def change_audio_speed(audio_file, speed):
|
| 5 |
+
if not audio_file:
|
| 6 |
+
return "Please upload an audio file."
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
# Load the audio file
|
| 10 |
+
print("inside try of audio call")
|
| 11 |
+
audio = AudioSegment.from_file(audio_file, format="wav")
|
| 12 |
+
|
| 13 |
+
# Modify speed
|
| 14 |
+
new_audio = audio._spawn(audio.raw_data, overrides={
|
| 15 |
+
"frame_rate": int(audio.frame_rate * speed)
|
| 16 |
+
}).set_frame_rate(audio.frame_rate)
|
| 17 |
+
|
| 18 |
+
# Save the processed file
|
| 19 |
+
output_path = "output.mp3"
|
| 20 |
+
new_audio.export(output_path, format="mp3")
|
| 21 |
+
|
| 22 |
+
return output_path
|
| 23 |
+
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print("inside except of audio call", str(e))
|
| 26 |
+
return str(e)
|
| 27 |
+
|
| 28 |
+
# Gradio UI
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# 🎵 Audio Speed Modifier with ElevenLabs API Key Input")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
audio_input = gr.File(label="Upload MP3 Audio")
|
| 34 |
+
api_key = gr.Textbox(label="Enter ElevenLabs API Key", type="password")
|
| 35 |
+
|
| 36 |
+
speed_slider = gr.Slider(0.5, 3.0, 1.2, step=0.1, label="Speed Factor (1.2x = 20% faster)")
|
| 37 |
+
|
| 38 |
+
output_audio = gr.Audio(label="Processed Audio", type="filepath")
|
| 39 |
+
|
| 40 |
+
process_button = gr.Button("Process Audio")
|
| 41 |
+
|
| 42 |
+
process_button.click(change_audio_speed, inputs=[audio_input, speed_slider], outputs=output_audio)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
demo.launch(debug=True)
|
package.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pydub
|
| 2 |
+
gradio
|
| 3 |
+
elevenlabs
|