From 78c9301580c977945649549f545b980e8ae2d370 Mon Sep 17 00:00:00 2001 From: Mohammad Hijjawi Date: Thu, 1 Oct 2026 01:07:46 +0100 Subject: [PATCH] fix(sensevoice): stop rendering the Cough event as the Sneeze emoji MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rich_transcription_postprocess() maps SenseVoice event tags through event_dict, which used 🤧 for both <|Sneeze|> and <|Cough|>, so coughs were displayed as sneezes. emoji_dict and event_set already use 😷 for coughs; use it in event_dict too, in funasr and in the funasr_onnx and funasr_torch runtime copies. --- funasr/utils/postprocess_utils.py | 2 +- .../funasr_torch/utils/postprocess_utils.py | 2 +- .../funasr_onnx/utils/postprocess_utils.py | 2 +- tests/test_rich_transcription_postprocess.py | 34 +++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/test_rich_transcription_postprocess.py diff --git a/funasr/utils/postprocess_utils.py b/funasr/utils/postprocess_utils.py index beaa87cb4e..28c5d4546d 100644 --- a/funasr/utils/postprocess_utils.py +++ b/funasr/utils/postprocess_utils.py @@ -353,7 +353,7 @@ def sentence_postprocess_sentencepiece(words): "<|Cry|>": "😭", "<|Sneeze|>": "🤧", "<|Breath|>": "", - "<|Cough|>": "🤧", + "<|Cough|>": "😷", } lang_dict = { diff --git a/runtime/python/libtorch/funasr_torch/utils/postprocess_utils.py b/runtime/python/libtorch/funasr_torch/utils/postprocess_utils.py index eb4e2232e3..a5a90f74a3 100644 --- a/runtime/python/libtorch/funasr_torch/utils/postprocess_utils.py +++ b/runtime/python/libtorch/funasr_torch/utils/postprocess_utils.py @@ -262,7 +262,7 @@ def sentence_postprocess(words: List[Any], time_stamp: List[List] = None): "<|Cry|>": "😭", "<|Sneeze|>": "🤧", "<|Breath|>": "", - "<|Cough|>": "🤧", + "<|Cough|>": "😷", } lang_dict = { diff --git a/runtime/python/onnxruntime/funasr_onnx/utils/postprocess_utils.py b/runtime/python/onnxruntime/funasr_onnx/utils/postprocess_utils.py index d144d31aba..d065b69fef 100644 --- a/runtime/python/onnxruntime/funasr_onnx/utils/postprocess_utils.py +++ b/runtime/python/onnxruntime/funasr_onnx/utils/postprocess_utils.py @@ -316,7 +316,7 @@ def sentence_postprocess_sentencepiece(words): "<|Cry|>": "😭", "<|Sneeze|>": "🤧", "<|Breath|>": "", - "<|Cough|>": "🤧", + "<|Cough|>": "😷", } lang_dict = { diff --git a/tests/test_rich_transcription_postprocess.py b/tests/test_rich_transcription_postprocess.py new file mode 100644 index 0000000000..8e07de09eb --- /dev/null +++ b/tests/test_rich_transcription_postprocess.py @@ -0,0 +1,34 @@ +"""Regression tests for SenseVoice rich transcription postprocessing.""" + +import importlib.util +from pathlib import Path + +import pytest + +REPO_ROOT = Path(__file__).resolve().parents[1] +RUNTIME_PYTHON = REPO_ROOT / "runtime" / "python" +POSTPROCESS_UTILS = [ + REPO_ROOT / "funasr" / "utils" / "postprocess_utils.py", + RUNTIME_PYTHON / "onnxruntime" / "funasr_onnx" / "utils" / "postprocess_utils.py", + RUNTIME_PYTHON / "libtorch" / "funasr_torch" / "utils" / "postprocess_utils.py", +] + + +def _load(path): + spec = importlib.util.spec_from_file_location(f"_postprocess_utils_{path.parts[-3]}", path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +@pytest.mark.parametrize("path", POSTPROCESS_UTILS, ids=lambda path: path.parts[-3]) +@pytest.mark.parametrize( + "event, emoji", + [("<|Cough|>", "😷"), ("<|Sneeze|>", "🤧")], +) +def test_cough_and_sneeze_events_render_distinct_emojis(path, event, emoji): + module = _load(path) + + text = module.rich_transcription_postprocess(f"<|en|><|NEUTRAL|>{event}<|woitn|>hello") + + assert text == f"{emoji}hello"