Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from pydub import AudioSegment | |
| import tempfile | |
| import os | |
| import shutil | |
| def convert_mp3_to_wav(mp3_file): | |
| # Extract base name without extension | |
| base_name = os.path.splitext(os.path.basename(mp3_file.name))[0] | |
| output_filename = f"{base_name}.wav" | |
| # Create temporary output directory | |
| temp_dir = tempfile.mkdtemp() | |
| output_path = os.path.join(temp_dir, output_filename) | |
| # Convert and export as WAV | |
| audio = AudioSegment.from_mp3(mp3_file.name) | |
| audio.export(output_path, format="wav") | |
| return output_path # Gradio will let the user download this | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=convert_mp3_to_wav, | |
| inputs=gr.File(label="Upload MP3 File", file_types=[".mp3"]), | |
| outputs=gr.File(label="Download WAV File"), | |
| title="MP3 to WAV Converter", | |
| description="Upload an MP3 file and download the converted WAV file with the same name." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |