From 1120be2f6094cbbf36fe950fe8d15bb7bbe37195 Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Mon, 26 Oct 2026 11:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A7=E5=88=B6=E5=8F=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/db/changelog/202610261030.sql | 4 ++++ .../resources/db/changelog/db.changelog-master.yaml | 7 +++++++ main/xiaozhi-server/core/providers/asr/base.py | 4 +--- main/xiaozhi-server/core/utils/voiceprint_provider.py | 10 +++++----- 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 main/manager-api/src/main/resources/db/changelog/202610261030.sql diff --git a/main/manager-api/src/main/resources/db/changelog/202610261030.sql b/main/manager-api/src/main/resources/db/changelog/202610261030.sql new file mode 100644 index 000000000..1ed0106f6 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202610261030.sql @@ -0,0 +1,4 @@ +-- 添加MCP接入点附带说话人身份的开关参数配置 +delete from `sys_params` where param_code = 'mcp_forward_speaker'; +INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) +VALUES (313, 'mcp_forward_speaker', 'true', 'boolean', 1, '是否随MCP调用附带说话人身份'); diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index 282fbaf48..2737a24d1 100644 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -753,3 +753,10 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202609172100.sql + - changeSet: + id: 202610261030 + author: RanChen + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202610261030.sql diff --git a/main/xiaozhi-server/core/providers/asr/base.py b/main/xiaozhi-server/core/providers/asr/base.py index 4bc891349..5c60c2b7d 100644 --- a/main/xiaozhi-server/core/providers/asr/base.py +++ b/main/xiaozhi-server/core/providers/asr/base.py @@ -120,14 +120,12 @@ class ASRProviderBase(ABC): raw_text, _ = asr_result speaker_id = None + speaker_name = "" if isinstance(voiceprint_result, Exception): logger.bind(tag=TAG).error(f"声纹识别失败: {voiceprint_result}") - speaker_name = "" elif voiceprint_result is not None: speaker_name = voiceprint_result.name or "" speaker_id = voiceprint_result.speaker_id - else: - speaker_name = "" # 判断 ASR 结果类型 if isinstance(raw_text, dict): diff --git a/main/xiaozhi-server/core/utils/voiceprint_provider.py b/main/xiaozhi-server/core/utils/voiceprint_provider.py index 256e38122..474e83ab7 100644 --- a/main/xiaozhi-server/core/utils/voiceprint_provider.py +++ b/main/xiaozhi-server/core/utils/voiceprint_provider.py @@ -19,7 +19,7 @@ class SpeakerIdentification(NamedTuple): """一次声纹识别结果。speaker_id 仅在命中已配置说话人时有值。""" speaker_id: Optional[str] - name: Optional[str] + name: str def resolve_speaker_identification( @@ -204,13 +204,13 @@ class VoiceprintProvider: identified = resolve_speaker_identification( speaker_id, score, self.speaker_map, self.similarity_threshold ) - # 相似度阈值检查 - if score < self.similarity_threshold: - logger.bind(tag=TAG).warning(f"声纹识别相似度{score:.3f}低于阈值{self.similarity_threshold}") - elif identified.speaker_id: + # 三种结果:命中 / 低于阈值 / id不在配置中 + if identified.speaker_id: logger.bind(tag=TAG).info( f"声纹识别成功: {identified.name} (id: {identified.speaker_id}, 相似度: {score:.3f})" ) + elif score < self.similarity_threshold: + logger.bind(tag=TAG).warning(f"声纹识别相似度{score:.3f}低于阈值{self.similarity_threshold}") else: logger.bind(tag=TAG).warning(f"未识别的说话人ID: {speaker_id}") return identified