Kevin676 commited on
Commit
6a4aaf8
1 Parent(s): 1820ca7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from turtle import title
2
  import gradio as gr
3
 
4
  import git
@@ -7,6 +7,11 @@ 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
 
@@ -23,9 +28,14 @@ import numpy as np
23
  import IPython
24
  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
31
  try:
@@ -154,12 +164,27 @@ 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,
161
- inputs=[gr.inputs.Textbox(label='What would you like the voice to say? (max. 2000 characters per request)'),gr.Audio(type="filepath", source="upload",label='Please upload a voice to clone (max. 30mb)'),gr.Audio(source="microphone", type="filepath", streaming=True)],
162
  outputs="audio",
163
- title="Bilal's Voice Cloning Tool"
 
 
164
  )
165
  demo.launch()
 
1
+ #from turtle import title
2
  import gradio as gr
3
 
4
  import git
 
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
+
15
  import sys
16
  TTS_PATH = "TTS/"
17
 
 
28
  import IPython
29
  from IPython.display import Audio
30
 
 
31
  import torch
32
 
33
+ enhance_model = SpectralMaskEnhancement.from_hparams(
34
+ source="speechbrain/metricgan-plus-voicebank",
35
+ savedir="pretrained_models/metricgan-plus-voicebank",
36
+ run_opts={"device":"cuda"},
37
+ )
38
+
39
  from TTS.tts.utils.synthesis import synthesis
40
  from TTS.tts.utils.text.symbols import make_symbols, phonemes, symbols
41
  try:
 
164
  out_path = os.path.join(OUT_PATH, file_name)
165
  print(" > Saving output to {}".format(out_path))
166
  ap.save_wav(wav, out_path)
167
+
168
+ voicefixer.restore(input=out_path, # input wav file path
169
+ output="audio1.wav", # output wav file path
170
+ cuda=True, # whether to use gpu acceleration
171
+ mode = 0) # You can try out mode 0, 1, or 2 to find out the best result
172
+
173
+ noisy = enhance_model.load_audio(
174
+ "audio1.wav"
175
+ ).unsqueeze(0)
176
+
177
+ enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
178
+ torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
179
+
180
+ return "enhanced.wav"
181
 
182
  demo = gr.Interface(
183
  fn=greet,
184
+ inputs=[gr.inputs.Textbox(label='请输入您想要合成的文字,请自觉合法合规使用!'),gr.Audio(type="filepath", source="upload",label='请上传您喜欢的声音(wav/mp3文件, max. 30mb)'),gr.Audio(source="microphone", type="filepath", label = '请用麦克风上传您喜欢的声音,与文件上传二选一即可')],
185
  outputs="audio",
186
+ title="🥳💬💕 - TalktoAI,随时随地,谈天说地!",
187
+ description = "🔴注意🔴:请不要生成会对个人以及组织造成侵害的内容,仅供科研、学习使用。用户生成内容与程序开发者无关,请自觉合法合规使用,违反者一切后果自负。"
188
+ article = "🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!",
189
  )
190
  demo.launch()