coraKong's picture
Update app.py
1e7525f
raw
history blame
No virus
2.06 kB
import gradio as gr
from TTS.api import TTS
# Init TTS
tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar = False, gpu=False)
zh_tts = TTS(model_name="tts_models/zh-CN/baker/tacotron2-DDC-GST", progress_bar=False, gpu=False)
de_tts = TTS(model_name = "tts_models/de/thorsten/vits", gpu=False)
# de_tts = TTS(model_name = "tts_models/de/thorsten/tacotron2-DCA", gpu=False)
# es_tts = TTS(model_name = "tts_models/es/mai/tacotron2-DCA", progress_bar=False, gpu=False)
def text_to_speech(text: str, speaker_wav, speaker_wav_file, language: str):
if speaker_wav_file and not speaker_wav:
speaker_wav = speaker_wav_file
file_path = "output.wav"
if language == "zh-CN":
# if speaker_wav is not None:
# zh_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
# else:
zh_tts.tts_to_file(text, file_path=file_path)
elif language == "de":
# if speaker_wav is not None:
# de_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
# else:
de_tts.tts_to_file(text, file_path=file_path)
# elif language == "es":
# if speaker_wav is not None:
# es_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
# else:
# es_tts.tts_to_file(text, file_path=file_path)
else:
if speaker_wav is not None:
tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path=file_path)
else:
tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path=file_path)
return file_path
inputs = [gr.Textbox(label="Input the text", value="", max_lines=3),
gr.Audio(label="Voice to clone", source="microphone", type="filepath"),
gr.Audio(label="Voice to clone", type="filepath"),
gr.Radio(label="Language", choices=["en", "zh-CN", "fr-fr", "de"], value="en")]
outputs = gr.Audio(label="Output")
demo = gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs)
demo.launch()