Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from pedalboard import Pedalboard, Compressor, Gain, Limiter, HighpassFilter | |
| from pedalboard.io import AudioFile | |
| import os | |
| import tempfile | |
| def master_audio(input_file): | |
| if input_file is None: | |
| return None | |
| try: | |
| # 1. Mamaky ny rakitra | |
| with AudioFile(input_file) as f: | |
| audio = f.read(f.frames) | |
| samplerate = f.samplerate | |
| # 2. Mastering Chain tsotra | |
| board = Pedalboard([ | |
| HighpassFilter(cutoff_frequency_hz=30), | |
| Compressor(threshold_db=-18, ratio=3.0), | |
| Gain(gain_db=3), | |
| Limiter(threshold_db=-0.5) | |
| ]) | |
| mastered_audio = board(audio, samplerate) | |
| # 3. Tehirizina amin'ny anarana mazava | |
| output_path = os.path.join(tempfile.gettempdir(), "mastered.wav") | |
| with AudioFile(output_path, 'w', samplerate, mastered_audio.shape[0]) as f: | |
| f.write(mastered_audio) | |
| return output_path | |
| except Exception as e: | |
| return None | |
| # 4. Interface natao ho an'ny Mobile (tsy misy Blocks be pitsiny) | |
| demo = gr.Interface( | |
| fn=master_audio, | |
| inputs=gr.Audio(type="filepath", label="Hira ampidirina", sources=["upload"]), | |
| outputs=gr.Audio(label="Hira efa vita"), | |
| title="AI Master Pro", | |
| # Ity 'concurrency_limit' ity dia manampy amin'ny fitoniana | |
| concurrency_limit=5 | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(share=True) |