Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
-
import torchaudio
|
| 4 |
-
#from speechbrain.inference.enhancement import SpectralMaskEnhancement
|
| 5 |
-
|
| 6 |
-
# Load the MetricGAN model
|
| 7 |
-
enhance_model = SpectralMaskEnhancement.from_hparams(
|
| 8 |
-
source="speechbrain/metricgan-plus-voicebank",
|
| 9 |
-
savedir="tmpdir_metricgan",
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
# Define a function to enhance speech
|
| 13 |
-
def enhance_speech(audio):
|
| 14 |
-
# Load the audio and add fake batch dimension
|
| 15 |
-
noisy = enhance_model.load_audio(audio).unsqueeze(0)
|
| 16 |
-
|
| 17 |
-
# Add relative length tensor (assuming full length)
|
| 18 |
-
lengths = torch.tensor([1.])
|
| 19 |
-
|
| 20 |
-
# Enhance the audio
|
| 21 |
-
enhanced = enhance_model.enhance_batch(noisy, lengths)
|
| 22 |
-
|
| 23 |
-
# Save enhanced audio to a temporary file
|
| 24 |
-
output_path = "enhanced.wav"
|
| 25 |
-
torchaudio.save(output_path, enhanced.cpu(), 16000)
|
| 26 |
-
return output_path
|
| 27 |
-
|
| 28 |
-
# Set up the Gradio interface
|
| 29 |
-
iface = gr.Interface(
|
| 30 |
-
fn=enhance_speech,
|
| 31 |
-
inputs=gr.Audio(type="filepath"), # Removed 'source' argument
|
| 32 |
-
outputs=gr.Audio(type="filepath"),
|
| 33 |
-
title="Speech Enhancement",
|
| 34 |
-
description="Upload a noisy audio file to enhance it using MetricGAN."
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
# Launch the Gradio interface
|
| 38 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|