Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,50 +3,45 @@ from pedalboard import Pedalboard, Compressor, Gain, Limiter, HighpassFilter
|
|
| 3 |
from pedalboard.io import AudioFile
|
| 4 |
import os
|
| 5 |
import tempfile
|
| 6 |
-
import shutil
|
| 7 |
|
| 8 |
def master_audio(input_file):
|
| 9 |
if input_file is None:
|
| 10 |
return None
|
| 11 |
|
| 12 |
try:
|
| 13 |
-
# 1. Mamaky ny rakitra
|
| 14 |
with AudioFile(input_file) as f:
|
| 15 |
audio = f.read(f.frames)
|
| 16 |
samplerate = f.samplerate
|
| 17 |
|
| 18 |
-
# 2.
|
| 19 |
board = Pedalboard([
|
| 20 |
HighpassFilter(cutoff_frequency_hz=30),
|
| 21 |
-
Compressor(threshold_db=-
|
| 22 |
-
Gain(gain_db=
|
| 23 |
-
Limiter(threshold_db=-
|
| 24 |
])
|
| 25 |
|
| 26 |
-
# 3. Manatanteraka ny Mastering
|
| 27 |
mastered_audio = board(audio, samplerate)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
output_path = os.path.join(tempfile.gettempdir(), "
|
| 31 |
with AudioFile(output_path, 'w', samplerate, mastered_audio.shape[0]) as f:
|
| 32 |
f.write(mastered_audio)
|
| 33 |
|
| 34 |
return output_path
|
| 35 |
except Exception as e:
|
| 36 |
-
print(f"Error: {e}")
|
| 37 |
return None
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
gr.
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
submit_btn = gr.Button("Submit / Master my Track", variant="primary")
|
| 49 |
-
submit_btn.click(fn=master_audio, inputs=audio_in, outputs=audio_out)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
-
demo.launch()
|
|
|
|
| 3 |
from pedalboard.io import AudioFile
|
| 4 |
import os
|
| 5 |
import tempfile
|
|
|
|
| 6 |
|
| 7 |
def master_audio(input_file):
|
| 8 |
if input_file is None:
|
| 9 |
return None
|
| 10 |
|
| 11 |
try:
|
| 12 |
+
# 1. Mamaky ny rakitra
|
| 13 |
with AudioFile(input_file) as f:
|
| 14 |
audio = f.read(f.frames)
|
| 15 |
samplerate = f.samplerate
|
| 16 |
|
| 17 |
+
# 2. Mastering Chain tsotra
|
| 18 |
board = Pedalboard([
|
| 19 |
HighpassFilter(cutoff_frequency_hz=30),
|
| 20 |
+
Compressor(threshold_db=-18, ratio=3.0),
|
| 21 |
+
Gain(gain_db=3),
|
| 22 |
+
Limiter(threshold_db=-0.5)
|
| 23 |
])
|
| 24 |
|
|
|
|
| 25 |
mastered_audio = board(audio, samplerate)
|
| 26 |
|
| 27 |
+
# 3. Tehirizina amin'ny anarana mazava
|
| 28 |
+
output_path = os.path.join(tempfile.gettempdir(), "mastered.wav")
|
| 29 |
with AudioFile(output_path, 'w', samplerate, mastered_audio.shape[0]) as f:
|
| 30 |
f.write(mastered_audio)
|
| 31 |
|
| 32 |
return output_path
|
| 33 |
except Exception as e:
|
|
|
|
| 34 |
return None
|
| 35 |
|
| 36 |
+
# 4. Interface natao ho an'ny Mobile (tsy misy Blocks be pitsiny)
|
| 37 |
+
demo = gr.Interface(
|
| 38 |
+
fn=master_audio,
|
| 39 |
+
inputs=gr.Audio(type="filepath", label="Hira ampidirina", sources=["upload"]),
|
| 40 |
+
outputs=gr.Audio(label="Hira efa vita"),
|
| 41 |
+
title="AI Master Pro",
|
| 42 |
+
# Ity 'concurrency_limit' ity dia manampy amin'ny fitoniana
|
| 43 |
+
concurrency_limit=5
|
| 44 |
+
)
|
|
|
|
|
|
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
+
demo.launch(share=True)
|