Repository navigation
Conversation
已启用的词典词条作为 Qwen3-ASR 的 context 参与 TextStream 识别, 在语音识别这一步就把专有名词写对,而不是只靠 LLM 润色去补。 - 沿用会话冻结的 asr.prompt,经环境变量 OPENLESS_TEXTSTREAM_CONTEXT 交给 worker,再传给 init_streaming(context=...)。 - worker 把 "A, B." 转成 mlx-qwen3-asr 文档要求的空格分隔:逗号列表会 诱使解码器在正常语句中续写词表。去掉尖括号,避免词条被分词成控制 token。 - 没有人声的窗口会让解码器把 context 当作转写输出,并残留在强制前缀里 吞掉之后的语音。检测连续 4 个及以上、顺序与词典一致的词条,从所有快照 中去掉并重启流;触发的那块音频在新流里再解码一次。 - 带 context 时被标成 None 的语言不再沿用到后续窗口。 - 把已发布的 worker 加入 PREVIOUS_WORKERS,已安装用户可直接升级脚本。 不带词典时行为与之前一致。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18caeb0348
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| done = spoken(state.text) | ||
| state = decode(audio, new_stream()) |
There was a problem hiding this comment.
Reconcile the triggering block before appending its replay
With at least four hotwords, a block can contain both real speech and a recitation. For example, RecitingSession returning Hello. {recited} on the first decode and Hello. on replay produces final text Hello. Hello.: this assignment has already retained the current block's speech in done, and spoken() then appends its replay a second time. Preserve the pre-block prefix or reconcile overlapping text before accumulating the replay.
Useful? React with 👍 / 👎.
| if recited.search(state.text): | ||
| state = new_stream() | ||
| heard_speech = False |
There was a problem hiding this comment.
Retain speech from a retry that also contains recitation
With at least four hotwords, if the poisoned stream returns only {recited} but replay recovers Hello. {recited}, this branch discards Hello. along with the recitation. The existing fake-session harness reproduces empty streamed and final output for that case, because done is never updated from the retry and heard_speech = False bypasses finalization. Retain the retry's cleaned speech before replacing its state, with overlap reconciliation.
Useful? React with 👍 / 👎.
| r"[\s,,、]*".join(terms[start:end]) | ||
| for end in range(len(terms), RECITED_PHRASES - 1, -1) | ||
| for start in range(end - RECITED_PHRASES + 1) |
There was a problem hiding this comment.
Bound the recitation matcher's startup complexity
With many short dictionary entries, enumerating every contiguous subsequence produces a cubic-sized regex even though build_asr_prompt caps input at 240 characters. A Python 3.12.3 reproduction with 60 two-character entries (239 prompt characters total) builds a 363,151-character pattern, takes about 9.5 seconds to compile, and peaks at about 170 MiB RSS. This runs before ready on every recording, substantially delaying startup for valid dictionaries. Bound matcher complexity rather than expanding all subsequence lengths.
Useful? React with 👍 / 👎.
摘要
无对应 issue。之前和维护者沟通过,TextStream 目前拿不到词典,词典只在 LLM 润色时生效。
这个 PR 让已启用的词典词条作为 Qwen3-ASR 的
context参与 TextStream 识别,在语音识别这一步就把专有名词写对,而不是全靠后面的润色去补。修复 / 新增 / 改进
asr.prompt(同一排序与字符预算),经环境变量OPENLESS_TEXTSTREAM_CONTEXT交给 worker,再传给init_streaming(context=...)。选区流程清空asr.prompt时不注入;内容为空或不可用时按无词典识别,不影响录音启动。asr.prompt是A, B.,而 mlx-qwen3-asr 文档要求空格分隔。实测逗号列表会诱使解码器在正常语句中接着“续写”词表并丢掉后半句,空格分隔没有出现这种情况,所以 worker 侧转成空格分隔。同时去掉<>:词条里出现<|audio_pad|>之类的写法会被分词成控制 token,导致每次录音失败。context后,没有人声的窗口会让解码器把整段context当作转写输出,且残留在强制前缀里吞掉之后的语音。worker 检测“连续 4 个及以上词条、顺序与词典一致”的片段(按词条计数,多词短语算一个;只匹配完整的词;词条间的标点和空格可以不同),从所有快照中去掉并重启流。触发的那一块音频会在新流里单独再解码一次,以免丢掉恰好在其中开始的语音;仍是背诵才丢弃,并像录音开始时一样等待人声。思路与 textstream-asr 原项目HALLUCINATION_PATTERNS的“检测后重置”一致,只是匹配对象由固定句子换成当前词典。context时,人声很少的 chunk 可能被标成None并强制沿用到之后的窗口,使中文窗口之间多出空格;检测到后重置为未判定。worker.py变了,把 v2.0.2-Beta.4 至 v2.0.3-Beta.3 的 worker 加入PREVIOUS_WORKERS,否则已安装用户升级后会被判为未安装。另外顺手补了 v2.0.2-Beta.1 至 Beta.3 那一版(fix(textstream): 快照前缀被改写时保留权威全文,不再中止整条转写 #1257 改 worker 时漏加),与本功能无关,维护者不需要可以去掉。兼容
docs/development/local-models.md已在上游移除);aoci.code.txt索引(本地没有aoci工具)。beta的 worker 输出逐字相同。.runtime/worker.py,不需要重装运行组件。feed_audio返回后进行;30 秒窗口提交发生在同一次调用内时仍可能把None带入后续窗口。修复需要改库的非公开状态,未做。context是通过系统提示实现的,背诵只能压低不能根除。更彻底的做法是解码时做词表偏置,或由 mlx-qwen3-asr 自身避免解码无人声的窗口,都超出本 PR 范围。beta上同样存在,本 PR 未处理。测试计划
命令:
python3 -B -m unittest discover -s src-tauri/src/asr/local/experimental/textstream -p 'test_*.py'结果:20 个通过(原有 13 个)。新增用例逐个做了反向验证:撤掉对应实现后用例会失败。注意 CI 目前不运行这个文件。
命令:
cargo test --locked --manifest-path src-tauri/Cargo.toml --lib textstream -- --test-threads=1结果:12 通过,2 个原本就标记 ignored。
命令:
npm test结果:通过。
local-asr-lifecycle-contract.test.mjs新增了接线断言,以及 Rust 与 Python 两侧环境变量名一致的检查。真实模型回归(本机已安装的 Qwen3-ASR 0.6B,经 worker 的真实 stdin/stdout 协议):
真实麦克风录音一段(约 100 秒,中英混说,含两次 10 秒停顿和结尾静音),同一段音频对比:
beta,无词典未验证:合成语音之外只有一位说话人的录音;没有覆盖耳语、多人、嘈杂环境;没有做系统性的词错率评测。背诵匹配规则与“再解码一次”是最后一轮修改,只经过上述测试。
证据路径:回归脚本与各场景输出可按需提供。
测试过程中发现的两个与本 PR 无关的问题,另行反馈:debug 构建在启动时于
permissions.rs的authorizationStatusForMediaType:调用处 panic(release 构建不受影响);127.0.0.1:7890被其他程序占用时 TextStream 无法启动。🤖 Generated with Claude Code