Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -111,7 +111,6 @@ class NormalChatExpressor:
|
|||||||
|
|
||||||
# 创建消息集
|
# 创建消息集
|
||||||
|
|
||||||
first_bot_msg = None
|
|
||||||
mark_head = False
|
mark_head = False
|
||||||
is_emoji = False
|
is_emoji = False
|
||||||
if len(response_set) == 0:
|
if len(response_set) == 0:
|
||||||
@@ -140,14 +139,16 @@ class NormalChatExpressor:
|
|||||||
# 提交消息集
|
# 提交消息集
|
||||||
if bot_msg:
|
if bot_msg:
|
||||||
await message_manager.add_message(bot_msg)
|
await message_manager.add_message(bot_msg)
|
||||||
logger.info(f"{self.log_prefix} 成功发送 {response_type}类型消息: {content}")
|
logger.info(
|
||||||
|
f"{self.log_prefix} 成功发送 {response_type}类型消息: {str(content)[:200] + '...' if len(str(content)) > 200 else content}"
|
||||||
|
)
|
||||||
container = await message_manager.get_container(self.chat_stream.stream_id) # 使用 self.stream_id
|
container = await message_manager.get_container(self.chat_stream.stream_id) # 使用 self.stream_id
|
||||||
for msg in container.messages[:]:
|
for msg in container.messages[:]:
|
||||||
if isinstance(msg, MessageThinking) and msg.message_info.message_id == thinking_id:
|
if isinstance(msg, MessageThinking) and msg.message_info.message_id == thinking_id:
|
||||||
container.messages.remove(msg)
|
container.messages.remove(msg)
|
||||||
logger.debug(f"[{self.stream_name}] 已移除未产生回复的思考消息 {thinking_id}")
|
logger.debug(f"[{self.stream_name}] 已移除未产生回复的思考消息 {thinking_id}")
|
||||||
break
|
break
|
||||||
return first_bot_msg
|
return bot_msg
|
||||||
else:
|
else:
|
||||||
logger.warning(f"{self.log_prefix} 没有有效的消息被创建")
|
logger.warning(f"{self.log_prefix} 没有有效的消息被创建")
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
from . import tts_action # noqa
|
|
||||||
16
src/plugins/built_in/tts_plugin/config.toml
Normal file
16
src/plugins/built_in/tts_plugin/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# 文字转语音插件配置文件
|
||||||
|
|
||||||
|
[plugin]
|
||||||
|
name = "tts_plugin"
|
||||||
|
version = "0.1.0"
|
||||||
|
enabled = true
|
||||||
|
description = "文字转语音插件"
|
||||||
|
|
||||||
|
# 组件启用控制
|
||||||
|
[components]
|
||||||
|
enable_tarots = true
|
||||||
|
|
||||||
|
# 日志配置
|
||||||
|
[logging]
|
||||||
|
level = "INFO"
|
||||||
|
prefix = "[TTS]"
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
|
from src.plugin_system.base.base_plugin import BasePlugin, register_plugin
|
||||||
|
from src.plugin_system.base.component_types import ComponentInfo
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.plugin_system.base.base_action import ActionActivationType
|
from src.plugin_system.base.base_action import BaseAction, ActionActivationType, ChatMode
|
||||||
from src.plugin_system.base.base_action import BaseAction as PluginAction, register_action
|
from typing import Tuple, List, Type
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
logger = get_logger("tts_action")
|
logger = get_logger("tts")
|
||||||
|
|
||||||
|
|
||||||
@register_action
|
class TTSAction(BaseAction):
|
||||||
class TTSAction(PluginAction):
|
|
||||||
"""TTS语音转换动作处理类"""
|
"""TTS语音转换动作处理类"""
|
||||||
|
|
||||||
action_name = "tts_action"
|
action_name = "tts"
|
||||||
action_description = "将文本转换为语音进行播放,适用于需要语音输出的场景"
|
action_description = "将文本转换为语音进行播放,适用于需要语音输出的场景"
|
||||||
action_parameters = {
|
action_parameters = {
|
||||||
"text": "需要转换为语音的文本内容,必填,内容应当适合语音播报,语句流畅、清晰",
|
"text": "需要转换为语音的文本内容,必填,内容应当适合语音播报,语句流畅、清晰",
|
||||||
@@ -24,6 +24,10 @@ class TTSAction(PluginAction):
|
|||||||
enable_plugin = True # 启用插件
|
enable_plugin = True # 启用插件
|
||||||
associated_types = ["tts_text"]
|
associated_types = ["tts_text"]
|
||||||
|
|
||||||
|
# 模式和并行控制
|
||||||
|
mode_enable = ChatMode.ALL
|
||||||
|
parallel_action = False
|
||||||
|
|
||||||
focus_activation_type = ActionActivationType.LLM_JUDGE
|
focus_activation_type = ActionActivationType.LLM_JUDGE
|
||||||
normal_activation_type = ActionActivationType.KEYWORD
|
normal_activation_type = ActionActivationType.KEYWORD
|
||||||
|
|
||||||
@@ -34,7 +38,7 @@ class TTSAction(PluginAction):
|
|||||||
# 并行执行设置 - TTS可以与回复并行执行,不覆盖回复内容
|
# 并行执行设置 - TTS可以与回复并行执行,不覆盖回复内容
|
||||||
parallel_action = False
|
parallel_action = False
|
||||||
|
|
||||||
async def process(self) -> Tuple[bool, str]:
|
async def execute(self) -> Tuple[bool, str]:
|
||||||
"""处理TTS文本转语音动作"""
|
"""处理TTS文本转语音动作"""
|
||||||
logger.info(f"{self.log_prefix} 执行TTS动作: {self.reasoning}")
|
logger.info(f"{self.log_prefix} 执行TTS动作: {self.reasoning}")
|
||||||
|
|
||||||
@@ -50,7 +54,7 @@ class TTSAction(PluginAction):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 发送TTS消息
|
# 发送TTS消息
|
||||||
await self.send_message(type="tts_text", data=processed_text)
|
await self.send_type(type="tts_text", text=processed_text)
|
||||||
|
|
||||||
logger.info(f"{self.log_prefix} TTS动作执行成功,文本长度: {len(processed_text)}")
|
logger.info(f"{self.log_prefix} TTS动作执行成功,文本长度: {len(processed_text)}")
|
||||||
return True, "TTS动作执行成功"
|
return True, "TTS动作执行成功"
|
||||||
@@ -82,3 +86,39 @@ class TTSAction(PluginAction):
|
|||||||
processed_text = processed_text + "。"
|
processed_text = processed_text + "。"
|
||||||
|
|
||||||
return processed_text
|
return processed_text
|
||||||
|
|
||||||
|
|
||||||
|
@register_plugin
|
||||||
|
class TTSPlugin(BasePlugin):
|
||||||
|
"""TTS插件
|
||||||
|
- 这是文字转语音插件
|
||||||
|
- Normal模式下依靠关键词触发
|
||||||
|
- Focus模式下由LLM判断触发
|
||||||
|
- 具有一定的文本预处理能力
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 插件基本信息
|
||||||
|
plugin_name = "tts_plugin"
|
||||||
|
plugin_description = "文字转语音插件"
|
||||||
|
plugin_version = "0.1.0"
|
||||||
|
plugin_author = "MaiBot开发团队"
|
||||||
|
enable_plugin = True
|
||||||
|
config_file_name = "config.toml"
|
||||||
|
|
||||||
|
def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]:
|
||||||
|
"""返回插件包含的组件列表"""
|
||||||
|
|
||||||
|
# 从配置获取组件启用状态
|
||||||
|
enable_tts = self.get_config("components.enable_tts", True)
|
||||||
|
components = []
|
||||||
|
|
||||||
|
# 添加Action组件
|
||||||
|
if enable_tts:
|
||||||
|
components.append(
|
||||||
|
(
|
||||||
|
TTSAction.get_action_info(name="tarots_action", description="文字转语音插件"),
|
||||||
|
TTSAction,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return components
|
||||||
Reference in New Issue
Block a user