kevinwang676 commited on
Commit
132e7e7
1 Parent(s): e4298f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -14,8 +14,16 @@ import gradio as gr
14
  from scipy.io import wavfile
15
  from scipy.io.wavfile import write
16
 
 
 
 
 
 
 
 
17
  knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
18
 
 
19
  def voice_change(audio_in, audio_ref):
20
  samplerate1, data1 = wavfile.read(audio_in)
21
  samplerate2, data2 = wavfile.read(audio_ref)
@@ -53,7 +61,14 @@ def tts(text, model, voice, api_key):
53
 
54
  # Get the file path of the temp file
55
  temp_file_path = temp_file.name
56
-
 
 
 
 
 
 
 
57
  return temp_file_path
58
 
59
 
 
14
  from scipy.io import wavfile
15
  from scipy.io.wavfile import write
16
 
17
+ from speechbrain.pretrained import SpectralMaskEnhancement
18
+
19
+ enhance_model = SpectralMaskEnhancement.from_hparams(
20
+ source="speechbrain/metricgan-plus-voicebank",
21
+ savedir="pretrained_models/metricgan-plus-voicebank",
22
+ )
23
+
24
  knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
25
 
26
+
27
  def voice_change(audio_in, audio_ref):
28
  samplerate1, data1 = wavfile.read(audio_in)
29
  samplerate2, data2 = wavfile.read(audio_ref)
 
61
 
62
  # Get the file path of the temp file
63
  temp_file_path = temp_file.name
64
+
65
+ noisy = enhance_model.load_audio(
66
+ temp_file_path
67
+ ).unsqueeze(0)
68
+ enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
69
+ torchaudio.save('enhanced.wav', enhanced.cpu(), 16000)
70
+ return 'enhanced.wav'
71
+
72
  return temp_file_path
73
 
74