Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,20 @@ from infer import inference
|
|
3 |
import unicodedata
|
4 |
import regex
|
5 |
|
6 |
-
# Основное описание
|
7 |
description = '''
|
8 |
Програма може не коректно визначати деякі наголоси і не перетворює цифри, акроніми і різні скорочення в словесну форму.
|
9 |
Якщо наголос не правильний, використовуйте символ + після наголошеного складу.
|
10 |
Також дуже маленькі речення можуть крешати, тому пишіть щось більше а не одне-два слова.
|
11 |
'''
|
12 |
|
13 |
-
# Дополнительные функции для
|
14 |
def normalize_text(text):
|
15 |
return unicodedata.normalize('NFC', text)
|
16 |
|
17 |
-
def
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
text = text.replace('—', '—:::')
|
22 |
-
text = text.replace('–', '–:::')
|
23 |
-
text = text.replace('.', '. ... ... ')
|
24 |
-
text = text.replace('!', '! ... ...')
|
25 |
-
text = text.replace('?', '? ... ...')
|
26 |
-
return text
|
27 |
|
28 |
def convert_accented_text(text):
|
29 |
result = ""
|
@@ -36,62 +29,73 @@ def convert_accented_text(text):
|
|
36 |
result += unicodedata.normalize('NFC', char)
|
37 |
return result
|
38 |
|
39 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
if convert_accent:
|
41 |
text = convert_accented_text(text)
|
42 |
-
if
|
43 |
text = add_pauses(text)
|
44 |
return text
|
45 |
|
46 |
-
# Функция синтеза
|
47 |
-
def synthesise(text, speed, steps,
|
48 |
if text.strip() == "":
|
49 |
raise gr.Error("You must enter some text")
|
50 |
if len(text) > 50000:
|
51 |
raise gr.Error("Text must be <50k characters")
|
52 |
|
53 |
-
# Применяем обработку в зависимости от флагов чекбоксов
|
54 |
-
text = preprocess_text(text, add_pauses, convert_accent)
|
55 |
-
|
56 |
print("*** saying ***")
|
57 |
print(text)
|
58 |
print("*** end ***")
|
59 |
|
60 |
return 24000, inference(text, progress, speed=speed, alpha=1.0, diffusion_steps=steps, embedding_scale=1.0)[0]
|
61 |
|
62 |
-
#
|
|
|
|
|
|
|
|
|
63 |
if __name__ == "__main__":
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
[
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
i.launch(share=False, server_name="0.0.0.0")
|
|
|
3 |
import unicodedata
|
4 |
import regex
|
5 |
|
|
|
6 |
description = '''
|
7 |
Програма може не коректно визначати деякі наголоси і не перетворює цифри, акроніми і різні скорочення в словесну форму.
|
8 |
Якщо наголос не правильний, використовуйте символ + після наголошеного складу.
|
9 |
Також дуже маленькі речення можуть крешати, тому пишіть щось більше а не одне-два слова.
|
10 |
'''
|
11 |
|
12 |
+
# Дополнительные функции для конвертации текста
|
13 |
def normalize_text(text):
|
14 |
return unicodedata.normalize('NFC', text)
|
15 |
|
16 |
+
def remove_combining_chars(text):
|
17 |
+
decomposed = unicodedata.normalize('NFD', text)
|
18 |
+
filtered = ''.join(c for c in decomposed if unicodedata.category(c) != 'Mn')
|
19 |
+
return unicodedata.normalize('NFC', filtered)
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def convert_accented_text(text):
|
22 |
result = ""
|
|
|
29 |
result += unicodedata.normalize('NFC', char)
|
30 |
return result
|
31 |
|
32 |
+
def add_pauses(text):
|
33 |
+
text = text.replace(':', ':::')
|
34 |
+
text = text.replace(',', ',:::')
|
35 |
+
text = text.replace(';', ';:::')
|
36 |
+
text = text.replace('—', '—:::')
|
37 |
+
text = text.replace('–', '–:::')
|
38 |
+
text = text.replace('.', '. ... ... ')
|
39 |
+
text = text.replace('!', '! ... ...')
|
40 |
+
text = text.replace('?', '? ... ...')
|
41 |
+
return text
|
42 |
+
|
43 |
+
def preprocess_text(text, should_add_pauses, convert_accent):
|
44 |
if convert_accent:
|
45 |
text = convert_accented_text(text)
|
46 |
+
if should_add_pauses:
|
47 |
text = add_pauses(text)
|
48 |
return text
|
49 |
|
50 |
+
# Функция синтеза речи
|
51 |
+
def synthesise(text, speed, steps, progress=gr.Progress()):
|
52 |
if text.strip() == "":
|
53 |
raise gr.Error("You must enter some text")
|
54 |
if len(text) > 50000:
|
55 |
raise gr.Error("Text must be <50k characters")
|
56 |
|
|
|
|
|
|
|
57 |
print("*** saying ***")
|
58 |
print(text)
|
59 |
print("*** end ***")
|
60 |
|
61 |
return 24000, inference(text, progress, speed=speed, alpha=1.0, diffusion_steps=steps, embedding_scale=1.0)[0]
|
62 |
|
63 |
+
# Функция для конвертации текста по кнопке
|
64 |
+
def convert_text(text, should_add_pauses, convert_accent):
|
65 |
+
return preprocess_text(text, should_add_pauses, convert_accent)
|
66 |
+
|
67 |
+
# Основной интерфейс Gradio
|
68 |
if __name__ == "__main__":
|
69 |
+
with gr.Blocks() as demo:
|
70 |
+
gr.Markdown(description)
|
71 |
+
|
72 |
+
text_input = gr.Textbox(label='Text:', lines=5, max_lines=10)
|
73 |
+
speed_slider = gr.Slider(label='Швидкість:', maximum=1.3, minimum=0.7, value=1.0)
|
74 |
+
steps_slider = gr.Slider(label='Кількість кроків дифузії:', minimum=3, maximum=20, step=1, value=3)
|
75 |
+
|
76 |
+
# Чекбоксы для обработки текста
|
77 |
+
add_pauses_checkbox = gr.Checkbox(label="Add pauses")
|
78 |
+
convert_accent_checkbox = gr.Checkbox(label="Convert accented characters")
|
79 |
+
|
80 |
+
# Кнопка для конвертации текста
|
81 |
+
convert_button = gr.Button("Convert Text")
|
82 |
+
convert_output = gr.Textbox(label="Converted Text")
|
83 |
+
|
84 |
+
# Кнопка для синтеза речи
|
85 |
+
synthesize_button = gr.Button("Synthesize Speech")
|
86 |
+
output_audio = gr.Audio(label="Audio", autoplay=False, streaming=False, type="numpy")
|
87 |
+
|
88 |
+
# Связываем кнопки с функциями
|
89 |
+
convert_button.click(
|
90 |
+
fn=convert_text,
|
91 |
+
inputs=[text_input, add_pauses_checkbox, convert_accent_checkbox],
|
92 |
+
outputs=convert_output
|
93 |
+
)
|
94 |
+
|
95 |
+
synthesize_button.click(
|
96 |
+
fn=synthesise,
|
97 |
+
inputs=[convert_output, speed_slider, steps_slider],
|
98 |
+
outputs=output_audio
|
99 |
+
)
|
100 |
+
|
101 |
+
demo.launch(share=True, server_name="0.0.0.0")
|
|