From 25d9e6c8cfae31d2febe94f3c43d18a7ac394bcd Mon Sep 17 00:00:00 2001 From: 3030332422 <3030332422@qq.com> Date: Sun, 7 Sep 2025 15:30:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?update:=20=E5=A3=B0=E7=BA=B9=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E6=B7=BB=E5=8A=A0=E7=9B=B8=E4=BC=BC=E5=BA=A6=E9=98=88?= =?UTF-8?q?=E5=80=BC=E6=A3=80=E6=9F=A5=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/config.yaml | 3 +++ .../xiaozhi-server/core/utils/voiceprint_provider.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index c0aa3f93..24947be4 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -148,6 +148,9 @@ voiceprint: - "test1,张三,张三是一个程序员" - "test2,李四,李四是一个产品经理" - "test3,王五,王五是一个设计师" + # 声纹识别相似度阈值,范围0.0-1.0,默认0.4 + # 数值越高越严格,减少误识别但可能增加拒识率 + similarity_threshold: 0.4 # ##################################################################################### # ################################以下是角色模型配置###################################### diff --git a/main/xiaozhi-server/core/utils/voiceprint_provider.py b/main/xiaozhi-server/core/utils/voiceprint_provider.py index 8e788172..5d95b73a 100644 --- a/main/xiaozhi-server/core/utils/voiceprint_provider.py +++ b/main/xiaozhi-server/core/utils/voiceprint_provider.py @@ -19,6 +19,8 @@ class VoiceprintProvider: self.original_url = config.get("url", "") self.speakers = config.get("speakers", []) self.speaker_map = self._parse_speakers() + # 声纹识别相似度阈值,默认0.4 + self.similarity_threshold = float(config.get("similarity_threshold", 0.4)) # 解析API地址和密钥 self.api_url = None @@ -62,7 +64,7 @@ class VoiceprintProvider: # 进行健康检查,验证服务器是否可用 if self._check_server_health(): self.enabled = True - logger.bind(tag=TAG).info(f"声纹识别已启用: API={self.api_url}, 说话人={len(self.speaker_ids)}个") + logger.bind(tag=TAG).info(f"声纹识别已启用: API={self.api_url}, 说话人={len(self.speaker_ids)}个, 相似度阈值={self.similarity_threshold}") else: self.enabled = False logger.bind(tag=TAG).warning(f"声纹识别服务器不可用,声纹识别已禁用: {self.api_url}") @@ -169,12 +171,14 @@ class VoiceprintProvider: logger.bind(tag=TAG).info(f"声纹识别耗时: {total_elapsed_time:.3f}s") - # 置信度检查 - if score < 0.5: - logger.bind(tag=TAG).warning(f"声纹识别置信度较低: {score:.3f}") + # 相似度阈值检查 + if score < self.similarity_threshold: + logger.bind(tag=TAG).warning(f"声纹识别相似度{score:.3f}低于阈值{self.similarity_threshold},拒绝识别") + return "未知说话人" if speaker_id and speaker_id in self.speaker_map: result_name = self.speaker_map[speaker_id]["name"] + logger.bind(tag=TAG).info(f"声纹识别成功: {result_name} (相似度: {score:.3f})") return result_name else: logger.bind(tag=TAG).warning(f"未识别的说话人ID: {speaker_id}") From d66db60177c0b68c22163e79843e58b02e7e197d Mon Sep 17 00:00:00 2001 From: 3030332422 <3030332422@qq.com> Date: Mon, 8 Sep 2025 09:32:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?update:=E4=BF=AE=E6=94=B9=E5=A3=B0=E7=BA=B9?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/utils/voiceprint_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/xiaozhi-server/core/utils/voiceprint_provider.py b/main/xiaozhi-server/core/utils/voiceprint_provider.py index 5d95b73a..ee4f06ca 100644 --- a/main/xiaozhi-server/core/utils/voiceprint_provider.py +++ b/main/xiaozhi-server/core/utils/voiceprint_provider.py @@ -173,7 +173,7 @@ class VoiceprintProvider: # 相似度阈值检查 if score < self.similarity_threshold: - logger.bind(tag=TAG).warning(f"声纹识别相似度{score:.3f}低于阈值{self.similarity_threshold},拒绝识别") + logger.bind(tag=TAG).warning(f"声纹识别相似度{score:.3f}低于阈值{self.similarity_threshold}") return "未知说话人" if speaker_id and speaker_id in self.speaker_map: From 8aed23f21a5da0ac19927fc0edfeb6a86314dbbb Mon Sep 17 00:00:00 2001 From: 3030332422 <3030332422@qq.com> Date: Mon, 8 Sep 2025 16:25:08 +0800 Subject: [PATCH 3/3] =?UTF-8?q?update:=E6=99=BA=E6=8E=A7=E5=8F=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=B8=E4=BC=BC=E5=BA=A6=E9=98=88=E5=80=BC=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/service/impl/ConfigServiceImpl.java | 14 ++++++++++++++ .../main/resources/db/changelog/202509081140.sql | 4 ++++ .../db/changelog/db.changelog-master.yaml | 7 +++++++ 3 files changed, 25 insertions(+) create mode 100644 main/manager-api/src/main/resources/db/changelog/202509081140.sql diff --git a/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java index 476f09cd..5586b9f0 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java @@ -298,6 +298,20 @@ public class ConfigServiceImpl implements ConfigService { Map voiceprintConfig = new HashMap<>(); voiceprintConfig.put("url", voiceprintUrl); voiceprintConfig.put("speakers", speakers); + + // 获取声纹识别相似度阈值,默认0.4 + String thresholdStr = sysParamsService.getValue("server.voiceprint_similarity_threshold", true); + if (StringUtils.isNotBlank(thresholdStr) && !"null".equals(thresholdStr)) { + try { + double threshold = Double.parseDouble(thresholdStr); + voiceprintConfig.put("similarity_threshold", threshold); + } catch (NumberFormatException e) { + // 如果解析失败,使用默认值0.4 + voiceprintConfig.put("similarity_threshold", 0.4); + } + } else { + voiceprintConfig.put("similarity_threshold", 0.4); + } result.put("voiceprint", voiceprintConfig); } catch (Exception e) { diff --git a/main/manager-api/src/main/resources/db/changelog/202509081140.sql b/main/manager-api/src/main/resources/db/changelog/202509081140.sql new file mode 100644 index 00000000..9dec9d04 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202509081140.sql @@ -0,0 +1,4 @@ +-- 添加声纹识别相似度阈值参数配置 +delete from `sys_params` where id = 115; +INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) +VALUES (115, 'server.voiceprint_similarity_threshold', '0.4', 'string', 1, '声纹识别相似度阈值,范围0.0-1.0,默认0.4,数值越高越严格'); 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 0e8d3dc3..dada3c78 100755 --- 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 @@ -303,3 +303,10 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202508131557.sql + - changeSet: + id: 202509081140 + author: cgd + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202509081140.sql