From 7191d28ada0dc6228da4eae625560e02d0bc524f Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 10 Oct 2025 12:11:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=AF=E5=8A=A8=E4=BA=86=20TTS=20?= =?UTF-8?q?=E4=BD=86=E6=9C=AA=E9=85=8D=E7=BD=AE=20TTS=20=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=97=B6=EF=BC=8CAt=20=E5=92=8C=20Reply=20=E5=8F=91=E9=80=81?= =?UTF-8?q?=E4=BA=BA=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes: #2996 --- .../core/pipeline/result_decorate/stage.py | 95 +++++++++---------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index 094d21768..c1f893baf 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -189,54 +189,54 @@ class ResultDecorateStage(Stage): logger.warning( f"会话 {event.unified_msg_origin} 未配置文本转语音模型。" ) - return - new_chain = [] - for comp in result.chain: - if isinstance(comp, Plain) and len(comp.text) > 1: - try: - logger.info(f"TTS 请求: {comp.text}") - audio_path = await tts_provider.get_audio(comp.text) - logger.info(f"TTS 结果: {audio_path}") - if not audio_path: - logger.error( - f"由于 TTS 音频文件未找到,消息段转语音失败: {comp.text}" + else: + new_chain = [] + for comp in result.chain: + if isinstance(comp, Plain) and len(comp.text) > 1: + try: + logger.info(f"TTS 请求: {comp.text}") + audio_path = await tts_provider.get_audio(comp.text) + logger.info(f"TTS 结果: {audio_path}") + if not audio_path: + logger.error( + f"由于 TTS 音频文件未找到,消息段转语音失败: {comp.text}" + ) + new_chain.append(comp) + continue + + use_file_service = self.ctx.astrbot_config[ + "provider_tts_settings" + ]["use_file_service"] + callback_api_base = self.ctx.astrbot_config[ + "callback_api_base" + ] + dual_output = self.ctx.astrbot_config[ + "provider_tts_settings" + ]["dual_output"] + + url = None + if use_file_service and callback_api_base: + token = await file_token_service.register_file( + audio_path + ) + url = f"{callback_api_base}/api/file/{token}" + logger.debug(f"已注册:{url}") + + new_chain.append( + Record( + file=url or audio_path, + url=url or audio_path, + ) ) + if dual_output: + new_chain.append(comp) + except Exception: + logger.error(traceback.format_exc()) + logger.error("TTS 失败,使用文本发送。") new_chain.append(comp) - continue - - use_file_service = self.ctx.astrbot_config[ - "provider_tts_settings" - ]["use_file_service"] - callback_api_base = self.ctx.astrbot_config[ - "callback_api_base" - ] - dual_output = self.ctx.astrbot_config[ - "provider_tts_settings" - ]["dual_output"] - - url = None - if use_file_service and callback_api_base: - token = await file_token_service.register_file( - audio_path - ) - url = f"{callback_api_base}/api/file/{token}" - logger.debug(f"已注册:{url}") - - new_chain.append( - Record( - file=url or audio_path, - url=url or audio_path, - ) - ) - if dual_output: - new_chain.append(comp) - except Exception: - logger.error(traceback.format_exc()) - logger.error("TTS 失败,使用文本发送。") + else: new_chain.append(comp) - else: - new_chain.append(comp) - result.chain = new_chain + result.chain = new_chain # 文本转图片 elif ( @@ -279,7 +279,6 @@ class ResultDecorateStage(Stage): result.chain = [Image.fromFileSystem(url)] # 触发转发消息 - has_forwarded = False if event.get_platform_name() == "aiocqhttp": word_cnt = 0 for comp in result.chain: @@ -290,9 +289,9 @@ class ResultDecorateStage(Stage): uin=event.get_self_id(), name="AstrBot", content=[*result.chain] ) result.chain = [node] - has_forwarded = True - if not has_forwarded: + has_plain = any(isinstance(item, Plain) for item in result.chain) + if has_plain: # at 回复 if ( self.reply_with_mention