Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,41 @@
|
|
1 |
-
from pydub import AudioSegment
|
2 |
-
from pydub.playback import play
|
3 |
import gradio as gr
|
4 |
-
|
5 |
-
import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
audio = AudioSegment.from_file(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
convert_audio.click(fn=apply_8d_effect, inputs=[audio_main], outputs=[audio_output])
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from pydub import AudioSegment
|
3 |
+
from pydub.effects import pan
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
+
|
7 |
+
def convert_to_8d(audio_file):
|
8 |
+
# Load the audio file
|
9 |
+
audio = AudioSegment.from_file(audio_file.name)
|
10 |
+
duration = len(audio)
|
11 |
+
|
12 |
+
# Create an 8D effect by panning audio back and forth
|
13 |
+
segments = []
|
14 |
+
for t in range(0, duration, 100): # Every 100ms, alternate panning
|
15 |
+
segment = audio[t:t+100]
|
16 |
+
pan_position = -1 + 2 * ((t // 100) % 2) # Alternates between -1 (left) and 1 (right)
|
17 |
+
segments.append(pan(segment, pan_position))
|
18 |
+
|
19 |
+
# Combine all segments
|
20 |
+
eight_d_audio = sum(segments)
|
21 |
+
|
22 |
+
# Save to a temporary file
|
23 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
24 |
+
eight_d_audio.export(temp_file.name, format="mp3")
|
25 |
+
return temp_file.name
|
26 |
+
|
27 |
+
# Gradio Interface
|
28 |
+
with gr.Blocks() as interface:
|
29 |
+
gr.Markdown("# 🎧 8D Audio Converter")
|
30 |
+
gr.Markdown("Upload your audio file, and this tool will transform it into 8D audio!")
|
31 |
+
|
32 |
+
with gr.Row():
|
33 |
+
audio_input = gr.Audio(label="Upload Audio", type="file")
|
34 |
+
audio_output = gr.Audio(label="8D Audio", type="filepath")
|
35 |
+
|
36 |
+
convert_button = gr.Button("Convert to 8D")
|
37 |
|
38 |
+
convert_button.click(fn=convert_to_8d, inputs=audio_input, outputs=audio_output)
|
|
|
39 |
|
40 |
+
print("launching app")
|
41 |
+
interface.launch(share=True)
|