Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
fix(cli): warn when jieba is unavailable for readable SRT splitting (#3726)
林SO940b0d246314
diff --git a/funasr/cli.py b/funasr/cli.pyindex ecf7db9d4..cf9cad319 100644--- a/funasr/cli.py+++ b/funasr/cli.py@@ -2,6 +2,7 @@import argparseimport json+import loggingimport osimport reimport sys@@ -184,13 +185,28 @@ def _timestamps_are_ordered(timestamps):)+_SUBTITLE_WORD_BOUNDARY_FALLBACK_WARNED = False+++def _warn_subtitle_word_boundary_fallback(error):+ """Report once that subtitle splitting lost its word-boundary scoring."""+ global _SUBTITLE_WORD_BOUNDARY_FALLBACK_WARNED+ if _SUBTITLE_WORD_BOUNDARY_FALLBACK_WARNED:+ return+ _SUBTITLE_WORD_BOUNDARY_FALLBACK_WARNED = True+ logging.warning(+ f"jieba word segmentation is unavailable ({error}); readable subtitles "+ "fall back to punctuation-only boundaries and can split words across "+ "cues. Install jieba to restore word-aware subtitle splitting."+ )++def _subtitle_break_weights(text, token_spans):"""Map token-boundary indices to lexical and punctuation preferences."""boundary_to_token = {span[1]: index + 1 for index, span in enumerate(token_spans)}breaks = {len(token_spans): 0.0}try:- import loggingimport warningswith warnings.catch_warnings():@@ -222,8 +238,8 @@ def _subtitle_break_weights(text, token_spans):breaks[token_index] = max(breaks.get(token_index, 0.0), strength)- except (ImportError, RuntimeError, ValueError):- pass+ except (ImportError, RuntimeError, ValueError) as error:+ _warn_subtitle_word_boundary_fallback(error)for index, span in enumerate(token_spans[:-1], 1):boundary = span[1]diff --git a/tests/test_cli.py b/tests/test_cli.pyindex d67422851..f6fe42054 100644--- a/tests/test_cli.py+++ b/tests/test_cli.py@@ -609,3 +609,20 @@ def test_merge_subtitle_segments_avoids_single_character_phrase_breaks():for boundary in boundary_offsets)search_from = phrase_start + 1+++def test_subtitle_break_weights_warns_once_without_jieba(monkeypatch):+ text = "钟书成为朴家保姆后他轻易的偷偷扭了一下儿子的耳朵"+ token_spans = [[index, index + 1] for index in range(len(text))]+ monkeypatch.setattr(cli, "_SUBTITLE_WORD_BOUNDARY_FALLBACK_WARNED", False, raising=False)++ with (+ patch.dict(sys.modules, {"jieba": None}),+ patch("logging.warning") as warning,+ ):+ first = cli._subtitle_break_weights(text, token_spans)+ second = cli._subtitle_break_weights(text, token_spans)++ assert first == second == {len(token_spans): 0.0}+ assert warning.call_count == 1+ assert "jieba" in warning.call_args[0][0]