mobenta's picture
Upload 2 files
2c84fff verified
raw
history blame
1.25 kB
import gradio as gr
from pydub import AudioSegment
def compress_audio(input_audio_path, compression_rate=128):
"""
Compress an audio file.
Args:
input_audio_path: Path to the input audio file.
compression_rate: Desired bitrate for compression (in kbps).
Returns:
Compressed audio file path.
"""
try:
# Load the audio file using pydub
audio = AudioSegment.from_file(input_audio_path)
# Temporary output path
output_path = "compressed_audio.mp3"
# Export the compressed audio
audio.export(output_path, format="mp3", bitrate=f"{compression_rate}k")
return output_path
except Exception as e:
return str(e)
# Create the Gradio app
interface = gr.Interface(
fn=compress_audio,
inputs=[
gr.Audio(label="Upload Audio File", type="filepath"),
gr.Slider(32, 320, step=16, label="Compression Rate (kbps)", value=128),
],
outputs=gr.File(label="Download Compressed Audio"),
title="Audio Compressor",
description="Upload an audio file and select the compression rate to reduce the file size.",
allow_flagging="never",
)
# Launch the app
interface.launch()