Spaces:
Sleeping
Sleeping
| # app.py | |
| # ============= | |
| # This is a complete app.py file for an audio conversion app using Gradio and PyDub. | |
| import gradio as gr | |
| from pydub import AudioSegment | |
| import os | |
| from datetime import datetime | |
| def convert_audio(file_path, volume_increase, bitrate): | |
| # Load the AAC file | |
| audio = AudioSegment.from_file(file_path, format="aac") | |
| # Increase the volume by the specified amount in dB | |
| audio = audio + volume_increase | |
| # Set the bitrate | |
| # Generate a unique filename to avoid overwriting | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| output_filename = f"converted_{timestamp}.mp3" | |
| output_path = os.path.join(os.path.dirname(file_path), output_filename) | |
| audio.export(output_path, format="mp3", bitrate=f"{bitrate}k") | |
| return output_path | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=convert_audio, | |
| inputs=[ | |
| gr.File(label="Upload AAC file"), | |
| gr.Slider(minimum=0, maximum=20, step=1, value=10, label="Volume Increase (dB)"), | |
| gr.Slider(minimum=32, maximum=320, step=8, value=64, label="Bitrate (kbps)") | |
| ], | |
| outputs=gr.Audio(label="Converted MP3 file", type="filepath"), | |
| title="AAC to MP3 Converter", | |
| description="Upload an AAC file, and it will be converted to MP3 with the specified volume increase and bitrate." | |
| ) | |
| # Launch the Gradio app | |
| if __name__ == "__main__": | |
| iface.launch() | |
| # Dependencies | |
| # ============= | |
| # The following dependencies are required to run this app: | |
| # - gradio | |
| # - pydub | |
| # - ffmpeg (required by pydub for audio processing) | |
| # | |
| # You can install these dependencies using pip: | |
| # pip install gradio pydub | |
| # | |
| # Note: ffmpeg is not a Python package but a system dependency. You can install it using your package manager: | |
| # - On Ubuntu/Debian: sudo apt-get install ffmpeg | |
| # - On macOS: brew install ffmpeg | |
| # - On Windows: Download and install from https://ffmpeg.org/download.html |