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: stop timestamp_sentence_en reusing a stale sentence start (#3741)
Chi-Wei Leebe7557f27ccc
diff --git a/funasr/utils/timestamp_tools.py b/funasr/utils/timestamp_tools.pyindex 17349068b..85cc42eba 100644--- a/funasr/utils/timestamp_tools.py+++ b/funasr/utils/timestamp_tools.py@@ -263,9 +263,10 @@ def timestamp_sentence_en(punc_stamp_text_list = list(zip_longest(punc_id_list, timestamp_postprocessed, texts, fillvalue=None))- is_sentence_start = Truefor punc_stamp_text in punc_stamp_text_list:punc_id, timestamp, text = punc_stamp_text+ if sentence_start is None and timestamp is not None:+ sentence_start = timestamp[0]# sentence_text += text if text is not None else ''if text is not None:if "a" <= text[0] <= "z" or "A" <= text[0] <= "Z":@@ -283,11 +284,7 @@ def timestamp_sentence_en(sentence_end = timestamp[1] if timestamp is not None else sentence_endif sentence_text.startswith(" "):sentence_text = sentence_text[1:]- if is_sentence_start:- sentence_start = timestamp[0] if timestamp is not None else sentence_start- is_sentence_start = Falseif punc_id > 1:- is_sentence_start = Truesentence_text += punc_list[punc_id - 2]if sentence_text_seg.endswith(" "):sentence_text_seg = sentence_text_seg[:-1]@@ -313,4 +310,5 @@ def timestamp_sentence_en(sentence_text = ""sentence_text_seg = ""ts_list = []+ sentence_start = Nonereturn resdiff --git a/tests/test_timestamp_tools.py b/tests/test_timestamp_tools.pyindex ba723f7ad..6b058d130 100644--- a/tests/test_timestamp_tools.py+++ b/tests/test_timestamp_tools.py@@ -1,4 +1,4 @@-from funasr.utils.timestamp_tools import timestamp_sentence_en+from funasr.utils.timestamp_tools import timestamp_sentence, timestamp_sentence_endef test_timestamp_sentence_en_handles_whitespace_only_segment():@@ -37,3 +37,19 @@ def test_timestamp_sentence_en_preserves_normal_sentence_output():"raw_text": "hello world",}]+++def test_timestamp_sentence_en_missing_trailing_timestamp_matches_zh_fallback():+ # timestamp_postprocessed is one entry shorter than punc_id_list/text_postprocessed,+ # the mismatch the function itself warns about. The second sentence ("bar.") has no+ # timestamp for its only word, so its start must be reported as unknown (None),+ # not silently reused from the previous, unrelated sentence.+ punc_id_list = [1, 3, 3]+ timestamp_postprocessed = [[0, 100], [100, 200]]+ text_postprocessed = "hello world bar"++ en_result = timestamp_sentence_en(punc_id_list, timestamp_postprocessed, text_postprocessed)+ zh_result = timestamp_sentence(punc_id_list, timestamp_postprocessed, text_postprocessed)++ assert en_result[1]["start"] is None+ assert en_result[1]["start"] == zh_result[1]["start"]