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: guard empty English timestamp segments
LauraGPT0a90cb5ca1b1
diff --git a/funasr/utils/timestamp_tools.py b/funasr/utils/timestamp_tools.pyindex ef5af8466..17349068b 100644--- a/funasr/utils/timestamp_tools.py+++ b/funasr/utils/timestamp_tools.py@@ -281,16 +281,16 @@ def timestamp_sentence_en(punc_id = int(punc_id) if punc_id is not None else 1sentence_end = timestamp[1] if timestamp is not None else sentence_end- sentence_text = sentence_text[1:] if sentence_text[0] == ' ' else sentence_text+ if sentence_text.startswith(" "):+ sentence_text = sentence_text[1:]if is_sentence_start:sentence_start = timestamp[0] if timestamp is not None else sentence_startis_sentence_start = Falseif punc_id > 1:is_sentence_start = Truesentence_text += punc_list[punc_id - 2]- sentence_text_seg = (- sentence_text_seg[:-1] if sentence_text_seg[-1] == " " else sentence_text_seg- )+ if sentence_text_seg.endswith(" "):+ sentence_text_seg = sentence_text_seg[:-1]if return_raw_text:res.append({diff --git a/tests/test_timestamp_tools.py b/tests/test_timestamp_tools.pynew file mode 100644index 000000000..ba723f7ad--- /dev/null+++ b/tests/test_timestamp_tools.py@@ -0,0 +1,39 @@+from funasr.utils.timestamp_tools import timestamp_sentence_en+++def test_timestamp_sentence_en_handles_whitespace_only_segment():+ result = timestamp_sentence_en(+ punc_id_list=[3],+ timestamp_postprocessed=[[0, 100]],+ text_postprocessed=" ",+ return_raw_text=True,+ )++ assert result == [+ {+ "text": ".",+ "start": 0,+ "end": 100,+ "timestamp": [[0, 100]],+ "raw_text": "",+ }+ ]+++def test_timestamp_sentence_en_preserves_normal_sentence_output():+ result = timestamp_sentence_en(+ punc_id_list=[1, 3],+ timestamp_postprocessed=[[0, 100], [100, 220]],+ text_postprocessed="hello world",+ return_raw_text=True,+ )++ assert result == [+ {+ "text": "hello world.",+ "start": 0,+ "end": 220,+ "timestamp": [[0, 100], [100, 220]],+ "raw_text": "hello world",+ }+ ]