Spaces:
Sleeping
Sleeping
File size: 966 Bytes
ab5dda0 27df5d6 ab5dda0 c7cf0aa ab5dda0 c7cf0aa ab5dda0 c7cf0aa ab5dda0 27df5d6 ab5dda0 c7cf0aa ab5dda0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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()
|