Kevin676 commited on
Commit
6d1d18c
1 Parent(s): f197956

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -7,6 +7,10 @@ os.system('git clone https://github.com/Edresson/Coqui-TTS -b multilingual-torch
7
  os.system('pip install -q -e TTS/')
8
  os.system('pip install -q torchaudio==0.9.0')
9
 
 
 
 
 
10
  import sys
11
  TTS_PATH = "TTS/"
12
 
@@ -25,6 +29,14 @@ from IPython.display import Audio
25
 
26
 
27
  import torch
 
 
 
 
 
 
 
 
28
 
29
  from TTS.tts.utils.synthesis import synthesis
30
  from TTS.tts.utils.text.symbols import make_symbols, phonemes, symbols
@@ -154,7 +166,18 @@ def greet(Text,Voicetoclone,VoiceMicrophone):
154
  out_path = os.path.join(OUT_PATH, file_name)
155
  print(" > Saving output to {}".format(out_path))
156
  ap.save_wav(wav, out_path)
157
- return out_path
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  demo = gr.Interface(
160
  fn=greet,
 
7
  os.system('pip install -q -e TTS/')
8
  os.system('pip install -q torchaudio==0.9.0')
9
 
10
+ os.system('pip install voicefixer --upgrade')
11
+ from voicefixer import VoiceFixer
12
+ voicefixer = VoiceFixer()
13
+
14
  import sys
15
  TTS_PATH = "TTS/"
16
 
 
29
 
30
 
31
  import torch
32
+ import torchaudio
33
+ from speechbrain.pretrained import SpectralMaskEnhancement
34
+
35
+ enhance_model = SpectralMaskEnhancement.from_hparams(
36
+ source="speechbrain/metricgan-plus-voicebank",
37
+ savedir="pretrained_models/metricgan-plus-voicebank",
38
+ run_opts={"device":"cuda"},
39
+ )
40
 
41
  from TTS.tts.utils.synthesis import synthesis
42
  from TTS.tts.utils.text.symbols import make_symbols, phonemes, symbols
 
166
  out_path = os.path.join(OUT_PATH, file_name)
167
  print(" > Saving output to {}".format(out_path))
168
  ap.save_wav(wav, out_path)
169
+ voicefixer.restore(input=out_path, # input wav file path
170
+ output="audio1.wav", # output wav file path
171
+ cuda=True, # whether to use gpu acceleration
172
+ mode = 0) # You can try out mode 0, 1, or 2 to find out the best result
173
+
174
+ noisy = enhance_model.load_audio(
175
+ "audio1.wav"
176
+ ).unsqueeze(0)
177
+
178
+ enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
179
+ torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
180
+ return "enhanced.wav"
181
 
182
  demo = gr.Interface(
183
  fn=greet,