Repository navigation
fix(say): 待合成文本改走标准输入与临时文件,不再拼进命令行参数 - #12
Open
modusensus wants to merge 2 commits into
Open
modusensus wants to merge 2 commits into
modusensus wants to merge 2 commits into
Conversation
三处调用点(lib/chat.js 的语音条、lib/index.js 的 say_aloud 工具、 lib/rules-remote.js 面板试听)原本都是 powershell -File say.ps1 -Text <回复>。 PowerShell 在 -File 模式下会把以 "-" 开头的值当作参数名解析,待合成文本 恰好是 "-Text" / "-Out" / "--text" 时直接报 MissingArgument 退出 1。三处 都是 await + try/catch,异常被吞成「语音条生成失败,回退文字」,表现为 没声音但对话照常继续——静默失败。 改法: - 新增 lib/say.js 的 runSay(),统一用 spawn 起 powershell,只传脚本路径 与 -Out,正文经 stdin 写入;带 EPIPE 兜底、超时 kill、退出码与 stderr 透传,并回读脚本报告的产物路径。 - say.ps1 去掉 $Text 的 Mandatory,未给 -Text 时用 StreamReader 按 UTF-8 读标准输入;显式设置 OutputEncoding 为无 BOM UTF-8,否则中文产物路径 经 stdout 回来是乱码;空文本直接 exit 2,不再往下走四层链产出静音。 - 正文落成临时文件供下游 CLI 读取:Tier 0 的 tts-volc.py 增加 --text-file 并把 --text 改为非必填,Tier 2 的 edge-tts 改用 -f;两者都把以 "-" 开头 的文本当作选项,同样会失败。临时文件用 PowerShell.Exiting 事件清理。 - 三处调用点改用 runSay,产物路径以脚本回报的为准。 测试:新增 tests/test-say.mjs(68 条断言),静态钉住三处调用点与 say.ps1 的传输方式,动态用 stub 跑十组恶意文本逐字节比对回读,并验证退出码与 stderr 透传、空文本拒绝、旧 -Text 写法仍兼容;已并入 tests/all.mjs。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
为什么改
say.ps1原来靠命令行-Text <回复>收待合成文本。PowerShell 在-File模式下会把以-开头的值当成参数名解析,所以回复里一旦出现-Text/-Out/--text这类字样,脚本就报:三个调用点(
lib/chat.js的语音条、lib/index.js的say_aloud工具、lib/rules-remote.js的面板试听)都是await+ 外层try/catch,异常被吞成「语音条生成失败,回退文字」——没有声音,但对话照常继续,从外面看不出来。待合成的正好是模型回复,QQ 里对方说的话会进来,内容不由我们决定。
同一个坑在下游还有两处:
tts-volc.py用 argparse、edge-tts用 click,--text -Text同样会被判成缺参数。实测这一路会一路降级到 Windows SAPI——不是没声音,而是悄悄换了音色和引擎。改法
lib/say.js(新增)runSay({ sayScript, text, out }):spawn 起 powershell,只传脚本路径与-Out,正文写 stdin。带 EPIPE 兜底、超时 kill、退出码与 stderr 透传,回读脚本报告的产物路径say.ps1$Text去掉Mandatory;没给-Text时用StreamReader按 UTF-8 读 stdin;显式设OutputEncoding为无 BOM UTF-8;空文本exit 2tts-volc.py--text-file,--text改为非必填;文本按utf-8-sig读edge-tts调用-f $textFilerunSay,产物路径以脚本回报为准(兜底层可能回.wav)两个非显然的点:
[Console]::In走控制台代码页(中文机器是 GBK),调用方按 UTF-8 写入,读出来就是「浣犲ソ」——念出来是一串噪音。正文另外落成一个 UTF-8 临时文件供下游 CLI 读,用
PowerShell.Exiting事件清理,不留垃圾。测试
新增
tests/test-say.mjs(68 条断言),已并入tests/all.mjs(现 11 套)。四组:say.js必须 spawn +-File、无-Command、无-Text、stdio pipe、stdin.end、stdin.on('error')、setTimeout;三个调用点都得有runSay且不得再自己拼 powershell 参数;再按正则扫全lib/兜底。ContainsKey('Text')、OpenStandardInput()、StreamReader+Encoding]::UTF8、IsNullOrWhiteSpace、exit 2、不再是 Mandatory、OutputEncoding是 UTF-8。-Text/--out/-NoProfile -File 这种东西/ 多行 / 引号反斜杠 /$(New-Item x)/ 反引号制表 / emoji 全角 / 3000 字长文本——逐字节比对回读。另测空文本拒绝、bad.ps1 exit 7的报错透传、老写法-Text "..."仍兼容。say.ps1必须用--text-file/-f;tts-volc.py必须有--text-file且--text不再 required;动态验证--text -Text确实被 argparse 拦下(这条记录了我们为什么改走文件)。第 3 组直接 import
lib/say.js调runSay,不是自己复刻一遍调用逻辑——否则测试绿了也不代表生产代码对。变异自证(3 次,均被抓)
say.js把'-Text', text塞回 spawn argvsay.ps1把 StreamReader 退回[Console]::In.ReadToEnd()tts-volc.py把--text改回required=True每次变异后都已还原。
验证
node tests/all.mjs→ 11 套全过(约 40 秒):真机端到端(直调
runSay+ 真say.ps1):普通中文 → Tier 0 火山出 mp3 21357B;文本恰为-Text→ 同样 Tier 0 出 mp3 9837B。改之前这一例会静默降级甚至失败。没做的事
tts-volc.py不在版本库里(.gitignore第 19 行,它是本机的复刻音脚本,不带凭据也跑不了),所以测试里对它只在文件存在时校验。-Text "..."保留兼容,只是不再推荐;文档已改为 stdin 示例。