From a8591060d3889cd7a72841fa32a7ee64b49db1d2 Mon Sep 17 00:00:00 2001
From: msgk <zxr935867802@outlook.com>
Date: 星期五, 14 二月 2025 14:16:51 +0800
Subject: [PATCH] fix(spk): 修复 speaker embedding 集群后的重新排序问题

---
 funasr/auto/auto_model.py |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/funasr/auto/auto_model.py b/funasr/auto/auto_model.py
index 96c642e..f5cbe01 100644
--- a/funasr/auto/auto_model.py
+++ b/funasr/auto/auto_model.py
@@ -549,8 +549,41 @@
 
             # speaker embedding cluster after resorted
             if self.spk_model is not None and kwargs.get("return_spk_res", True):
-                if raw_text is None:
-                    logging.error("Missing punc_model, which is required by spk_model.")
+                # 1. 鍏堟鏌ユ椂闂存埑
+                has_timestamp = (
+                    hasattr(self.model, "internal_punc") or
+                    self.punc_model is not None or
+                    "timestamp" in result
+                )
+                
+                if not has_timestamp:
+                    logging.error("Need timestamp support...")
+                    return results_ret_list
+
+                # 2. 鍒濆鍖� punc_res
+                punc_res = None
+                
+                # 3. 鏍规嵁涓嶅悓鎯呭喌璁剧疆 punc_res
+                if hasattr(self.model, "internal_punc"):
+                    punc_res = [{
+                        "text": result["text"],
+                        "punc_array": result.get("punc_array", []),
+                        "timestamp": result.get("timestamp", [])
+                    }]
+                elif self.punc_model is not None:
+                    punc_res = self.inference(
+                        result["text"], 
+                        model=self.punc_model, 
+                        kwargs=self.punc_kwargs, 
+                        **cfg
+                    )
+                else:
+                    # 濡傛灉鍙湁鏃堕棿鎴筹紝鍒涘缓涓�涓熀鏈殑 punc_res
+                    punc_res = [{
+                        "text": result["text"],
+                        "punc_array": [],  # 绌虹殑鏍囩偣鏁扮粍
+                        "timestamp": result["timestamp"]
+                    }]
                 all_segments = sorted(all_segments, key=lambda x: x[0])
                 spk_embedding = result["spk_embedding"]
                 labels = self.cb_model(

--
Gitblit v1.9.1