Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pydub import AudioSegment
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def combine_audio(waves_file, seagulls_file):
|
| 6 |
+
try:
|
| 7 |
+
# Load the audio files
|
| 8 |
+
waves = AudioSegment.from_file(waves_file)
|
| 9 |
+
seagulls = AudioSegment.from_file(seagulls_file)
|
| 10 |
+
|
| 11 |
+
# Adjust volumes
|
| 12 |
+
waves = waves - 5 # Lower the volume of waves by 5dB
|
| 13 |
+
seagulls = seagulls + 3 # Increase the volume of seagulls by 3dB
|
| 14 |
+
|
| 15 |
+
# Combine audio
|
| 16 |
+
combined_audio = waves.overlay(seagulls)
|
| 17 |
+
|
| 18 |
+
# Save the output
|
| 19 |
+
output_file = "seagulls_over_waves.mp3"
|
| 20 |
+
combined_audio.export(output_file, format="mp3")
|
| 21 |
+
|
| 22 |
+
return output_file
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Error: {e}"
|
| 25 |
+
|
| 26 |
+
# Define the Gradio interface
|
| 27 |
+
interface = gr.Interface(
|
| 28 |
+
fn=combine_audio,
|
| 29 |
+
inputs=[
|
| 30 |
+
gr.Audio(source="upload", type="file", label="Upload Waves Audio"),
|
| 31 |
+
gr.Audio(source="upload", type="file", label="Upload Seagulls Audio"),
|
| 32 |
+
],
|
| 33 |
+
outputs=gr.Audio(type="file", label="Combined Audio"),
|
| 34 |
+
title="Audio Combiner",
|
| 35 |
+
description="Upload two audio files (e.g., waves and seagulls) to combine them into one seamless track.",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Launch the app
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
interface.launch()
|