Skip to content

Commit

Permalink
Merge pull request #667 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
对接EasyAIVtuber
  • Loading branch information
Ikaros-521 committed Feb 29, 2024
2 parents 276e84d + 801497e commit e87eda7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
6 changes: 5 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1318,7 +1321,8 @@
"visual_body": {
"live2d": true,
"xuniren": true,
"unity": true
"unity": true,
"EasyAIVtuber": true
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1318,7 +1321,8 @@
"visual_body": {
"live2d": true,
"xuniren": true,
"unity": true
"unity": true,
"EasyAIVtuber": true
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
文案
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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='语音合成',
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)



Expand Down

0 comments on commit e87eda7

Please sign in to comment.