feat(voice): 实现自身语音缓存以跳过ASR识别

当机器人通过TTS插件发送语音时,会自动将语音数据和对应的原始文本进行缓存。

当机器人接收到自己发送的语音消息时,会优先从缓存中直接读取文本,从而跳过调用ASR(自动语音识别)服务的步骤。

此项优化可以:
- 节省不必要的ASR资源开销和费用。
- 保证对机器人自身语音100%的识别准确性。
- 提升对自身消息的响应处理速度。
This commit is contained in:
tt-P607
2025-10-26 01:14:23 +08:00
parent 3ea56c55f1
commit c61cc19eb6
3 changed files with 96 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ import toml
from src.common.logger import get_logger
from src.plugin_system.base.base_action import BaseAction, ChatMode
from src.chat.utils.self_voice_cache import register_self_voice
from ..services.manager import get_service
@@ -174,6 +175,8 @@ class TTSVoiceAction(BaseAction):
)
if audio_b64:
# 在发送语音前,将文本注册到缓存中
register_self_voice(audio_b64, text)
await self.send_custom(message_type="voice", content=audio_b64)
logger.info(f"{self.log_prefix} GPT-SoVITS语音发送成功")
await self.store_action_info(