|
import gradio as gr |
|
import os |
|
from TTS.api import TTS |
|
import time |
|
|
|
|
|
""" |
|
For Fairseq models, use the following name format: tts_models/<lang-iso_code>/fairseq/vits. You can find the language ISO codes here and learn about the Fairseq models here. |
|
https://dl.fbaipublicfiles.com/mms/tts/all-tts-languages.html |
|
""" |
|
|
|
api_rus = TTS(f"tts_models/rus/fairseq/vits", gpu=False) |
|
api_eng = TTS(f"tts_models/eng/fairseq/vits", gpu=False) |
|
api_spa = TTS(f"tts_models/spa/fairseq/vits", gpu=False) |
|
api_fas = TTS(f"tts_models/fas/fairseq/vits", gpu=False) |
|
api_tur = TTS(f"tts_models/tur/fairseq/vits", gpu=False) |
|
api_deu = TTS(f"tts_models/deu/fairseq/vits", gpu=False) |
|
api_ara = TTS(f"tts_models/ara/fairseq/vits", gpu=False) |
|
api_por = TTS(f"tts_models/por/fairseq/vits", gpu=False) |
|
api_hin = TTS(f"tts_models/hin/fairseq/vits", gpu=False) |
|
|
|
|
|
def audio_tts(txt, language, audio_file): |
|
|
|
|
|
print(f"Language: {language}") |
|
if language == "rus": |
|
api_rus.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "eng": |
|
api_eng.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "spa": |
|
api_spa.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "fas": |
|
api_fas.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "tur": |
|
api_tur.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "deu": |
|
api_deu.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "ara": |
|
api_ara.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "por": |
|
api_por.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
elif language == "hin": |
|
api_hin.tts_with_vc_to_file(txt, speaker_wav=audio_file, file_path="ouptut.wav") |
|
return "ouptut.wav" |
|
|
|
|
|
demo = gr.Interface(fn=audio_tts, inputs=[gr.Textbox(label="Input text TTS", value="Привет! Я Макс."), |
|
gr.Dropdown(choices=["rus", "eng", "spa", "fas", "tur", "deu", "ara", "por", "hin"], |
|
label="Language", value="rus"), |
|
gr.Audio(source="upload", type="filepath", label="Input audio")], |
|
outputs=gr.Audio(source="upload", type="filepath", label="Output audio")) |
|
|
|
demo.queue(concurrency_count=1).launch(show_error=True) |