|
|
|
import gradio as gr |
|
import tempfile |
|
import subprocess |
|
|
|
def convert_webm_to_mp3(webm_file): |
|
|
|
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as tmp_mp3: |
|
tmp_mp3_path = tmp_mp3.name |
|
|
|
|
|
ffmpeg_command = [ |
|
"ffmpeg", "-y", |
|
"-i", webm_file, |
|
"-vn", |
|
"-acodec", "libmp3lame", |
|
"-q:a", "2", |
|
tmp_mp3_path |
|
] |
|
|
|
|
|
process = subprocess.run(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
|
|
|
if process.returncode != 0: |
|
|
|
print("Error in conversion:", process.stderr.decode()) |
|
return "Error in conversion. Please check the file format and try again." |
|
|
|
|
|
return tmp_mp3_path |
|
|
|
|
|
iface = gr.Interface( |
|
fn=convert_webm_to_mp3, |
|
inputs=gr.File(type="filepath", label="Upload .webm file"), |
|
outputs=gr.File(label="Converted .mp3 file"), |
|
title="WebM to MP3 Converter", |
|
description="Upload a .webm audio file, and this tool will convert it to .mp3 format." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|