File size: 1,651 Bytes
dfc143a
 
 
 
9fd1e6b
 
dfc143a
 
 
 
9fd1e6b
dfc143a
 
 
 
 
 
 
c5e6494
dfc143a
 
c5e6494
dfc143a
 
 
 
 
 
 
c5e6494
dfc143a
 
 
 
c5e6494
9fd1e6b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
from infer_onnx import TTS
from ruaccent import RUAccent # https://huggingface.co/TeraTTS/accentuator

title = "GitHub with models: https://github.com/Tera2Space/RUTTS"

models = ["TeraTTS/natasha-g2p-vits", "TeraTTS/glados2-g2p-vits"]

models = {k:TTS(k) for k in models}

accentizer = RUAccent(workdir="./model/ruaccent", allow_cuda=False)
accentizer.load(omograph_model_size='medium', dict_load_startup=True)


def process_text(text: str) -> str:
    text = accentizer.process_all(text)
    return text

def text_to_speech(model_name, lenght_scale, text, prep_text):
    if prep_text:
        text = process_text(text)
    audio = models[model_name](text, lenght_scale=lenght_scale)
    models[model_name].save_wav(audio, 'temp.wav')

    return 'temp.wav', f"Обработанный текст: '{text}'"

model_choice = gr.Dropdown(choices=list(models.keys()), value="TeraTTS/natasha-g2p-vits", label="Выберите модель")
input_text = gr.Textbox(label="Введите текст для синтеза речи")
prep_text = gr.Checkbox(label="Предобработать", info="Хотите пред обработать текст?(Ударения, ё)", value=True)
lenght_scale = gr.Slider(minimum=0.1, maximum=2.0, label="Lenght Scale(увеличить длину звучания) Default: 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, lenght_scale, input_text, prep_text], outputs=[output_audio, output_text], title=title)
iface.launch()