From a57cc3f92a5064cdb4dd8f9417d2f03316ea77b3 Mon Sep 17 00:00:00 2001 From: LauraGPT <18321252+LauraGPT@users.noreply.github.com> Date: Tue, 29 Sep 2026 06:12:59 +0000 Subject: [PATCH] fix(sensevoice): keep words separate at standalone boundaries Signed-off-by: LauraGPT <18321252+LauraGPT@users.noreply.github.com> --- funasr/models/sense_voice/model.py | 1 + tests/test_sensevoice_word_timestamps.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/funasr/models/sense_voice/model.py b/funasr/models/sense_voice/model.py index c2f89eefd..d822939d5 100644 --- a/funasr/models/sense_voice/model.py +++ b/funasr/models/sense_voice/model.py @@ -1093,6 +1093,7 @@ class SenseVoiceSmall(nn.Module): start = int(start * 1000) end = int(end * 1000) if word == "▁": + prev_word = None continue if i == 0: word = word[1:] if word.startswith("▁") else word diff --git a/tests/test_sensevoice_word_timestamps.py b/tests/test_sensevoice_word_timestamps.py index 5f1a4e9be..c1e539d99 100644 --- a/tests/test_sensevoice_word_timestamps.py +++ b/tests/test_sensevoice_word_timestamps.py @@ -66,6 +66,24 @@ from funasr.models.sense_voice.model import SenseVoiceSmall pytest.param( ["A", "\u2581B", "C"], ["A", "BC"], [[0, 125], [125, 375]], id="word-boundary" ), + pytest.param( + ["Hello", "\u2581", "world"], + ["Hello", "world"], + [[0, 125], [250, 375]], + id="standalone-word-boundary", + ), + pytest.param( + ["\u2581Hel", "lo", "\u2581", "wor", "ld"], + ["Hello", "world"], + [[0, 250], [375, 625]], + id="subpieces-around-standalone-boundary", + ), + pytest.param( + ["Hello", "\u2581", "\u2581", "world"], + ["Hello", "world"], + [[0, 125], [375, 500]], + id="repeated-standalone-boundaries", + ), ], ) def test_post_preserves_word_boundaries_and_timestamp_alignment(tokens, words, timestamps):