Skip to content

Commit

Permalink
Merge pull request #877 from yanyuxiyangzk/main
Browse files Browse the repository at this point in the history
对接metahuman
  • Loading branch information
Ikaros-521 authored Jun 13, 2024
2 parents 43bf63a + 27c0ea3 commit af80aa0
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"EasyAIVtuber": {
"api_ip_port": "http://127.0.0.1:7888"
},
"metahuman": {
"api_ip_port": "http://127.0.0.1:8000"
},
"musetalk": {
"api_ip_port": "http://127.0.0.1:8000"
},
"digital_human_video_player": {
"type": "easy_wav2lip",
"api_ip_port": "http://127.0.0.1:8091"
Expand Down Expand Up @@ -1776,6 +1782,8 @@
"visual_body": {
"live2d": true,
"xuniren": true,
"metahuman": true,
"musetalk": true,
"unity": true,
"EasyAIVtuber": true,
"digital_human_video_player": true
Expand Down
60 changes: 57 additions & 3 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,32 @@ async def EasyAIVtuber_api(self, audio_path=""):
logging.error(traceback.format_exc())
return False

# 调用metahuman的api
async def metahuman_api(self, message=""):
try:
print(message)
url = "http://127.0.0.1:8000/human"
# url = urljoin(self.config.get('metahuman', 'api_ip_port'), "/human")
data = {
"type": 'echo',
"text": message
}
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"metahuman发送成功,返回:{json_response['status']}")
logging.info("metahuman发送成功")
return True
# else:
# logging.error(f"metahuman发送失败,状态码:{response.status}")
# return False

except Exception as e:
logging.error(traceback.format_exc())
return False

# 调用digital_human_video_player的api
async def digital_human_video_player_api(self, audio_path=""):
Expand Down Expand Up @@ -752,10 +777,38 @@ async def tts_handle(self, message):
Returns:
dict: json数据,含tts配置,tts类型,合成结果等信息
"""
# 区分TTS类型

try:
logging.debug(f"message={message}")
logging.debug(message)

# 特殊配置下特殊处理
if self.config.get("visual_body") == "metahuman" or self.config.get("visual_body") == "musetalk":
# 如果是tts类型为none,暂时这类为直接播放音频,所以就丢给路径队列
if message["tts_type"] == "none":
Audio.voice_tmp_path_queue.put(message)
return None

logging.debug(f"合成音频前的原始数据:{message['content']}")
message["content"] = self.common.remove_extra_words(message["content"], message["config"]["max_len"], message["config"]["max_char_len"])
# logging.info("裁剪后的合成文本:" + text)

message["content"] = message["content"].replace('\n', '。')

await self.metahuman_api(message['content'])

# 如果是tts类型为none,暂时这类为直接播放音频,所以就丢给路径队列
if message["tts_type"] == "tts_close":
logging.info(f"------------关闭tts声音,使用数字人声音播放-----------------------")
#打开ws链接数字人
return None
# 空数据就散了吧
if message["content"] == "":
return None
except Exception as e:
logging.error(traceback.format_exc())
return None

try:
if message["tts_type"] == "vits":
# 语言检测
language = self.common.lang_check(message["content"])
Expand Down Expand Up @@ -1029,7 +1082,8 @@ async def tts_handle(self, message):

voice_tmp_path = await self.my_tts.chattts_api(data)
elif message["tts_type"] == "none":
voice_tmp_path = None
Audio.voice_tmp_path_queue.put(message)
return None

message["result"] = {
"code": 200,
Expand Down
34 changes: 33 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,12 @@ def common_textarea_handle(content):
if config.get("webui", "show_card", "visual_body", "xuniren"):
config_data["xuniren"]["api_ip_port"] = input_xuniren_api_ip_port.value

if config.get("webui", "show_card", "visual_body", "metahuman"):
config_data["metahuman"]["api_ip_port"] = input_metahuman_api_ip_port.value

if config.get("webui", "show_card", "visual_body", "musetalk"):
config_data["musetalk"]["api_ip_port"] = input_musetalk_api_ip_port.value

if config.get("webui", "show_card", "visual_body", "unity"):
# config_data["unity"]["enable"] = switch_unity_enable.value
config_data["unity"]["api_ip_port"] = input_unity_api_ip_port.value
Expand Down Expand Up @@ -2804,7 +2810,7 @@ def save_config():

select_visual_body = ui.select(
label='虚拟身体',
options={'xuniren': 'xuniren', 'unity': 'unity', 'EasyAIVtuber': 'EasyAIVtuber', 'digital_human_video_player': '数字人视频播放器', '其他': '其他'},
options={'xuniren': 'xuniren','metahuman': 'metahuman','musetalk': 'musetalk', 'unity': 'unity', 'EasyAIVtuber': 'EasyAIVtuber', 'digital_human_video_player': '数字人视频播放器', '其他': '其他'},
value=config.get("visual_body")
).style("width:200px;").tooltip('选用的虚拟身体类型。如果使用VTS对接,就选其他,用什么展示身体就选什么,大部分对接的选项需要单独启动对应的服务端程序,请勿随便选择。')

Expand Down Expand Up @@ -5087,6 +5093,30 @@ async def fish_speech_load_model(data):
options=data_json,
value=config.get("live2d", "name")
).style("width:150px")
if config.get("webui", "show_card", "visual_body", "metahuman"):
with ui.card().style(card_css):
ui.label("metahuman")
with ui.row():
input_metahuman_api_ip_port = ui.input(
label='API地址',
value=config.get("metahuman", "api_ip_port"),
placeholder='metahuman应用启动API后,监听的ip和端口',
validation={
'请输入正确格式的URL': lambda value: common.is_url_check(value),
}
)
if config.get("webui", "show_card", "visual_body", "musetalk"):
with ui.card().style(card_css):
ui.label("musetalk")
with ui.row():
input_musetalk_api_ip_port = ui.input(
label='API地址',
value=config.get("musetalk", "api_ip_port"),
placeholder='musetalk应用启动API后,监听的ip和端口',
validation={
'请输入正确格式的URL': lambda value: common.is_url_check(value),
}
)
if config.get("webui", "show_card", "visual_body", "xuniren"):
with ui.card().style(card_css):
ui.label("xuniren")
Expand Down Expand Up @@ -5946,6 +5976,8 @@ def update_echart_gift():
with ui.row():
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_metahuman = ui.switch('metahuman', value=config.get("webui", "show_card", "visual_body", "metahuman")).style(switch_internal_css)
switch_webui_show_card_visual_body_musetalk = ui.switch('musetalk', value=config.get("webui", "show_card", "visual_body", "musetalk")).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)
switch_webui_show_card_visual_body_digital_human_video_player = ui.switch('digital_human_video_player', value=config.get("webui", "show_card", "visual_body", "digital_human_video_player")).style(switch_internal_css)
Expand Down

0 comments on commit af80aa0

Please sign in to comment.