Shokoufehhh commited on
Commit
930cece
·
verified ·
1 Parent(s): 26b1985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -1,7 +1,38 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()