File size: 3,054 Bytes
454c9e4
 
 
 
 
 
 
 
 
 
 
 
 
 
0d4f556
454c9e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
try:
    import load_env

    print('已加载环境变量')
except ImportError:
    print('未找到环境变量文件,将使用现有环境变量')

import os

import gradio as gr

from tts_config import load_TTS

load_TTS = [i for i in load_TTS if i.is_show()]
load_TTS[0].default_show = True

TTS_dict = {}
for i in load_TTS:
    TTS_dict[i.get_name()] = i


def change_config_page(select_bar):
    change_map = {}

    for i in TTS_dict.keys():
        if select_bar == i:
            change_map[TTS_dict[i].config] = gr.Group(visible=True)
            change_map[TTS_dict[i].btn] = gr.Button(visible=True)
        else:
            change_map[TTS_dict[i].config] = gr.Group(visible=False)
            change_map[TTS_dict[i].btn] = gr.Button(visible=False)

    return change_map


with gr.Blocks() as TTS_merge:
    with gr.Row():
        with gr.Column():
            with gr.Group():
                select_bar = gr.Dropdown(choices=list(TTS_dict.keys()), label="选择测试接口",
                                         value=list(TTS_dict.keys())[0], interactive=True)
                audio = gr.Audio(label="背景音乐", interactive=True)
                with gr.Row():
                    speaker_up = gr.Slider(minimum=-20, maximum=20, value=0, label='TTS语音增益(db)', interactive=True)
                    back_up = gr.Slider(minimum=-20, maximum=20, value=0, label='BGM增益(db)', interactive=True)

            text = gr.TextArea(label="要合成的内容", placeholder="内容",
                               value="旅行者和开拓者们,大家好呀!欢迎各位试用原神和星穹铁道在线语音合成!",
                               lines=3, interactive=True)

            with gr.Accordion("配置页面") as config_page:
                for i in load_TTS:
                    i.get_config_page()

            # get submit
            for i in load_TTS:
                i.get_submit_button()

        with gr.Column():
            ori_audio_output = gr.Audio(label="TTS引擎输出", interactive=False)
            mix_audio_output = gr.Audio(label="TTS混合背景音乐后的输出", interactive=False)
            text_output = gr.Textbox(label="日志", lines=5, max_lines=100)

    # create event
    select_bar.change(change_config_page, inputs=[select_bar],
                      outputs=[i.config for i in load_TTS] + [i.btn for i in load_TTS])
    for i in load_TTS:
        i.create_interface_event(text, audio, speaker_up, back_up, text_output, ori_audio_output, mix_audio_output)

if __name__ == "__main__":
    using_local = True if os.environ.get('USING_LOCAL', 'false').lower() == 'true' else False
    if using_local:
        from TTSs.genshin_local.genshin_bg import get_advanced_block

        iface = gr.TabbedInterface([TTS_merge, get_advanced_block()],
                                   ["TTS all in one", "原神本地推理-高级版"])
    else:
        iface = gr.TabbedInterface([TTS_merge],
                                   ["TTS all in one"])

    iface.launch()