theNeofr commited on
Commit
f584883
·
verified ·
1 Parent(s): 8667802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -32
app.py CHANGED
@@ -1,35 +1,41 @@
1
- from pydub import AudioSegment
2
- from pydub.playback import play
3
  import gradio as gr
4
- import os as neo
5
- import sys
6
-
7
- now_dir = neo.getcwd()
8
- sys.path.append(now_dir)
9
-
10
- def apply_8d_effect(audio_path):
11
- audio = AudioSegment.from_file(audio_path)
12
- num_directions = 8
13
- panned_tracks = []
14
-
15
- for i in range(num_directions):
16
- pan_position = i / num_directions
17
- panned_audio = audio.pan(pan_position)
18
- panned_tracks.append(panned_audio)
19
-
20
- output_audio = f"{audio_path}_8d.wav"
21
- combined_audio = sum(panned_tracks)
22
- combined_audio.export(output_audio, format="wav")
23
-
24
- return output_audio
25
-
26
-
27
-
28
- with gr.Blocks() as app:
29
- audio_main = gr.Audio(label="your audio input", type="filepath")
30
- audio_output = gr.Audio(label="your audio output")
 
 
 
 
 
 
 
 
31
 
32
- convert_audio = gr.Button("Convert")
33
- convert_audio.click(fn=apply_8d_effect, inputs=[audio_main], outputs=[audio_output])
34
 
35
- app.launch(share=True)
 
 
 
 
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)