Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2112,7 +2114,7 @@
"description": "额外前缀提示词",
"type": "string",
},
"provider_settings.dual_output": {
"provider_tts_settings.dual_output": {
"description": "开启 TTS 时同时输出语音和文字内容",
"type": "bool",
},
Expand Down
3 changes: 3 additions & 0 deletions astrbot/core/pipeline/preprocess_stage/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion astrbot/core/pipeline/result_decorate/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 17 additions & 7 deletions packages/astrbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down