diff --git a/main/xiaozhi-server/core/handle/receiveAudioHandle.py b/main/xiaozhi-server/core/handle/receiveAudioHandle.py index 8aae3af26..2e81a78b2 100644 --- a/main/xiaozhi-server/core/handle/receiveAudioHandle.py +++ b/main/xiaozhi-server/core/handle/receiveAudioHandle.py @@ -64,7 +64,7 @@ async def startToChat(conn: "ConnectionHandler", text): elif "content" in data: # FunASR 等返回 {"content","language","emotion"}:只把识别正文交给 LLM, # 否则整段 JSON 会进入对话历史 - actual_text = str(data["content"]) + actual_text = data["content"] except (json.JSONDecodeError, KeyError): # 如果解析失败,继续使用原始文本 pass diff --git a/main/xiaozhi-server/tests/core/handle/__init__.py b/main/xiaozhi-server/tests/core/handle/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/main/xiaozhi-server/tests/core/handle/test_start_to_chat_asr_payload.py b/main/xiaozhi-server/tests/core/handle/test_start_to_chat_asr_payload.py deleted file mode 100644 index dccc305a4..000000000 --- a/main/xiaozhi-server/tests/core/handle/test_start_to_chat_asr_payload.py +++ /dev/null @@ -1,73 +0,0 @@ -"""startToChat must hand the recognized text, not the ASR JSON, to the LLM.""" -import json -import logging -from types import SimpleNamespace - -import pytest - -import core.handle.receiveAudioHandle as receive - - -class _Executor: - def __init__(self): - self.calls = [] - - def submit(self, fn, *args): - self.calls.append(args) - - -def _conn(): - logger = logging.getLogger("test") - return SimpleNamespace( - logger=SimpleNamespace(bind=lambda **_: logger), - introduced_speakers=set(), - current_speaker=None, - need_bind=False, - max_output_size=0, - client_is_speaking=False, - client_listen_mode="auto", - client_abort=True, - executor=_Executor(), - chat=lambda text: None, - ) - - -@pytest.fixture(autouse=True) -def _no_side_effects(monkeypatch): - async def not_handled(conn, text): - return False - - async def ignore(*args, **kwargs): - return None - - monkeypatch.setattr(receive, "handle_user_intent", not_handled) - monkeypatch.setattr(receive, "send_stt_message", ignore) - - -async def test_funasr_payload_without_speaker_passes_only_content(): - conn = _conn() - payload = json.dumps({"content": "今日は寒いね。", "language": "ja", "emotion": "😶"}, ensure_ascii=False) - - await receive.startToChat(conn, payload) - - assert conn.executor.calls == [("今日は寒いね。",)] - assert conn.current_speaker is None - - -async def test_first_speaker_payload_still_keeps_json_once(): - conn = _conn() - payload = json.dumps({"speaker": "Alice", "content": "hello"}, ensure_ascii=False) - - await receive.startToChat(conn, payload) - await receive.startToChat(conn, payload) - - assert conn.executor.calls == [(payload,), ("hello",)] - assert conn.current_speaker == "Alice" - - -async def test_plain_text_is_unchanged(): - conn = _conn() - - await receive.startToChat(conn, "你好") - - assert conn.executor.calls == [("你好",)]