diff --git a/main.py b/main.py index 58f70b99..7cb234c8 100644 --- a/main.py +++ b/main.py @@ -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()) @@ -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": diff --git a/webui.py b/webui.py index 3e1e4dc3..6758d882 100644 --- a/webui.py +++ b/webui.py @@ -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(