mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-25 04:29:51 +01:00
新增 S2S 模块类型:把 VAD→ASR→LLM→TTS 中间那一格换成自己判轮次、自己出声、能被打断的实时语音模型,设备协议与现有工具、记忆、OTA、白名单照用。上游原文件只动 4 个(connection、abortHandle、receiveAudioHandle、listenMessageHandler)约 30 行,其余在 core/providers/s2s/ 与 core/utils/s2s.py。第一个实现 openai_realtime:WebSocket 直连平台;下行走现成 sendAudio 节拍器并记已播位置;握手失败回退级联;残余回声门控;工具经统一工具处理器;转写进对话历史。附 25 个不出网的测试(含假 Realtime 服务端)与文档 docs/s2s-provider-integration.md。
22 lines
803 B
Python
22 lines
803 B
Python
import json
|
||
from typing import TYPE_CHECKING
|
||
|
||
if TYPE_CHECKING:
|
||
from core.connection import ConnectionHandler
|
||
TAG = __name__
|
||
|
||
|
||
async def handleAbortMessage(conn: "ConnectionHandler"):
|
||
conn.logger.bind(tag=TAG).info("Abort message received")
|
||
# 设置成打断状态,会自动打断llm、tts任务
|
||
conn.close_after_chat = False
|
||
conn.client_abort = True
|
||
conn.clear_queues()
|
||
# 打断客户端说话状态
|
||
await conn.websocket.send(
|
||
json.dumps({"type": "tts", "state": "stop", "session_id": conn.session_id})
|
||
)
|
||
conn.clearSpeakStatus()
|
||
if conn.s2s is not None:
|
||
await conn.s2s.cancel("device") # S2S 模式:丢掉未发的帧、取消上游回复、把上下文截到已播位置
|
||
conn.logger.bind(tag=TAG).info("Abort message received-end")
|