Ahsen Khaliq commited on
Commit
c7ccbdd
β€’
1 Parent(s): 8cf66e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchaudio
3
+ from speechbrain.pretrained import SpectralMaskEnhancement
4
+ import gradio as gr
5
+
6
+ enhance_model = SpectralMaskEnhancement.from_hparams(
7
+ source="speechbrain/metricgan-plus-voicebank",
8
+ savedir="pretrained_models/metricgan-plus-voicebank",
9
+ )
10
+
11
+ def speechbrain(aud):
12
+ # Load and add fake batch dimension
13
+ noisy = enhance_model.load_audio(
14
+ aud.name
15
+ ).unsqueeze(0)
16
+ enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
17
+ torchaudio.save('enhanced.wav', enhanced.cpu(), 16000)
18
+ return 'enhanced.wav'
19
+
20
+ inputs = gr.inputs.Audio(label="Input Audio", type="file")
21
+ outputs = gr.outputs.Audio(label="Output Audio", type="file")
22
+ title = "Speechbrain Speech Enhancement"
23
+ 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."
24
+ 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>"
25
+ examples = [
26
+ ['samples_audio_samples_example_fr.wav']
27
+ ]
28
+ gr.Interface(speechbrain, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()