feat(napcat_adapter): 添加服务器地址和端口配置选项,优先使用插件配置
feat(tts_plugin): 优化TTS处理逻辑,支持生成回复并处理文本格式
This commit is contained in:
@@ -279,6 +279,8 @@ class NapcatAdapterPlugin(BasePlugin):
|
||||
},
|
||||
"maibot_server": {
|
||||
"platform_name": ConfigField(type=str, default="qq", description="平台名称,用于消息路由"),
|
||||
"host": ConfigField(type=str, default="", description="MoFox-Bot服务器地址,留空则使用全局配置"),
|
||||
"port": ConfigField(type=int, default=0, description="MoFox-Bot服务器端口,设为0则使用全局配置"),
|
||||
},
|
||||
"voice": {
|
||||
"use_tts": ConfigField(
|
||||
|
||||
@@ -15,10 +15,23 @@ def create_router(plugin_config: dict):
|
||||
"""创建路由器实例"""
|
||||
global router
|
||||
platform_name = config_api.get_plugin_config(plugin_config, "maibot_server.platform_name", "qq")
|
||||
server = get_global_server()
|
||||
host = server.host
|
||||
port = server.port
|
||||
logger.debug(f"初始化MoFox-Bot连接,使用地址:{host}:{port}")
|
||||
|
||||
# 优先从插件配置读取 host 和 port,如果不存在则回退到全局配置
|
||||
config_host = config_api.get_plugin_config(plugin_config, "maibot_server.host", "")
|
||||
config_port = config_api.get_plugin_config(plugin_config, "maibot_server.port", 0)
|
||||
|
||||
if config_host and config_port > 0:
|
||||
# 使用插件配置
|
||||
host = config_host
|
||||
port = config_port
|
||||
logger.debug(f"初始化MoFox-Bot连接,使用插件配置地址:{host}:{port}")
|
||||
else:
|
||||
# 回退到全局配置
|
||||
server = get_global_server()
|
||||
host = server.host
|
||||
port = server.port
|
||||
logger.debug(f"初始化MoFox-Bot连接,使用全局配置地址:{host}:{port}")
|
||||
|
||||
route_config = RouteConfig(
|
||||
route_config={
|
||||
platform_name: TargetConfig(
|
||||
|
||||
@@ -6,6 +6,8 @@ from src.plugin_system.base.base_action import ActionActivationType, BaseAction,
|
||||
from src.plugin_system.base.base_plugin import BasePlugin
|
||||
from src.plugin_system.base.component_types import ComponentInfo
|
||||
from src.plugin_system.base.config_types import ConfigField
|
||||
from src.plugin_system.apis.generator_api import generate_reply
|
||||
from src.config.config import global_config
|
||||
|
||||
logger = get_logger("tts")
|
||||
|
||||
@@ -49,16 +51,34 @@ class TTSAction(BaseAction):
|
||||
"""处理TTS文本转语音动作"""
|
||||
logger.info(f"{self.log_prefix} 执行TTS动作: {self.reasoning}")
|
||||
|
||||
# 获取要转换的文本
|
||||
text = self.action_data.get("text")
|
||||
|
||||
if not text:
|
||||
logger.error(f"{self.log_prefix} 执行TTS动作时未提供文本内容")
|
||||
return False, "执行TTS动作失败:未提供文本内容"
|
||||
success, response_set, _ = await generate_reply(
|
||||
chat_stream=self.chat_stream,
|
||||
reply_message=self.chat_stream.context_manager.context.get_last_message(),
|
||||
enable_tool=global_config.tool.enable_tool,
|
||||
request_type="chat.tts",
|
||||
from_plugin=False,
|
||||
)
|
||||
|
||||
# 确保文本适合TTS使用
|
||||
processed_text = self._process_text_for_tts(text)
|
||||
reply_text = ""
|
||||
for reply_seg in response_set:
|
||||
# 调试日志:验证reply_seg的格式
|
||||
logger.debug(f"Processing reply_seg type: {type(reply_seg)}, content: {reply_seg}")
|
||||
|
||||
# 修正:正确处理元组格式 (格式为: (type, content))
|
||||
if isinstance(reply_seg, tuple) and len(reply_seg) >= 2:
|
||||
_, data = reply_seg
|
||||
else:
|
||||
# 向下兼容:如果已经是字符串,则直接使用
|
||||
data = str(reply_seg)
|
||||
|
||||
if isinstance(data, list):
|
||||
data = "".join(map(str, data))
|
||||
reply_text += data
|
||||
|
||||
# 处理文本以优化TTS效果
|
||||
processed_text = self._process_text_for_tts(reply_text)
|
||||
|
||||
try:
|
||||
# 发送TTS消息
|
||||
await self.send_custom(message_type="tts_text", content=processed_text)
|
||||
|
||||
Reference in New Issue
Block a user