Skip to content

feat(formatting): normalize quote marks in the final transcript - #52

Merged
giraphant merged 1 commit into
mainfrom
giraphant/formatting-quotation
Jul 27, 2026
Merged

giraphant merged 1 commit into
mainfrom
giraphant/formatting-quotation

Conversation

@giraphant

Copy link
Copy Markdown
Owner

问题

ASR 引擎吐回来的是 ASCII 引号 —— Soniox 在转述句里给 ",缩写里给 ' —— 所以听写出来的文本不管什么语境都是直引号。

改动

TranscriptCorrector 新增规则 3 normalizeQuotes:跨整段配对每一个双引号,按配置的风格重新输出。

  • 语境按整段判断:文本里有任一汉字就算中文语境,所以中文句子里引用的英文术语也走中文引号(什么是"action" → 什么是「action」);纯拉丁文本永远用弯引号,不受设置影响。
  • 新增 quoteStyle 偏好:「」 / “” / 不处理,默认 “”。设置界面在 智能增强 → 文本格式。
  • 撇号:don't → don’t,但只在两侧都是词内字符时才转。单边判断会把 'hi' 变成 'hi’(头直尾弯),比不动更难看;代价是所有格复数 students' 保持 ASCII 撇号。
  • 中文语境下顺手吃掉引号与汉字之间的游离空格(他说 "你好" → 他说「你好」)。TranscriptFormatter.tightenCJKSpaces 故意不认弯引号(它们同时是英文标点),所以这个 trim 只能在已知语境的这一层做。

为什么放在 corrector 而不是 formatter

开引号还是闭引号的判断需要整段最终文本,流式片段给不了。代价是听写过程中 HUD 预览里仍然是直引号,只有最终注入的文本被规范化。

已知天花板

  • 语言检测就是"含汉字即中文"。英文句子里夹一个中文词会走中文引号。真踩到再换 Han 比例阈值。
  • 豆包(纯中文路由)根本不产引号,enable_punctuation / enable_text_post_process 都已开启也没用。所以 「」 只在走 Soniox(中英混合)时才有素材可规范。这是引擎限制,不是格式化规则能补的。

验证

  • 362 个单测全过,新增 8 个覆盖引号规则(中英语境、已有引号重排、嵌套、撇号、空格 trim、off、幂等)。
  • make install 后现场听写验证:
    • He said, "I don't care about distinction." → He said, “I don’t care about distinction.”
    • 他说,I don't care about distinction,我觉得他说得挺对的。 → 他说:「I don’t care about distinction,」我觉得他说得挺对的。

🤖 Generated with Claude Code

ASR engines hand back ASCII quote marks — Soniox in particular emits `"`
around quoted speech and `'` in contractions — so dictated text arrived
with straight quotes regardless of the surrounding language.

Adds rule 3 to TranscriptCorrector: pair every double-quote mark across
the dictation and re-emit it in the configured style. Language context is
decided per dictation (any Han ideograph => Chinese), so a quoted English
term inside a Chinese sentence takes Chinese marks; Latin-only text always
gets curly marks. New `quoteStyle` preference picks the Chinese convention
(「」 / “” / off), surfaced under 智能增强 → 文本格式.

Lives in TranscriptCorrector, not TranscriptFormatter: the open/close call
needs the whole final text, which a streamed fragment can't provide. The
cost is that the HUD preview still shows straight quotes mid-dictation.

Single quotes are only touched as apostrophes, and only with a word
character on both sides — a one-sided test curls the tail of 'hi' while
leaving its head straight, which reads worse than not touching it.

Co-Authored-By: Claude <noreply@anthropic.com>
@giraphant
giraphant merged commit 1bf7a0b into main Jul 27, 2026
1 check passed
@giraphant
giraphant deleted the giraphant/formatting-quotation branch July 27, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant