File size: 1,082 Bytes
9496c69 232819a 9496c69 232819a 9496c69 232819a 9496c69 d59b27f 9496c69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import gradio as gr
import torch
import torchaudio
from df import enhance, init_df
from pydub import AudioSegment
def wav_to_mp3(wav_path, mp3_path):
# Load the WAV file
audio = AudioSegment.from_wav(wav_path)
# Export as MP3
audio.export(mp3_path, format="mp3")
# Initialize DeepFilterNet model
model, df_state, _ = init_df()
def denoise_audio(audio):
# Load the input audio file
waveform, sample_rate = torchaudio.load(audio)
# Denoise the audio
enhanced_audio = enhance(model, df_state, waveform)
# Save and return the enhanced audio file
output_file = "enhanced_output.wav"
torchaudio.save(output_file, enhanced_audio, sample_rate)
wav_to_mp3(output_file,"enhanced.mp3")
output_file="enhanced.mp3"
return output_file
# Gradio interface
iface = gr.Interface(
fn=denoise_audio,
inputs=gr.Audio(type="filepath"), # Remove 'source' argument
outputs="file",
title="DeepFilterNet Audio Denoising",
description="Upload an audio file to remove noise using DeepFilterNet."
)
iface.launch()
|