Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from pydub import AudioSegment | |
| import numpy as np | |
| import noisereduce as nr | |
| import scipy.io.wavfile as wav | |
| import os | |
| def reduce_noise(audio_file_path, noise_level): | |
| # Load audio | |
| audio = AudioSegment.from_file(audio_file_path) | |
| audio = audio.set_channels(1) | |
| audio = audio.set_frame_rate(44100) | |
| audio = audio.normalize() | |
| # Save temp wav | |
| temp_input = "temp_input.wav" | |
| audio.export(temp_input, format="wav") | |
| # Read raw audio | |
| rate, data = wav.read(temp_input) | |
| # Noise Reduction | |
| reduced = nr.reduce_noise(y=data, sr=rate, prop_decrease=noise_level) | |
| # Save output | |
| output_path = "output.wav" | |
| wav.write(output_path, rate, reduced.astype(np.int16)) | |
| return output_path | |
| # Gradio Interface | |
| interface = gr.Interface( | |
| fn=reduce_noise, | |
| inputs=[ | |
| gr.Audio(type="filepath", label="π Upload your audio file"), | |
| gr.Slider(minimum=0.1, maximum=1.0, value=0.8, step=0.1, label="ποΈ Noise-reduction level (low β high)") | |
| ], | |
| outputs=gr.Audio(type="filepath", label="β Noise-removed output"), | |
| title="π§ Free Noise Remover", | |
| description="Upload your audio file and set the level to get a noise-free output.", | |
| ) | |
| interface.launch() | |