Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pydub import AudioSegment
|
| 3 |
+
from pydub.effects import normalize, compress_dynamic_range
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def mix_audio(vocal_file, music_file):
|
| 7 |
+
# تحميل ومعالجة الصوت
|
| 8 |
+
vocals = AudioSegment.from_file(vocal_file)
|
| 9 |
+
music = AudioSegment.from_file(music_file)
|
| 10 |
+
|
| 11 |
+
vocals = normalize(vocals)
|
| 12 |
+
vocals = compress_dynamic_range(vocals, threshold=-20.0, ratio=4.0)
|
| 13 |
+
|
| 14 |
+
if len(music) < len(vocals):
|
| 15 |
+
music = music * ((len(vocals) // len(music)) + 1)
|
| 16 |
+
|
| 17 |
+
music = music[:len(vocals) + 2000] - 9
|
| 18 |
+
final = music.overlay(vocals, position=0)
|
| 19 |
+
final = normalize(final)
|
| 20 |
+
|
| 21 |
+
output_path = "final_master.mp3"
|
| 22 |
+
final.export(output_path, format="mp3", bitrate="320k")
|
| 23 |
+
return output_path
|
| 24 |
+
|
| 25 |
+
# واجهة بسيطة لاستقبال الملفات من n8n
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=mix_audio,
|
| 28 |
+
inputs=[gr.Audio(type="filepath"), gr.Audio(type="filepath")],
|
| 29 |
+
outputs=gr.Audio(type="filepath")
|
| 30 |
+
)
|
| 31 |
+
demo.launch()
|