From 28ccfbfc51068a663a80764e14074df5edf2b5ba Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期五, 13 三月 2026 17:41:41 +0800
Subject: [PATCH] 提交

---
 tests/test_sv_inference_pipeline.py |   44 ++++++++++++++++++++++----------------------
 1 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/tests/test_sv_inference_pipeline.py b/tests/test_sv_inference_pipeline.py
index 54ab564..76754ab 100644
--- a/tests/test_sv_inference_pipeline.py
+++ b/tests/test_sv_inference_pipeline.py
@@ -12,37 +12,37 @@
     def test_funasr_path(self):
         import funasr
         import os
+
         logger.info("run_dir:{0} ; funasr_path: {1}".format(os.getcwd(), funasr.__file__))
 
     def test_inference_pipeline(self):
         inference_sv_pipline = pipeline(
             task=Tasks.speaker_verification,
-            model='damo/speech_xvector_sv-zh-cn-cnceleb-16k-spk3465-pytorch'
+            model="damo/speech_xvector_sv-zh-cn-cnceleb-16k-spk3465-pytorch",
         )
-        # 鎻愬彇涓嶅悓鍙ュ瓙鐨勮璇濅汉宓屽叆鐮�
+
+        # the same speaker
         rec_result = inference_sv_pipline(
-            audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav')
-        enroll = rec_result["spk_embedding"]
+            audio_in=(
+                "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav",
+                "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_same.wav",
+            )
+        )
+        assert (
+            abs(rec_result["scores"][0] - 0.85) < 0.1 and abs(rec_result["scores"][1] - 0.14) < 0.1
+        )
+        logger.info(f"Similarity {rec_result['scores']}")
 
+        # different speaker
         rec_result = inference_sv_pipline(
-            audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_same.wav')
-        same = rec_result["spk_embedding"]
-
-        rec_result = inference_sv_pipline(
-            audio_in='https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_different.wav')
-        different = rec_result["spk_embedding"]
-
-        # 瀵圭浉鍚岀殑璇磋瘽浜鸿绠椾綑寮︾浉浼煎害
-        sv_threshold = 0.9465
-        same_cos = np.sum(enroll * same) / (np.linalg.norm(enroll) * np.linalg.norm(same))
-        same_cos = max(same_cos - sv_threshold, 0.0) / (1.0 - sv_threshold) * 100.0
-        logger.info("Similarity: {}".format(same_cos))
-
-        # 瀵逛笉鍚岀殑璇磋瘽浜鸿绠椾綑寮︾浉浼煎害
-        diff_cos = np.sum(enroll * different) / (np.linalg.norm(enroll) * np.linalg.norm(different))
-        diff_cos = max(diff_cos - sv_threshold, 0.0) / (1.0 - sv_threshold) * 100.0
-        logger.info("Similarity: {}".format(diff_cos))
+            audio_in=(
+                "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_enroll.wav",
+                "https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/sv_example_different.wav",
+            )
+        )
+        assert abs(rec_result["scores"][0] - 0.0) < 0.1 and abs(rec_result["scores"][1] - 1.0) < 0.1
+        logger.info(f"Similarity {rec_result['scores']}")
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main()

--
Gitblit v1.9.1