File size: 21,286 Bytes
446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 6cce716 446c342 |
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
import os
import gradio as gr
from TTSs import elevenlabs_tts
from TTSs import genshin_api_tts
from TTSs import openai_tts
from TTSs import reecho_ai
from TTSs import volcengine
try:
import load_env
print('已加载环境变量')
except ImportError:
print('未找到环境变量文件,将使用现有环境变量')
using_local = True if os.environ.get('USING_LOCAL', 'false').lower() == 'true' else False
with gr.Blocks() as TTS_merge:
def change_config_page(select_bar):
# 列出所有需要修改的组件,给出字典形式的默认值
if using_local:
available_configs = {
config_eleven: gr.Group(visible=False),
config_openai: gr.Group(visible=False),
config_genshin_api: gr.Group(visible=False),
config_genshin_local: gr.Group(visible=False),
config_reecho_ai: gr.Group(visible=False),
config_volcengine: gr.Group(visible=False),
btn_eleven: gr.Button("一键合成", variant="primary", visible=False),
btn_openai: gr.Button("一键合成", variant="primary", visible=False),
btn_genshin_api: gr.Button("一键合成", variant="primary", visible=False),
btn_recho_ai: gr.Button("一键合成", variant="primary", visible=False),
btn_volcengine: gr.Button("一键合成", variant="primary", visible=False),
btn_genshin_local: gr.Button("一键合成", variant="primary", visible=False),
}
else:
available_configs = {
config_eleven: gr.Group(visible=False),
config_openai: gr.Group(visible=False),
config_genshin_api: gr.Group(visible=False),
config_reecho_ai: gr.Group(visible=False),
config_volcengine: gr.Group(visible=False),
btn_eleven: gr.Button("一键合成", variant="primary", visible=False),
btn_openai: gr.Button("一键合成", variant="primary", visible=False),
btn_recho_ai: gr.Button("一键合成", variant="primary", visible=False),
btn_volcengine: gr.Button("一键合成", variant="primary", visible=False),
btn_genshin_api: gr.Button("一键合成", variant="primary", visible=False),
}
# 根据选择的值,返回对应的字典
if select_bar == 'elevenlabs':
available_configs[config_eleven] = gr.Group(visible=True)
available_configs[btn_eleven] = gr.Button("一键合成", variant="primary", visible=True)
elif select_bar == 'openai':
available_configs[config_openai] = gr.Group(visible=True)
available_configs[btn_openai] = gr.Button("一键合成", variant="primary", visible=True)
elif select_bar == 'genshin-api':
available_configs[config_genshin_api] = gr.Group(visible=True)
available_configs[btn_genshin_api] = gr.Button("一键合成", variant="primary", visible=True)
elif select_bar == 'genshin-local':
available_configs[config_genshin_local] = gr.Group(visible=True)
available_configs[btn_genshin_local] = gr.Button("一键合成", variant="primary", visible=True)
elif select_bar == 'reecho-ai':
available_configs[config_reecho_ai] = gr.Group(visible=True)
available_configs[btn_recho_ai] = gr.Button("一键合成", variant="primary", visible=True)
elif select_bar == 'volcengine':
available_configs[config_volcengine] = gr.Group(visible=True)
available_configs[btn_volcengine] = gr.Button("一键合成", variant="primary", visible=True)
else:
raise Exception('select error')
return available_configs
with gr.Row():
with gr.Column():
if using_local:
select = ['elevenlabs', 'openai', 'genshin-api', 'reecho-ai', 'volcengine', 'genshin-local']
else:
select = ['elevenlabs', 'openai', 'genshin-api', 'reecho-ai', 'volcengine']
with gr.Group():
select_bar = gr.Dropdown(choices=select, label="选择测试接口", value=select[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:
with gr.Group(visible=True) as config_eleven:
with gr.Row():
elevenlabs_api_key = gr.Textbox(label="elevenlabs的API Key(默认为环境变量值)",
placeholder="请输入elevenlabs的API Key",
type="password",
interactive=True,
value=os.environ.get('ELEVENLABS_API_KEY', ''))
speaker_eleven = gr.Dropdown(choices=elevenlabs_tts.select_key,
value=elevenlabs_tts.select_key[0], label="音色选择",
interactive=True)
with gr.Blocks():
with gr.Row():
stability = gr.Slider(minimum=0, maximum=1, value=0.5, label='stability', interactive=True)
similarity_boost = gr.Slider(minimum=0, maximum=1, value=0.75, label='similarity_boost',
interactive=True)
with gr.Row():
style = gr.Slider(minimum=0, maximum=1, value=0, label='style', interactive=True)
use_speaker_boost = gr.Checkbox(label="Use Speaker Boost", value=True, interactive=True)
with gr.Group(visible=False) as config_openai:
openai_api_key = gr.Textbox(label="openai的API Key(默认为环境变量值)",
placeholder="请输入openai的API Key",
type="password",
interactive=True,
value=os.environ.get('OPENAI_API_KEY', ''))
with gr.Row():
openai_model_choices = ['tts-1', 'tts-1-hd']
openai_voices = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']
openai_model = gr.Dropdown(choices=openai_model_choices, value=openai_model_choices[0],
label="模型选择",
interactive=True)
openai_speaker = gr.Dropdown(choices=openai_voices, value=openai_voices[0], label="音色选择",
interactive=True)
with gr.Group(visible=False) as config_genshin_api:
gr.Markdown('原作者:https://modelscope.cn/studios/erythrocyte/Bert-VITS2_Genshin_TTS/summary')
with gr.Row():
token = gr.Textbox(label="AccessToken", placeholder="请输入AccessToken",
type="password",
interactive=True, value=os.environ.get('GENSHIN_API_KEY', ''))
appid = gr.Textbox(label="AppID", placeholder="请输入AppID", interactive=True,
value='ig8t76x6036h3hpw')
with gr.Row():
gr.Markdown(
"AppID不要改,AccessToken最好换自己的。")
with gr.Row():
speaker = gr.Dropdown(choices=genshin_api_tts.speakers_genshin,
value=genshin_api_tts.speakers_genshin[0], label="角色",
interactive=True)
search = gr.Textbox(label="搜索角色", lines=1, interactive=True)
btn2 = gr.Button(value="搜索")
with gr.Column():
with gr.Row():
sdp_ratio = gr.Slider(minimum=0, maximum=1, value=0.2, step=0.1, label="SDP/DP 混合比",
interactive=True)
noise_scale = gr.Slider(minimum=0.1, maximum=2, value=0.6, step=0.1, label="感情",
interactive=True)
with gr.Row():
noise_scale_w = gr.Slider(minimum=0.1, maximum=2, value=0.8, step=0.1, label="音素长度",
interactive=True)
length_scale = gr.Slider(minimum=-99, maximum=99, value=0, step=0.1, label="语速(%)",
interactive=True)
btn2.click(genshin_api_tts.search_speaker, inputs=[search], outputs=[speaker])
with gr.Group(visible=False) as config_reecho_ai:
gr.Markdown('控制台在此:https://dash.reecho.ai/')
with gr.Row():
reecho_api_key = gr.Textbox(label="reecho的API Key(默认为环境变量值)",
placeholder="请输入reecho的API Key",
type="password",
interactive=True,
value=os.environ.get('REECHO_API_KEY', ''),
scale=3)
btn_refush = gr.Button(value="刷新角色列表")
with gr.Row():
randomness = gr.Slider(minimum=0, maximum=100, value=97, step=1, label="多样性",
interactive=True)
stability_boost = gr.Slider(minimum=0, maximum=100, value=0, step=1, label="稳定性过度",
interactive=True)
reecho_ai.refresh_roles(reecho_api_key.value)
role = gr.Dropdown(choices=reecho_ai.available_roles.keys(),
value=list(reecho_ai.available_roles.keys())[0],
label="角色", interactive=True)
example_audio = gr.Audio(label="该角色示例音频", interactive=False,
value=reecho_ai.get_example_audio(role.value))
role.change(reecho_ai.get_example_audio,
inputs=[role], outputs=[example_audio])
btn_refush.click(lambda x: (reecho_ai.refresh_roles(x),
gr.Dropdown(choices=reecho_ai.available_roles.keys(),
value=list(reecho_ai.available_roles.keys())[0],
label="角色", interactive=True)
)[-1],
inputs=[reecho_api_key],
outputs=[role])
with gr.Group(visible=False) as config_volcengine:
voices = list(volcengine.useful_voice.keys())
with gr.Row():
volcengine_appid = gr.Textbox(label="volcengine的appid(默认为环境变量值)",
placeholder="请输入volcengine的appid",
type="password",
interactive=True,
value=os.environ.get('VOLCENGINE_APPID', ''))
volcengine_access_token = gr.Textbox(label="volcengine的access_token(默认为环境变量值)",
placeholder="请输入volengine的access_token",
type="password",
interactive=True,
value=os.environ.get('VOLCENGINE_ACCESS_TOKEN', ''))
voice_type = gr.Dropdown(choices=voices, value=voices[0], label="音色选择", interactive=True)
with gr.Row():
speed_ratio = gr.Slider(minimum=0.2, maximum=3, value=1, step=0.1, label="语速",
interactive=True)
volume_ratio = gr.Slider(minimum=0.1, maximum=3, value=1, step=0.1, label="音量",
interactive=True)
pitch_ratio = gr.Slider(minimum=0.1, maximum=3, value=1, step=0.1, label="音高",
interactive=True)
with gr.Row():
emotion = gr.Textbox(label="情感/风格(还未适配)", placeholder="请输入情感", interactive=True)
language = gr.Textbox(label="语言类型(还未适配)", placeholder="请输入语言", interactive=True)
if using_local:
with gr.Group(visible=False) as config_genshin_local:
from TTSs.genshin_bg import speakers as speakers_genshin_local
from TTSs.genshin_bg import languages
from TTSs import genshin_local_tts
def search_speaker(search_value):
for s in speakers_genshin_local:
if search_value == s:
return s
for s in speakers_genshin_local:
if search_value in s:
return s
gr.Markdown('原作者:红血球AE3803\nhttps://space.bilibili.com/6589795/dynamic')
with gr.Row():
speaker_local = gr.Dropdown(choices=speakers_genshin_local, value=speakers_genshin_local[0],
label="角色",
interactive=True)
search_local = gr.Textbox(label="搜索角色", lines=1, interactive=True)
btn2 = gr.Button(value="搜索")
with gr.Column():
with gr.Row():
sdp_ratio_local = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1,
label="SDP Ratio",
interactive=True)
noise_scale_local = gr.Slider(minimum=0.1, maximum=2, value=0.6, step=0.1,
label="Noise",
interactive=True)
with gr.Row():
noise_scale_w_local = gr.Slider(minimum=0.1, maximum=2, value=0.9, step=0.1,
label="Noise_W",
interactive=True)
length_scale_local = gr.Slider(minimum=0.1, maximum=2, value=1.0, step=0.1,
label="Length",
interactive=True)
language_local = gr.Dropdown(
choices=languages, value=languages[0], label="Language", interactive=True
)
btn2.click(search_speaker, inputs=[search], outputs=[speaker])
btn_eleven = gr.Button("一键合成", variant="primary", visible=True)
btn_openai = gr.Button("一键合成", variant="primary", visible=False)
btn_genshin_api = gr.Button("一键合成", variant="primary", visible=False)
btn_recho_ai = gr.Button("一键合成", variant="primary", visible=False)
btn_volcengine = gr.Button("一键合成", variant="primary", visible=True)
if using_local:
btn_genshin_local = gr.Button("一键合成", variant="primary", visible=False)
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)
if using_local:
select_bar.change(change_config_page, inputs=[select_bar],
outputs=[config_eleven, config_openai, config_genshin_api, config_reecho_ai,
config_genshin_local, btn_eleven,
btn_openai, btn_genshin_api, btn_recho_ai, btn_genshin_local, btn_volcengine, config_volcengine])
else:
select_bar.change(change_config_page, inputs=[select_bar],
outputs=[config_eleven, config_openai, config_genshin_api, config_reecho_ai, btn_eleven,
btn_openai,
btn_recho_ai, btn_genshin_api, btn_volcengine, config_volcengine])
btn_eleven.click(elevenlabs_tts.merge_audio,
inputs=[elevenlabs_api_key, text, audio, speaker_eleven, stability,
similarity_boost, style,
use_speaker_boost, speaker_up, back_up],
outputs=[text_output, ori_audio_output, mix_audio_output])
btn_openai.click(openai_tts.tts,
inputs=[openai_api_key, text, openai_model, openai_speaker, audio, speaker_up, back_up],
outputs=[text_output, ori_audio_output, mix_audio_output])
btn_genshin_api.click(genshin_api_tts.infer,
inputs=[token, appid, speaker, text, sdp_ratio, noise_scale, noise_scale_w,
length_scale, audio,
speaker_up, back_up],
outputs=[text_output, ori_audio_output, mix_audio_output])
btn_recho_ai.click(reecho_ai.get_reecho_ai_result,
inputs=[reecho_api_key, text, role, randomness, stability_boost,
audio, speaker_up, back_up],
outputs=[text_output, ori_audio_output, mix_audio_output])
btn_volcengine.click(volcengine.tts,
inputs=[text, volcengine_appid, volcengine_access_token, voice_type, speed_ratio,
volume_ratio, pitch_ratio, audio, speaker_up, back_up],
outputs=[text_output, ori_audio_output, mix_audio_output])
if using_local:
btn_genshin_local.click(genshin_local_tts.func_genshin,
inputs=[
text,
speaker_local,
sdp_ratio_local,
noise_scale_local,
noise_scale_w_local,
length_scale_local,
language_local,
audio,
speaker_up,
back_up
],
outputs=[text_output, ori_audio_output, mix_audio_output]
)
if __name__ == "__main__":
if using_local:
from TTSs.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()
|