From b84d32b4a73129702673e962d69b312ebeb35ba9 Mon Sep 17 00:00:00 2001 From: Aniruddha Khandare Date: Sat, 28 Feb 2026 20:03:33 +0530 Subject: [PATCH 1/2] fix: check all speaker diarization imports to prevent silent failures Addresses the issue flagged in PR #2818 review where only ClusterBackend was checked but sv_chunk, postprocess and distribute_spk could also be None if imports fail, causing a cryptic TypeError later. This fix: - Initializes all 4 variables to None before the try block - Replaces bare except with except Exception as e + warning log - Checks all 4 variables together before usage with a clear ImportError Related: #2806, #2818 --- funasr/auto/auto_model.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/funasr/auto/auto_model.py b/funasr/auto/auto_model.py index 309e50c70..5f5400429 100644 --- a/funasr/auto/auto_model.py +++ b/funasr/auto/auto_model.py @@ -46,11 +46,19 @@ def _resolve_ncpu(config, fallback=4): value = fallback return max(value, 1) +sv_chunk = None +postprocess = None +distribute_spk = None +ClusterBackend = None try: from funasr.models.campplus.utils import sv_chunk, postprocess, distribute_spk from funasr.models.campplus.cluster_backend import ClusterBackend -except: - pass +except Exception as e: + import logging + logging.warning( + f"Speaker diarization modules could not be imported: {e}. " + "Speaker diarization functionality will be unavailable." + ) def prepare_data_iterator(data_in, input_len=None, data_type=None, key=None): @@ -175,6 +183,11 @@ def __init__(self, **kwargs): spk_kwargs["device"] = kwargs["device"] spk_kwargs.setdefault("ncpu", kwargs.get("ncpu", 4)) spk_model, spk_kwargs = self.build_model(**spk_kwargs) + if any(x is None for x in (sv_chunk, postprocess, distribute_spk, ClusterBackend)): + raise ImportError( + "Speaker diarization dependencies failed to import. " + "Please ensure scikit-learn>=1.3.0 and scipy are properly installed." + ) self.cb_model = ClusterBackend(**cb_kwargs).to(kwargs["device"]) spk_mode = kwargs.get("spk_mode", "punc_segment") if spk_mode not in ["default", "vad_segment", "punc_segment"]: From fb61a841cbf2b8b52c762a6701b22b25f241ebb5 Mon Sep 17 00:00:00 2001 From: Aniruddha Khandare Date: Sat, 28 Feb 2026 20:24:55 +0530 Subject: [PATCH 2/2] fix: remove redundant logging import in except block Removed unnecessary import of the logging module when speaker diarization modules fail to import. --- funasr/auto/auto_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/funasr/auto/auto_model.py b/funasr/auto/auto_model.py index 5f5400429..d11e3de15 100644 --- a/funasr/auto/auto_model.py +++ b/funasr/auto/auto_model.py @@ -54,7 +54,6 @@ def _resolve_ncpu(config, fallback=4): from funasr.models.campplus.utils import sv_chunk, postprocess, distribute_spk from funasr.models.campplus.cluster_backend import ClusterBackend except Exception as e: - import logging logging.warning( f"Speaker diarization modules could not be imported: {e}. " "Speaker diarization functionality will be unavailable."