Keep spaces between English words in Paraformer transcripts #890
The English fix is right, but the regex only covers Han-Han pairs, so digits and punctuation in Chinese output pick up stray spaces. I ran tests/test_paraformer_transcription_events.py on the PR head in Docker: 12 passed. I then fed token lists through FunASR 1.4.29's own sentence_postprocess. Without timestamps it already returns 我喜欢python编程 and hello world, so it only joins tokens with spaces on the timestamp path (" ".join(real_word_lists)). On that path, the regex at src/speech_to_speech/STT/paraformer_handler.py:22 turns 我 有 3 个 into 我有 3 个 and 今 天 , 好 。 into 今天 , 好 。. The old .replace(" ", "") produced 我有3个 and 今天,好。, so any digit or full-width punctuation token the model emits now keeps its spaces.
Suggestions:
(?<![A-Za-z0-9'])\s+|\s+(?![A-Za-z0-9']). That gives the same output as FunASR's non-timestamp path, so the transcript doesn't depend on which path the model took.,/。 case to the parametrize at tests/test_paraformer_transcription_events.py:135.paraformer_handler.py:62 (warmup) still uses .replace(" ", ""). The result is discarded, but sharing one helper would keep the two in sync.Thanks, you're right. I'd missed that only the timestamp path adds the spaces. Pushed 22fbf5a with your rule (keep spaces only between Latin/digit words), added the digit and punctuation cases, and the warmup now uses the same helper.
1AbdullahButt
Shizoqua
Fixes #887
What was wrong
ParaformerSTTHandler.processinsrc/speech_to_speech/STT/paraformer_handler.pycalled.replace(" ", "")on the transcript. FunASR keeps the spaces between English words on both of its output paths, soparaformer-enoutput"hello world how are you"became"helloworldhowareyou".Fix
Keep a space only between two Latin or digit words and drop the rest. FunASR's timestamp path joins every token with a space (
我 有 3 个) while its plain path does not (我有3个), so Chinese text, digits and full-width punctuation now come out the same on both paths. Warmup uses the same helper.Tests
test_paraformer_keeps_spaces_only_between_latin_or_digit_wordsintests/test_paraformer_transcription_events.pyfeeds a stub model FunASR-style output for Chinese, English, mixed speech, digits and full-width punctuation. The English, mixed, digit and punctuation cases fail onmain('helloworldhowareyou' == 'hello world how are you') and all pass now. The existing Chinese tests are unchanged and still pass.uv run pytest tests/test_paraformer_transcription_events.py -q
15 passed
uv run pytest tests/ -q
4189 passed, 13 skipped
uv run ruff check src/ tests/,uv run ruff format --check src/ tests/anduv run mypy src/pass.I did not run Big Bench Audio. Its default stack uses Parakeet for STT, so it would not exercise Paraformer, and running it with Paraformer needs the FunASR models. The change only touches the text the handler returns.