File size: 1,355 Bytes
d997a1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()