xiaozhi-esp32-server/main/xiaozhi-server/core/handle/abortHandle.py
Bao f38806c858 feat(s2s): 语音进语音出 provider 插槽,附 OpenAI Realtime 实现
新增 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。
2026-10-31 22:20:16 +08:00

22 lines
803 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")