From 245ee66ac8faa3413c2d03a964c91718c93cdc15 Mon Sep 17 00:00:00 2001 From: Ting Zhang <181050363+GPT-AGI@users.noreply.github.com> Date: Tue, 10 Nov 2026 03:55:18 +0800 Subject: [PATCH 1/2] fix: drop the leading space on Latin sentence timestamps timestamp_sentence inserts a space before an English word but, unlike timestamp_sentence_en, never removes a leading space. A Chinese utterance that continues in English was stored as " iphone pro max.". Signed-off-by: Ting Zhang <181050363+GPT-AGI@users.noreply.github.com> Co-authored-by: Cursor --- funasr/utils/timestamp_tools.py | 5 +++++ tests/test_timestamp_tools.py | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/funasr/utils/timestamp_tools.py b/funasr/utils/timestamp_tools.py index b97e405f33..8009ec7575 100644 --- a/funasr/utils/timestamp_tools.py +++ b/funasr/utils/timestamp_tools.py @@ -189,6 +189,11 @@ def timestamp_sentence( punc_id = int(punc_id) if punc_id is not None else 1 sentence_end = timestamp[1] if timestamp is not None else sentence_end + # Latin tokens are inserted with a leading space. Drop one leading + # space, as timestamp_sentence_en does, so a sentence that starts + # with an English word is not stored as " iphone...". + if sentence_text.startswith(" "): + sentence_text = sentence_text[1:] if punc_id > 1: sentence_text += punc_list[punc_id - 2] if sentence_text_seg.endswith(" "): diff --git a/tests/test_timestamp_tools.py b/tests/test_timestamp_tools.py index a9dd41d18e..763c14e197 100644 --- a/tests/test_timestamp_tools.py +++ b/tests/test_timestamp_tools.py @@ -57,6 +57,31 @@ def test_timestamp_sentence_en_missing_trailing_timestamp_matches_zh_fallback(): assert en_result[1]["start"] == zh_result[1]["start"] +def test_timestamp_sentence_does_not_prefix_latin_text_with_a_space(): + mixed = timestamp_sentence( + punc_id_list=[1, 2, 1, 1, 3], + timestamp_postprocessed=[[0, 100], [100, 200], [200, 300], [300, 400], [400, 500]], + text_postprocessed="我 用 iphone pro max", + return_raw_text=True, + ) + assert [sentence["text"] for sentence in mixed] == ["我用,", "iphone pro max。"] + assert [sentence["raw_text"] for sentence in mixed] == ["我 用", "iphone pro max"] + + english = timestamp_sentence( + [1, 3, 1], + [[0, 100], [100, 200], [200, 300]], + "hello world again", + ) + assert [sentence["text"] for sentence in english] == ["hello world。", "again"] + + chinese = timestamp_sentence( + [1, 3], + [[0, 100], [100, 200]], + "你好 世界", + ) + assert chinese[0]["text"] == "你好世界。" + + def test_timestamp_sentence_raw_text_keeps_token_separators(): result = timestamp_sentence( punc_id_list=[1, 2, 1, 1, 3], From e7e633a2d3d6d304ba4c8b57afc7b7d359a4c19e Mon Sep 17 00:00:00 2001 From: zhifu gao Date: Wed, 11 Nov 2026 13:18:58 +0800 Subject: [PATCH 2/2] test(timestamp): align VAD sentence expectation with Latin spacing fix Retain exact sentence, raw-text and timestamp assertions for PR #3866. The corrected expectation fails on the old implementation and passes on the fixed current-base tree; the complete NumPy CI selection passed privately (421 passed, 27 CUDA-only skips). Signed-off-by: LauraGPT --- tests/test_punc_model_none.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_punc_model_none.py b/tests/test_punc_model_none.py index 42dfe34e60..d827bca019 100644 --- a/tests/test_punc_model_none.py +++ b/tests/test_punc_model_none.py @@ -796,7 +796,7 @@ def test_chinese_vad_boundaries_remove_rich_tags_only_for_alignment(self): def test_mixed_vad_boundaries_preserve_timestamp_units(self): self._check_vad_chunk_alignment( ["你 好 hello", "world 我 来"], - ["你好 hello,", " world 我来。"], + ["你好 hello,", "world 我来。"], "你 好 hello world 我 来", raw_text=True, )