import gradio as gr from pydub import AudioSegment from pydub.effects import pan import tempfile import os def convert_to_8d(audio_file): # Load the audio file audio = AudioSegment.from_file(audio_file) duration = len(audio) # Create an 8D effect by panning audio back and forth segments = [] for t in range(0, duration, 100): # Every 100ms, alternate panning segment = audio[t:t+100] pan_position = -1 + 2 * ((t // 100) % 2) # Alternates between -1 (left) and 1 (right) segments.append(pan(segment, pan_position)) # Combine all segments eight_d_audio = sum(segments) # Save to a temporary file temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") eight_d_audio.export(temp_file.name, format="mp3") return temp_file.name # Gradio Interface with gr.Blocks() as interface: gr.Markdown("# 🎧 8D Audio Converter") gr.Markdown("Upload your audio file, and this tool will transform it into 8D audio!") audio_input = gr.Audio(label="Upload Audio", type="filepath") audio_output = gr.Audio(label="8D Audio", type="filepath") convert_button = gr.Button("Convert to 8D") convert_button.click(fn=convert_to_8d, inputs=audio_input, outputs=audio_output) print("launching app") interface.launch(share=True)