From 02cd5e396b321f135b730b974cf0164b95e2b2e0 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:04:27 +0800 Subject: [PATCH] feat: add trigger probability setting for TTS and support to render slider in schema (#4047) * feat: add trigger probability setting for TTS and support to render slider in schema * chore: ruff format --- astrbot/core/config/default.py | 13 ++++ astrbot/core/config/i18n_utils.py | 1 + .../core/pipeline/result_decorate/stage.py | 22 +++++- .../src/components/shared/AstrBotConfig.vue | 68 ++++++++++++++----- .../src/components/shared/AstrBotConfigV4.vue | 27 ++++++-- .../en-US/features/config-metadata.json | 3 + .../zh-CN/features/config-metadata.json | 3 + 7 files changed, 114 insertions(+), 23 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 7f42aa88b..47501d513 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -108,6 +108,7 @@ DEFAULT_CONFIG = { "provider_id": "", "dual_output": False, "use_file_service": False, + "trigger_probability": 1.0, }, "provider_ltm_settings": { "group_icl_enable": False, @@ -2209,6 +2210,9 @@ CONFIG_METADATA_2 = { "use_file_service": { "type": "bool", }, + "trigger_probability": { + "type": "float", + }, }, }, "provider_ltm_settings": { @@ -2419,6 +2423,14 @@ CONFIG_METADATA_3 = { "provider_tts_settings.enable": True, }, }, + "provider_tts_settings.trigger_probability": { + "description": "TTS 触发概率", + "type": "float", + "slider": {"min": 0, "max": 1, "step": 0.05}, + "condition": { + "provider_tts_settings.enable": True, + }, + }, "provider_settings.image_caption_prompt": { "description": "图片转述提示词", "type": "text", @@ -2986,6 +2998,7 @@ CONFIG_METADATA_3 = { "description": "回复概率", "type": "float", "hint": "0.0-1.0 之间的数值", + "slider": {"min": 0, "max": 1, "step": 0.05}, "condition": { "provider_ltm_settings.active_reply.enable": True, }, diff --git a/astrbot/core/config/i18n_utils.py b/astrbot/core/config/i18n_utils.py index d61073f20..aa441c0c1 100644 --- a/astrbot/core/config/i18n_utils.py +++ b/astrbot/core/config/i18n_utils.py @@ -79,6 +79,7 @@ class ConfigMetadataI18n: "_special", "invisible", "options", + "slider", ]: if attr in field_data: field_result[attr] = field_data[attr] diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index 208f3a9f2..7647ef022 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -1,3 +1,4 @@ +import random import re import time import traceback @@ -42,6 +43,18 @@ class ResultDecorateStage(Stage): "forward_threshold" ] + trigger_probability = ctx.astrbot_config["provider_tts_settings"].get( + "trigger_probability", + 1, + ) + try: + self.tts_trigger_probability = max( + 0.0, + min(float(trigger_probability), 1.0), + ) + except (TypeError, ValueError): + self.tts_trigger_probability = 1.0 + # 分段回复 self.words_count_threshold = int( ctx.astrbot_config["platform_settings"]["segmented_reply"][ @@ -246,7 +259,14 @@ class ResultDecorateStage(Stage): and result.is_llm_result() and SessionServiceManager.should_process_tts_request(event) ): - if not tts_provider: + should_tts = self.tts_trigger_probability >= 1.0 or ( + self.tts_trigger_probability > 0.0 + and random.random() <= self.tts_trigger_probability + ) + + if not should_tts: + logger.debug("跳过 TTS:触发概率未命中。") + elif not tts_provider: logger.warning( f"会话 {event.unified_msg_origin} 未配置文本转语音模型。", ) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index d6c6fee9c..361794156 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -304,16 +304,32 @@ function hasVisibleItemsAfter(items, currentIndex) { hide-details > - - +
+ class="d-flex align-center gap-3" + > + + +
- - +
+ class="d-flex align-center gap-3" + > + + +
- - + +
+ + +