From e6ef9d1b0883d7c8d730431da0577fbfd0527de0 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 28 Sep 2025 10:43:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D"=E5=BC=80=E5=90=AF=20?= =?UTF-8?q?TTS=20=E6=97=B6=E5=90=8C=E6=97=B6=E8=BE=93=E5=87=BA=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E5=92=8C=E6=96=87=E5=AD=97=E5=86=85=E5=AE=B9"?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=B8=8D=E5=8F=AF=E7=94=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes: #2844 --- astrbot/core/config/default.py | 16 +++++++------ .../core/pipeline/preprocess_stage/stage.py | 3 +++ .../core/pipeline/result_decorate/stage.py | 6 ++++- packages/astrbot/main.py | 24 +++++++++++++------ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 26eab94f9..53e2db11e 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -1976,26 +1976,28 @@ "hint": "留空代表不使用。可用于不支持视觉模态的聊天模型。", }, "provider_stt_settings.enable": { - "description": "默认启用语音转文本", + "description": "启用语音转文本", "type": "bool", + "hint": "STT 总开关。", }, "provider_stt_settings.provider_id": { - "description": "语音转文本模型", + "description": "默认语音转文本模型", "type": "string", - "hint": "留空代表不使用。", + "hint": "用户也可使用 /provider 指令单独选择会话的 STT 模型。", "_special": "select_provider_stt", "condition": { "provider_stt_settings.enable": True, }, }, "provider_tts_settings.enable": { - "description": "默认启用文本转语音", + "description": "启用文本转语音", "type": "bool", + "hint": "TTS 总开关。当关闭时,会话启用 TTS 也不会生效。", }, "provider_tts_settings.provider_id": { - "description": "文本转语音模型", + "description": "默认文本转语音模型", "type": "string", - "hint": "留空代表不使用。", + "hint": "用户也可使用 /provider 单独选择会话的 TTS 模型。", "_special": "select_provider_tts", "condition": { "provider_tts_settings.enable": True, @@ -2112,7 +2114,7 @@ "description": "额外前缀提示词", "type": "string", }, - "provider_settings.dual_output": { + "provider_tts_settings.dual_output": { "description": "开启 TTS 时同时输出语音和文字内容", "type": "bool", }, diff --git a/astrbot/core/pipeline/preprocess_stage/stage.py b/astrbot/core/pipeline/preprocess_stage/stage.py index 3e0d4e50f..50dc85a4b 100644 --- a/astrbot/core/pipeline/preprocess_stage/stage.py +++ b/astrbot/core/pipeline/preprocess_stage/stage.py @@ -46,6 +46,9 @@ async def process( ctx = self.plugin_manager.context stt_provider = ctx.get_using_stt_provider(event.unified_msg_origin) if not stt_provider: + logger.warning( + f"会话 {event.unified_msg_origin} 未配置语音转文本模型。" + ) return message_chain = event.get_messages() for idx, component in enumerate(message_chain): diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index 4964dd68c..094d21768 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -183,9 +183,13 @@ async def process( if ( self.ctx.astrbot_config["provider_tts_settings"]["enable"] and result.is_llm_result() - and tts_provider and SessionServiceManager.should_process_tts_request(event) ): + if not tts_provider: + logger.warning( + f"会话 {event.unified_msg_origin} 未配置文本转语音模型。" + ) + return new_chain = [] for comp in result.chain: if isinstance(comp, Plain) and len(comp.text) > 1: diff --git a/packages/astrbot/main.py b/packages/astrbot/main.py index 5d33512b4..327dd8f58 100644 --- a/packages/astrbot/main.py +++ b/packages/astrbot/main.py @@ -310,17 +310,27 @@ async def t2i(self, event: AstrMessageEvent): @filter.command("tts") async def tts(self, event: AstrMessageEvent): """开关文本转语音(会话级别)""" - session_id = event.unified_msg_origin - current_status = SessionServiceManager.is_tts_enabled_for_session(session_id) + umo = event.unified_msg_origin + ses_tts = SessionServiceManager.is_tts_enabled_for_session(umo) + cfg = self.context.get_config(umo=umo) + tts_enable = cfg["provider_tts_settings"]["enable"] # 切换状态 - new_status = not current_status - SessionServiceManager.set_tts_status_for_session(session_id, new_status) + new_status = not ses_tts + SessionServiceManager.set_tts_status_for_session(umo, new_status) status_text = "已开启" if new_status else "已关闭" - event.set_result( - MessageEventResult().message(f"{status_text}当前会话的文本转语音。") - ) + + if new_status and not tts_enable: + event.set_result( + MessageEventResult().message( + f"{status_text}当前会话的文本转语音。但 TTS 功能在配置中未启用,请前往 WebUI 开启。" + ) + ) + else: + event.set_result( + MessageEventResult().message(f"{status_text}当前会话的文本转语音。") + ) @filter.command("sid") async def sid(self, event: AstrMessageEvent):