coraKong commited on
Commit
b04ebb9
1 Parent(s): 582cf5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,21 +1,26 @@
1
  import gradio as gr
2
  from TTS.api import TTS
3
 
4
- # List available 🐸TTS models and choose the first one
5
- model_name = "tts_models/zh-CN/baker/tacotron2-DDC-GST"
6
  # Init TTS
7
- tts = TTS(model_name, progress_bar=False, gpu=False)
 
8
 
9
  def text_to_speech(text: str, speaker_wav, language: str):
10
- if speaker_wav is not None:
11
- tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
 
 
 
12
  else:
13
- tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path="output.wav")
 
 
 
14
  return 'output.wav'
15
 
16
- inputs = [gr.Textbox(label="Input the text", value="Hello!", max_lines=3),
17
  gr.Audio(lable="Input your voice here", source="microphone", type="filepath"),
18
- gr.Radio(label="Language", choices=tts.languages, value="en")]
19
  outputs = gr.Audio(label="Output")
20
 
21
  demo = gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs)
 
1
  import gradio as gr
2
  from TTS.api import TTS
3
 
 
 
4
  # Init TTS
5
+ tts = TTS(TTS.list_models()[0], progress_bar=False, gpu=False) # 多语言
6
+ zh_tts = TTS("tts_models/zh-CN/baker/tacotron2-DDC-GST", progress_bar=False, gpu=False)
7
 
8
  def text_to_speech(text: str, speaker_wav, language: str):
9
+ if language == "中文":
10
+ if speaker_wav is not None:
11
+ zh_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path="output.wav")
12
+ else:
13
+ zh_tts.tts_to_file(text, file_path="output.wav")
14
  else:
15
+ if speaker_wav is not None:
16
+ tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
17
+ else:
18
+ tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path="output.wav")
19
  return 'output.wav'
20
 
21
+ inputs = [gr.Textbox(label="Input the text", value="", max_lines=3),
22
  gr.Audio(lable="Input your voice here", source="microphone", type="filepath"),
23
+ gr.Radio(label="Language", choices=["en", "中文", "fr-fr"], value="en")]
24
  outputs = gr.Audio(label="Output")
25
 
26
  demo = gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs)