From 801497e2e401b3f1867eaf9919f306c5e775b9c3 Mon Sep 17 00:00:00 2001 From: ikaros <327209194@qq.com> Date: Thu, 29 Feb 2024 14:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5EasyAIVtuber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 6 +++++- config.json.bak | 6 +++++- utils/audio.py | 31 +++++++++++++++++++++++++++++++ webui.py | 14 +++++++++++++- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index ad9903fc..716228a4 100644 --- a/config.json +++ b/config.json @@ -25,6 +25,9 @@ "api_ip_port": "http://127.0.0.1:5700/add", "password": "中文的密码,怕了吧!" }, + "EasyAIVtuber": { + "api_ip_port": "http://127.0.0.1:7888" + }, "play_audio": { "enable": true, "text_split_enable": true, @@ -1318,7 +1321,8 @@ "visual_body": { "live2d": true, "xuniren": true, - "unity": true + "unity": true, + "EasyAIVtuber": true } } } diff --git a/config.json.bak b/config.json.bak index ad9903fc..716228a4 100644 --- a/config.json.bak +++ b/config.json.bak @@ -25,6 +25,9 @@ "api_ip_port": "http://127.0.0.1:5700/add", "password": "中文的密码,怕了吧!" }, + "EasyAIVtuber": { + "api_ip_port": "http://127.0.0.1:7888" + }, "play_audio": { "enable": true, "text_split_enable": true, @@ -1318,7 +1321,8 @@ "visual_body": { "live2d": true, "xuniren": true, - "unity": true + "unity": true, + "EasyAIVtuber": true } } } diff --git a/utils/audio.py b/utils/audio.py index af7beffe..8d78c415 100644 --- a/utils/audio.py +++ b/utils/audio.py @@ -310,6 +310,35 @@ async def xuniren_api(self, audio_path=""): logging.error(traceback.format_exc()) return False + # 调用EasyAIVtuber的api + async def EasyAIVtuber_api(self, audio_path=""): + try: + from urllib.parse import urljoin + + url = urljoin(self.config.get('EasyAIVtuber', 'api_ip_port'), "/alive") + + data = { + "type": "speak", # 说话动作 + "speech_path": os.path.abspath(audio_path) + } + + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + # 检查响应状态 + if response.status == 200: + # 使用await等待异步获取JSON响应 + json_response = await response.json() + logging.info(f"EasyAIVtuber发送成功,返回:{json_response['status']}") + + return True + else: + logging.error(f"EasyAIVtuber发送失败,状态码:{response.status}") + return False + + except Exception as e: + logging.error(traceback.format_exc()) + return False + # 音频合成(edge-tts / vits_fast)并播放 def audio_synthesis(self, message): @@ -933,6 +962,8 @@ async def only_play_audio(self): # 根据接入的虚拟身体类型执行不同逻辑 if self.config.get("visual_body") == "xuniren": await self.xuniren_api(voice_tmp_path) + elif self.config.get("visual_body") == "EasyAIVtuber": + await self.EasyAIVtuber_api(voice_tmp_path) else: if self.config.get("play_audio", "player") in ["audio_player", "audio_player_v2"]: if "insert_index" in data_json: diff --git a/webui.py b/webui.py index d78940e2..69cc3114 100644 --- a/webui.py +++ b/webui.py @@ -1407,6 +1407,9 @@ def common_textarea_handle(content): # config_data["unity"]["enable"] = switch_unity_enable.value config_data["unity"]["api_ip_port"] = input_unity_api_ip_port.value config_data["unity"]["password"] = input_unity_password.value + + if config.get("webui", "show_card", "visual_body", "EasyAIVtuber"): + config_data["EasyAIVtuber"]["api_ip_port"] = input_EasyAIVtuber_api_ip_port.value """ 文案 @@ -1649,6 +1652,7 @@ def common_textarea_handle(content): config_data["webui"]["show_card"]["visual_body"]["live2d"] = switch_webui_show_card_visual_body_live2d.value config_data["webui"]["show_card"]["visual_body"]["xuniren"] = switch_webui_show_card_visual_body_xuniren.value config_data["webui"]["show_card"]["visual_body"]["unity"] = switch_webui_show_card_visual_body_unity.value + config_data["webui"]["show_card"]["visual_body"]["EasyAIVtuber"] = switch_webui_show_card_visual_body_EasyAIVtuber.value config_data["webui"]["theme"]["choose"] = select_webui_theme_choose.value @@ -1801,7 +1805,7 @@ def common_textarea_handle(content): value=config.get("chat_type") ).style("width:200px;") - select_visual_body = ui.select(label='虚拟身体', options={'xuniren': 'xuniren', 'unity': 'unity', '其他': '其他'}, value=config.get("visual_body")).style("width:200px;") + select_visual_body = ui.select(label='虚拟身体', options={'xuniren': 'xuniren', 'unity': 'unity', 'EasyAIVtuber': 'EasyAIVtuber', '其他': '其他'}, value=config.get("visual_body")).style("width:200px;") select_audio_synthesis_type = ui.select( label='语音合成', @@ -3218,6 +3222,13 @@ def clear_tts_common_audio_card(file_path): # switch_unity_enable = ui.switch('启用', value=config.get("unity", "enable")).style(switch_internal_css) input_unity_api_ip_port = ui.input(label='API地址', value=config.get("unity", "api_ip_port"), placeholder='对接Unity应用使用的HTTP中转站监听的ip和端口') input_unity_password = ui.input(label='密码', value=config.get("unity", "password"), placeholder='对接Unity应用使用的HTTP中转站的密码') + + if config.get("webui", "show_card", "visual_body", "EasyAIVtuber"): + with ui.card().style(card_css): + ui.label("EasyAIVtuber") + with ui.row(): + input_EasyAIVtuber_api_ip_port = ui.input(label='API地址', value=config.get("EasyAIVtuber", "api_ip_port"), placeholder='对接EasyAIVtuber应用监听的ip和端口') + with ui.tab_panel(copywriting_page).style(tab_panel_css): with ui.row(): @@ -3745,6 +3756,7 @@ def update_echart_gift(): switch_webui_show_card_visual_body_live2d = ui.switch('Live2D', value=config.get("webui", "show_card", "visual_body", "live2d")).style(switch_internal_css) switch_webui_show_card_visual_body_xuniren = ui.switch('xuniren', value=config.get("webui", "show_card", "visual_body", "xuniren")).style(switch_internal_css) switch_webui_show_card_visual_body_unity = ui.switch('unity', value=config.get("webui", "show_card", "visual_body", "unity")).style(switch_internal_css) + switch_webui_show_card_visual_body_EasyAIVtuber = ui.switch('EasyAIVtuber', value=config.get("webui", "show_card", "visual_body", "EasyAIVtuber")).style(switch_internal_css)