Kevin676's picture
Duplicate from akhaliq/Speechbrain-Speech-enhancement
d997a1f
raw
history blame
1.36 kB
import torch
import torchaudio
from speechbrain.pretrained import SpectralMaskEnhancement
import gradio as gr
enhance_model = SpectralMaskEnhancement.from_hparams(
source="speechbrain/metricgan-plus-voicebank",
savedir="pretrained_models/metricgan-plus-voicebank",
)
def speechbrain(aud):
# Load and add fake batch dimension
noisy = enhance_model.load_audio(
aud.name
).unsqueeze(0)
enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
torchaudio.save('enhanced.wav', enhanced.cpu(), 16000)
return 'enhanced.wav'
inputs = gr.inputs.Audio(label="Input Audio", type="file")
outputs = gr.outputs.Audio(label="Output Audio", type="file")
title = "Speechbrain Speech Enhancement"
description = "Gradio demo for Speech enhancement with SpeechBrain. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below."
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2104.03538' target='_blank'>MetricGAN+: An Improved Version of MetricGAN for Speech Enhancement</a> | <a href='https://github.com/speechbrain/speechbrain' target='_blank'>Github Repo</a></p>"
examples = [
['samples_audio_samples_example_fr.wav']
]
gr.Interface(speechbrain, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()