Geek7 commited on
Commit
41eafd2
·
verified ·
1 Parent(s): 0da2786

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -1,3 +1,32 @@
1
  import gradio as gr
 
 
 
2
 
3
- gr.Interface.load("models/speechbrain/mtl-mimic-voicebank").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torchaudio
3
+ from speechbrain.inference.enhancement import WaveformEnhancement
4
+ import torch
5
 
6
+ # Load the SpeechBrain enhancement model
7
+ enhance_model = WaveformEnhancement.from_hparams(
8
+ source="speechbrain/mtl-mimic-voicebank",
9
+ savedir="pretrained_models/mtl-mimic-voicebank",
10
+ )
11
+
12
+ def enhance_audio(input_audio):
13
+ # Load the uploaded audio file
14
+ waveform, sample_rate = torchaudio.load(input_audio)
15
+
16
+ # Enhance the audio
17
+ enhanced_waveform = enhance_model.enhance_batch(waveform)
18
+
19
+ # Save the enhanced audio to a file
20
+ output_path = "enhanced_audio.wav"
21
+ torchaudio.save(output_path, enhanced_waveform.cpu(), sample_rate)
22
+
23
+ return output_path
24
+
25
+ # Set up the Gradio interface
26
+ demo = gr.Interface(
27
+ fn=enhance_audio,
28
+ inputs=gr.Audio(type="filepath"), # Upload an audio file
29
+ outputs=gr.Audio(type="filepath"), # Download the enhanced audio
30
+ )
31
+
32
+ demo.launch()