coraKong's picture
Update app.py
b04ebb9
raw
history blame
No virus
1.16 kB
import gradio as gr
from TTS.api import TTS
# Init TTS
tts = TTS(TTS.list_models()[0], progress_bar=False, gpu=False) # 多语言
zh_tts = TTS("tts_models/zh-CN/baker/tacotron2-DDC-GST", progress_bar=False, gpu=False)
def text_to_speech(text: str, speaker_wav, language: str):
if language == "中文":
if speaker_wav is not None:
zh_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path="output.wav")
else:
zh_tts.tts_to_file(text, file_path="output.wav")
else:
if speaker_wav is not None:
tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
else:
tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path="output.wav")
return 'output.wav'
inputs = [gr.Textbox(label="Input the text", value="", max_lines=3),
gr.Audio(lable="Input your voice here", source="microphone", type="filepath"),
gr.Radio(label="Language", choices=["en", "中文", "fr-fr"], value="en")]
outputs = gr.Audio(label="Output")
demo = gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs)
demo.launch()