Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| import subprocess | |
| # Function to get the file extension | |
| def get_file_extension(file_path): | |
| return os.path.splitext(file_path)[1].lower() | |
| # Function to convert the audio file using ffmpeg | |
| def convert_audio(file, output_extension): | |
| input_extension = get_file_extension(file) | |
| output_file = file.replace(input_extension, f'.{output_extension}') | |
| # FFmpeg command to convert the audio file | |
| command = f'ffmpeg -i "{file}" "{output_file}"' | |
| subprocess.run(command, shell=True) | |
| return output_file | |
| # Gradio Interface | |
| def interface(file, output_extension): | |
| output_file = convert_audio(file, output_extension) | |
| return output_file | |
| # Building the Gradio interface | |
| with gr.Blocks() as app: | |
| gr.Markdown("## Audio Converter using FFmpeg") | |
| with gr.Row(): | |
| input_file = gr.File(label="Upload Audio File", type="filepath") | |
| output_extension = gr.Textbox(label="Enter Output File Extension (e.g., mp3, wav, m4a, etc.)") | |
| output_file = gr.File(label="Converted Audio File") | |
| convert_button = gr.Button("Convert") | |
| convert_button.click(fn=interface, inputs=[input_file, output_extension], outputs=output_file) | |
| # Launch the app | |
| app.launch() | |