Skip to content

Commit

Permalink
特殊处理:针对LiveTalking(metahuman-stream)新的是否播放中的接口,定时获取播放情况,修改本地的待播放音频数为1…
Browse files Browse the repository at this point in the history
…或0,来配合闲时任务使用
  • Loading branch information
Ikaros-521 committed Nov 1, 2024
1 parent 9888683 commit 6285075
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
87 changes: 69 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,25 +1499,41 @@ def do_task(
local_audio_path_list,
)
elif config.get("idle_time_task", "type") == "待播放音频队列更新闲时":
if my_handle.is_queue_less_or_greater_than(
type="voice_tmp_path_queue",
less=int(
config.get(
"idle_time_task", "min_audio_queue_len_to_trigger"
logger.debug(f"待播放音频数:{wait_play_audio_num}")
# 特殊处理:metahuman_stream平台,判断wait_play_audio_num
if config.get("visual_body") == "metahuman_stream":
if wait_play_audio_num < config.get("idle_time_task", "min_audio_queue_len_to_trigger"):
(
last_mode,
copywriting_copy_list,
comment_copy_list,
local_audio_path_list,
) = do_task(
last_mode,
copywriting_copy_list,
comment_copy_list,
local_audio_path_list,
)
else:
if my_handle.is_queue_less_or_greater_than(
type="voice_tmp_path_queue",
less=int(
config.get(
"idle_time_task", "min_audio_queue_len_to_trigger"
)
),
):
(
last_mode,
copywriting_copy_list,
comment_copy_list,
local_audio_path_list,
) = do_task(
last_mode,
copywriting_copy_list,
comment_copy_list,
local_audio_path_list,
)
),
):
(
last_mode,
copywriting_copy_list,
comment_copy_list,
local_audio_path_list,
) = do_task(
last_mode,
copywriting_copy_list,
comment_copy_list,
local_audio_path_list,
)

except Exception as e:
logger.error(traceback.format_exc())
Expand Down Expand Up @@ -1593,6 +1609,41 @@ def run_image_recognition_schedule(interval: int, type: str):
)
image_recognition_cam_schedule_thread.start()

# 针对对接LiveTalking(metahuman-stream)特殊处理
if config.get("visual_body") == "metahuman_stream":
# 创建线程定时请求LiveTalking的is_speaking接口,判断是否有音频在播放
def run_metahuman_stream_is_speaking_schedule():
global wait_play_audio_num

try:
from urllib.parse import urljoin
url = urljoin(
config.get("metahuman_stream", "api_ip_port"), "is_speaking"
)
resp_json = common.send_request(url, 'POST', {"sessionid": 0})
if resp_json and resp_json["code"] == 0:
if resp_json["data"]:
logger.debug("LiveTalking有音频在播放")
wait_play_audio_num = 1
else:
logger.debug("LiveTalking没有音频在播放")
wait_play_audio_num = 0

except Exception as e:
logger.error(traceback.format_exc())
logger.error("请求LiveTalking is_speaking接口失败")

interval = 3
try:
schedule.every(interval).seconds.do(
partial(run_metahuman_stream_is_speaking_schedule)
)
except Exception as e:
logger.error(traceback.format_exc())

while True:
schedule.run_pending()

logger.info(f"当前平台:{platform}")

if platform == "bilibili":
Expand Down
8 changes: 4 additions & 4 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3924,13 +3924,13 @@ def local_qa_text_json_file_reload():
input_idle_time_task_idle_min_msg_queue_len_to_trigger = ui.input(
label='待合成消息队列个数小于此值时触发',
value=config.get("idle_time_task", "min_msg_queue_len_to_trigger"),
placeholder='最小闲时间隔时间(正整数,单位:秒),就是在没有弹幕情况下经过的时间'
).style("width:250px;").tooltip('最小闲时间隔时间(正整数,单位:秒),就是在没有弹幕情况下经过的时间')
placeholder='待合成消息队列个数小于此值时,才会触发闲时任务'
).style("width:250px;").tooltip('待合成消息队列个数小于此值时,才会触发闲时任务')
input_idle_time_task_idle_min_audio_queue_len_to_trigger = ui.input(
label='待播放音频队列个数小于此值时触发',
value=config.get("idle_time_task", "min_audio_queue_len_to_trigger"),
placeholder='最小闲时间隔时间(正整数,单位:秒),就是在没有弹幕情况下经过的时间'
).style("width:250px;").tooltip('最小闲时间隔时间(正整数,单位:秒),就是在没有弹幕情况下经过的时间')
placeholder='待播放音频队列个数小于此值时,才会触发闲时任务'
).style("width:250px;").tooltip('待播放音频队列个数小于此值时,才会触发闲时任务')

with ui.row():
input_idle_time_task_idle_time_min = ui.input(
Expand Down

0 comments on commit 6285075

Please sign in to comment.