From 73867c76d8b5576103db6ed46e40620723a6b2e3 Mon Sep 17 00:00:00 2001 From: Chu Khac Minh <87845619+Minh3132@users.noreply.github.com> Date: Mon, 14 Sep 2026 18:10:02 +0800 Subject: [PATCH 1/2] test: cover CLI speaker diarization switch case handling --- tests/test_cli_sd_switch.py | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/test_cli_sd_switch.py diff --git a/tests/test_cli_sd_switch.py b/tests/test_cli_sd_switch.py new file mode 100644 index 0000000..7029187 --- /dev/null +++ b/tests/test_cli_sd_switch.py @@ -0,0 +1,48 @@ +import sys +from pathlib import Path + +import numpy as np + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "funclip")) + +from videoclipper import VideoClipper, get_parser + + +class RecorderASR: + def generate(self, data, **kwargs): + self.return_spk_res = kwargs["return_spk_res"] + return [{"text": "", "raw_text": "", "timestamp": [], "sentence_info": []}] + + +def _speaker_requested(sd_switch): + model = RecorderASR() + clipper = VideoClipper(model) + clipper.lang = "zh" + _, _, state = clipper.recog((16000, np.zeros(160)), sd_switch=sd_switch) + return model.return_spk_res, "sd_sentences" in state + + +def test_cli_yes_enables_speaker_diarization(): + args = get_parser().parse_args([ + "--stage", "1", + "--file", "placeholder.wav", + "--sd_switch", "yes", + ]) + assert _speaker_requested(args.sd_switch) == (True, True) + + +def test_cli_no_and_default_keep_speaker_diarization_disabled(): + parser = get_parser() + explicit = parser.parse_args([ + "--stage", "1", + "--file", "placeholder.wav", + "--sd_switch", "no", + ]) + default = parser.parse_args(["--stage", "1", "--file", "placeholder.wav"]) + assert _speaker_requested(explicit.sd_switch) == (False, False) + assert _speaker_requested(default.sd_switch) == (False, False) + + +def test_existing_ui_case_variants_remain_supported(): + assert _speaker_requested("Yes") == (True, True) + assert _speaker_requested("No") == (False, False) From ad11daa554b737720dcc884be8d4232778542598 Mon Sep 17 00:00:00 2001 From: Chu Khac Minh <87845619+Minh3132@users.noreply.github.com> Date: Mon, 14 Sep 2026 18:48:22 +0800 Subject: [PATCH 2/2] fix(cli): make speaker diarization switch case-insensitive --- funclip/videoclipper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funclip/videoclipper.py b/funclip/videoclipper.py index 8655940..019a427 100644 --- a/funclip/videoclipper.py +++ b/funclip/videoclipper.py @@ -141,7 +141,7 @@ def recog(self, audio_input, sd_switch='no', state=None, hotwords="", output_dir logging.warning("Input wav shape: {}, only first channel reserved.".format(data.shape)) data = data[:,0] state['audio_input'] = (sr, data) - if sd_switch == 'Yes': + if str(sd_switch).lower() == 'yes': rec_result = self.funasr_model.generate(data, return_spk_res=True, return_raw_text=True,