|
import gradio as gr |
|
from infer_onnx import TTS |
|
from ruaccent import RUAccent |
|
|
|
|
|
title = "RU - Russian Voices" |
|
article="Speech synthesis - RU" |
|
|
|
|
|
models = ["S1m0neAI/ru_model"] |
|
|
|
|
|
models = {k: TTS(k) for k in models} |
|
|
|
|
|
accentizer = RUAccent() |
|
accentizer.load(omograph_model_size='turbo3.1', use_dictionary=True) |
|
|
|
|
|
|
|
|
|
def text_to_speech(model_name, length_scale, text, prep_text): |
|
if prep_text: |
|
text = accentizer.process_all(text) |
|
audio = models[model_name](text, length_scale=length_scale) |
|
models[model_name].save_wav(audio, 'temp.wav', sample_rate=models[model_name].config["samplerate"]) |
|
|
|
return 'temp.wav', f"Обработанный текст: '{text}'" |
|
|
|
|
|
model_choice = gr.Dropdown(choices=list(models.keys()), value="S1m0neAI/ru_model", label="Модель") |
|
input_text = gr.Textbox(label="Введите текст для синтеза речи") |
|
prep_text = gr.Checkbox(label="Предобработать", info="Хотите предобработать текст? (ударения, ё)", value=True) |
|
length_scale = gr.Slider(minimum=0.1, maximum=2.0, label="Length scale (увеличить длину звучания) По умолчанию: 1.2", value=1.2) |
|
|
|
output_audio = gr.Audio(label="Аудио", type="numpy") |
|
output_text = gr.Textbox(label="Текст") |
|
|
|
iface = gr.Interface(fn=text_to_speech, inputs=[model_choice, length_scale, input_text, prep_text], outputs=[output_audio, output_text], title=title) |
|
iface.launch() |