wechat-clawbot 1.3.4 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/cordis.patch.yml +2 -1
  2. package/lib/bridge.d.ts +11 -0
  3. package/lib/bridge.d.ts.map +1 -1
  4. package/lib/bridge.js +89 -6
  5. package/lib/bridge.js.map +1 -1
  6. package/lib/claude-peer.d.ts +6 -0
  7. package/lib/claude-peer.d.ts.map +1 -1
  8. package/lib/claude-peer.js +21 -0
  9. package/lib/claude-peer.js.map +1 -1
  10. package/lib/client.js +22 -0
  11. package/lib/codex-rpc.js +1 -1
  12. package/lib/config.d.ts +30 -8
  13. package/lib/config.d.ts.map +1 -1
  14. package/lib/config.js +34 -1
  15. package/lib/config.js.map +1 -1
  16. package/lib/inbound.d.ts +22 -1
  17. package/lib/inbound.d.ts.map +1 -1
  18. package/lib/inbound.js +136 -13
  19. package/lib/inbound.js.map +1 -1
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +28 -6
  22. package/lib/index.js.map +1 -1
  23. package/lib/mcp-server.js +1 -1
  24. package/lib/monitor.d.ts +25 -0
  25. package/lib/monitor.d.ts.map +1 -1
  26. package/lib/monitor.js +107 -8
  27. package/lib/monitor.js.map +1 -1
  28. package/lib/onboarding.d.ts +71 -0
  29. package/lib/onboarding.d.ts.map +1 -0
  30. package/lib/onboarding.js +255 -0
  31. package/lib/onboarding.js.map +1 -0
  32. package/lib/prompt.d.ts +6 -2
  33. package/lib/prompt.d.ts.map +1 -1
  34. package/lib/prompt.js +63 -14
  35. package/lib/prompt.js.map +1 -1
  36. package/lib/schedule-migrate.d.ts +97 -7
  37. package/lib/schedule-migrate.d.ts.map +1 -1
  38. package/lib/schedule-migrate.js +96 -16
  39. package/lib/schedule-migrate.js.map +1 -1
  40. package/lib/voice-setup.d.ts +90 -0
  41. package/lib/voice-setup.d.ts.map +1 -0
  42. package/lib/voice-setup.js +289 -0
  43. package/lib/voice-setup.js.map +1 -0
  44. package/lib/voice.d.ts +182 -0
  45. package/lib/voice.d.ts.map +1 -0
  46. package/lib/voice.js +639 -0
  47. package/lib/voice.js.map +1 -0
  48. package/native/macos-speech/main.swift +198 -0
  49. package/package.json +5 -2
  50. package/wechat-clawbot-INSTALL.md +50 -9
@@ -0,0 +1,289 @@
1
+ import { defineTool } from "@deepseek-ai/dsh-tools";
2
+ import { logger } from "./ilink/util/logger.js";
3
+ import { hostSpeechStatus, sharedSpeechHelper, voicePlatformSupported, VOICE_SETUP_PHRASE, } from "./voice.js";
4
+ /** DSH's optional bundle that brings the speech service and its local recognizer. */
5
+ export const VOICE_BUNDLE = "@deepseek-ai/dsh-experimental-voice-input-bundle";
6
+ export const VOICE_TOOL = "enable_voice_input";
7
+ /** By hand, for when the bot cannot do it. */
8
+ export const VOICE_BY_HAND = "在电脑的 DSH 网页里点左边的「插件」,打开「语音输入」,再点「下载并准备」";
9
+ function service(ctx, name) {
10
+ try {
11
+ return ctx.get(name);
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ }
17
+ /** DSH's speech recognition, when the owner has it switched on. */
18
+ export function hostSpeech(ctx) {
19
+ return service(ctx, "speechToText");
20
+ }
21
+ let macCache = null;
22
+ /** Whether this Mac's own models can transcribe `language` (asked of the helper; remembered for a minute). */
23
+ async function macReadiness(language) {
24
+ if (!voicePlatformSupported())
25
+ return "unsupported";
26
+ if (macCache !== null && macCache.language === language && Date.now() - macCache.at < 60_000)
27
+ return macCache.value;
28
+ let value = "unavailable";
29
+ try {
30
+ const status = await sharedSpeechHelper().status(language);
31
+ value = status.ok === true && typeof status.engine === "string" ? "ready" : "unavailable";
32
+ }
33
+ catch {
34
+ value = "unavailable";
35
+ }
36
+ macCache = { at: Date.now(), language, value };
37
+ return value;
38
+ }
39
+ /** Where voice stands on this machine right now. */
40
+ export async function voiceStatus(deps) {
41
+ const host = hostSpeechStatus(hostSpeech(deps.ctx));
42
+ const mac = await (deps.macReady ?? (() => macReadiness(deps.config.voiceLanguage || "zh-CN")))();
43
+ const on = deps.config.voiceTranscribe !== false;
44
+ return { engine: !on ? null : host.state === "ready" ? "dsh" : mac === "ready" ? "mac" : null, host, mac, on };
45
+ }
46
+ /** One line on where voice stands, for the bot to pass on. */
47
+ export function describeVoice(status) {
48
+ if (!status.on)
49
+ return "插件里的「语音没带文字时在本机转写」开关关着,所以听不了没带文字的语音。";
50
+ if (status.engine === "dsh") {
51
+ return `能听语音:用的是 DSH 的「语音输入」(${status.host.state === "absent" ? "" : status.host.name},${status.host.state !== "absent" && !status.host.local ? "云端" : "在这台电脑上运行"})。`;
52
+ }
53
+ const hostLine = status.host.state === "absent"
54
+ ? "DSH 的「语音输入」没开"
55
+ : status.host.state === "preparing"
56
+ ? "DSH 的「语音输入」开着,语音识别模型正在下载或加载"
57
+ : status.host.state === "failed"
58
+ ? `DSH 的「语音输入」开着,但模型没准备成${status.host.message ? `(${status.host.message})` : ""}`
59
+ : "DSH 的「语音输入」开着,但语音识别模型还没下载";
60
+ if (status.engine === "mac")
61
+ return `能听语音:用的是这台 Mac 自带的转写(${hostLine};打开它一般更准,中英文夹着说也认得更好)。`;
62
+ return `还听不了没带文字的语音:${hostLine}${status.mac === "unsupported" ? "" : ",这台 Mac 自带的转写也用不了"}。`;
63
+ }
64
+ /**
65
+ * A plain yes to "shall I switch it on?". Anything else is a no — a bare
66
+ * 嗯 / 是 / 对 too, which on WeChat is often just "I'm reading".
67
+ */
68
+ export function isPlainYes(reply) {
69
+ if (reply === null)
70
+ return false;
71
+ return /^\s*(好|好的|好啊|好呀|可以|行|行的|确认|同意|没问题|打开|打开吧|开吧|ok|okay|yes|y)\s*[。.!!~]*\s*$/i.test(reply);
72
+ }
73
+ /** What the owner is asked before DSH is changed. Sent as written. */
74
+ export function consentQuestion(host) {
75
+ if (host.state === "absent") {
76
+ return [
77
+ "要我替你打开 DSH 的「语音输入」吗?打开后你发的语音就能在这台电脑上转成文字。它是 DSH 自带的插件(标着「实验性」),打开意味着:",
78
+ "· 下载一个约 240 MB 的语音识别模型,只下一次",
79
+ "· 语音只在这台电脑上处理,不上传",
80
+ "· DSH 网页的输入框旁边会多一个麦克风按钮",
81
+ "· 不想要了,随时可以在 DSH 网页的「插件」里关掉",
82
+ "回「好」我就打开,回别的我就不动。",
83
+ ].join("\n");
84
+ }
85
+ return "DSH 的「语音输入」已经开着,但语音识别模型还没下载好。要我现在下载吗?约 240 MB,只下一次,下好后语音就在这台电脑上转成文字,不上传。回「好」就开始,回别的我就不动。";
86
+ }
87
+ function megabytes(bytes) {
88
+ return `${Math.round(bytes / 1024 / 1024)} MB`;
89
+ }
90
+ function progress(host) {
91
+ if (host.state === "absent" || host.completedBytes === undefined)
92
+ return "";
93
+ return host.totalBytes !== undefined && host.totalBytes > 0
94
+ ? `(已下载 ${megabytes(host.completedBytes)} / ${megabytes(host.totalBytes)})`
95
+ : `(已下载 ${megabytes(host.completedBytes)})`;
96
+ }
97
+ const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
98
+ /** For the long watch of a download: it must not keep a process alive that has nothing else to do. */
99
+ const idle = (ms) => new Promise((resolve) => { setTimeout(resolve, ms).unref?.(); });
100
+ /** One watcher per process, however many times the owner asks. */
101
+ let watching = false;
102
+ /**
103
+ * Follow the model's download to its end and tell the owner how it went.
104
+ * Quiet when someone switches the bundle off meanwhile.
105
+ */
106
+ function watchPreparation(deps) {
107
+ if (watching)
108
+ return;
109
+ watching = true;
110
+ const pollMs = deps.pollMs ?? 3000;
111
+ const deadline = Date.now() + (deps.watchMs ?? 60 * 60_000);
112
+ void (async () => {
113
+ try {
114
+ for (;;) {
115
+ await idle(pollMs);
116
+ const host = hostSpeechStatus(hostSpeech(deps.ctx));
117
+ if (host.state === "absent")
118
+ return;
119
+ if (host.state === "ready") {
120
+ logger.info(`voice-setup: DSH's ${host.name} is ready`);
121
+ await deps.tellOwner("语音识别准备好了。现在发语音,我就能听了。");
122
+ return;
123
+ }
124
+ if (host.state === "failed") {
125
+ logger.warn(`voice-setup: DSH's ${host.name} did not get ready (${host.message ?? "no reason given"})`);
126
+ await deps.tellOwner(`语音识别模型没准备成${host.message ? `(${host.message})` : ""}。再跟我说一次「${VOICE_SETUP_PHRASE}」可以重试;`
127
+ + "也可以在电脑的 DSH 网页里点「插件」→「语音输入」,换一个下载源再试。");
128
+ return;
129
+ }
130
+ if (Date.now() > deadline) {
131
+ await deps.tellOwner(`语音识别模型下载了很久还没好${progress(host)}。可以在电脑的 DSH 网页里点「插件」→「语音输入」看看卡在哪一步。`);
132
+ return;
133
+ }
134
+ }
135
+ }
136
+ catch (err) {
137
+ logger.warn(`voice-setup: stopped watching the model's download: ${String(err.message ?? err).slice(0, 200)}`);
138
+ }
139
+ finally {
140
+ watching = false;
141
+ }
142
+ })();
143
+ }
144
+ /** Only the owner changes this machine; the desktop (no WeChat sender) is the owner too. */
145
+ function notOwner(deps) {
146
+ const owner = deps.getAccount()?.userId;
147
+ if (owner === undefined || owner === "")
148
+ return "不知道机主是谁(登录信息里没有用户 id),这件事做不了。重新扫码登录一次再试。";
149
+ const sender = deps.activeSender();
150
+ if (sender !== undefined && sender !== owner)
151
+ return "打开语音识别要改这台电脑上的 DSH,只有机主能决定。请机主自己来说。";
152
+ return undefined;
153
+ }
154
+ /**
155
+ * Switch DSH's speech recognition on for the owner and get its model, after
156
+ * asking them. Returns what to tell them now; the end of the download is told
157
+ * later by `tellOwner`.
158
+ */
159
+ export async function enableVoiceInput(deps, signal) {
160
+ const refused = notOwner(deps);
161
+ if (refused !== undefined)
162
+ return { ok: false, summary: refused };
163
+ let host = hostSpeechStatus(hostSpeech(deps.ctx));
164
+ if (host.state === "ready") {
165
+ return { ok: true, summary: `DSH 的「语音输入」已经可以用了(${host.name}),不用再设置。让用户直接发语音试试。` };
166
+ }
167
+ if (host.state === "preparing") {
168
+ watchPreparation(deps);
169
+ return { ok: true, summary: `语音识别模型正在下载或加载${progress(host)},好了会有一条消息告诉用户。在那之前发的语音还听不了。` };
170
+ }
171
+ // Find out whether it can be done at all before asking whether it should be.
172
+ const manager = host.state === "absent" ? service(deps.ctx, "pluginManager") : undefined;
173
+ if (host.state === "absent" && (manager === undefined || typeof manager.setBundleEnabled !== "function")) {
174
+ return { ok: false, summary: `这个版本的 DSH 不让我替用户打开插件,得用户自己来:${VOICE_BY_HAND}。弄好后再发语音就行。` };
175
+ }
176
+ const answer = await deps.askOwner(consentQuestion(host), signal);
177
+ if (answer.status !== "answered") {
178
+ const why = answer.status === "undelivered"
179
+ ? `问题没发出去(${answer.detail ?? "原因不明"})`
180
+ : answer.status === "timeout" ? "用户一直没回" : answer.status === "stopped" ? "这一轮被停下了" : "不知道机主是谁";
181
+ return { ok: false, summary: `没有打开语音输入:${why}。什么都没改。` };
182
+ }
183
+ if (!isPlainYes(answer.reply)) {
184
+ return { ok: false, summary: `用户没有同意(回的是「${answer.reply.slice(0, 40)}」),什么都没改。不要再追问;他想自己弄的话,做法是:${VOICE_BY_HAND}。` };
185
+ }
186
+ if (host.state === "absent" && manager !== undefined) {
187
+ let application = "";
188
+ try {
189
+ const result = await manager.setBundleEnabled(VOICE_BUNDLE, true);
190
+ application = String(result?.application ?? "");
191
+ if (application === "failed" || application === "cancelled" || application === "overridden") {
192
+ const detail = result?.error?.message;
193
+ throw new Error(`${application}${typeof detail === "string" ? `: ${detail}` : ""}`);
194
+ }
195
+ }
196
+ catch (err) {
197
+ const detail = String(err.message ?? err).slice(0, 160);
198
+ logger.warn(`voice-setup: could not switch the voice-input bundle on (${detail})`);
199
+ return { ok: false, summary: `没打开成(${detail})。请用户自己来:${VOICE_BY_HAND}。` };
200
+ }
201
+ logger.info(`voice-setup: switched DSH's voice-input bundle on at the owner's word (${application || "applied"})`);
202
+ if (application === "restart-required") {
203
+ return { ok: true, summary: `已经替用户选上了 DSH 的「语音输入」,但这台 DSH 要重启一次才生效。请用户重启 DSH,然后再说一次「${VOICE_SETUP_PHRASE}」,我接着下载模型。` };
204
+ }
205
+ // The bundle's plugins start a moment after the change is saved.
206
+ const until = Date.now() + (deps.appearMs ?? 20_000);
207
+ while (host.state === "absent" && Date.now() < until) {
208
+ await sleep(Math.min(250, deps.pollMs ?? 250));
209
+ host = hostSpeechStatus(hostSpeech(deps.ctx));
210
+ }
211
+ if (host.state === "absent") {
212
+ return { ok: true, summary: `「语音输入」已经打开,但语音识别服务还没起来。过一会儿让用户再说一次「${VOICE_SETUP_PHRASE}」,或者自己到 DSH 网页的「插件」→「语音输入」里点「下载并准备」。` };
213
+ }
214
+ }
215
+ if (host.state === "ready") {
216
+ return { ok: true, summary: "已经打开,模型以前就下载过,语音识别现在就能用。让用户发一条语音试试。" };
217
+ }
218
+ if (host.state === "unprepared" || host.state === "failed") {
219
+ const speech = hostSpeech(deps.ctx);
220
+ if (speech === undefined || typeof speech.prepare !== "function") {
221
+ return { ok: true, summary: "「语音输入」已经打开,但模型要用户自己点一下才会下载:在电脑的 DSH 网页里点「插件」→「语音输入」→「下载并准备」。" };
222
+ }
223
+ try {
224
+ speech.prepare(host.providerId);
225
+ }
226
+ catch (err) {
227
+ const detail = String(err.message ?? err).slice(0, 160);
228
+ logger.warn(`voice-setup: could not start the model's download (${detail})`);
229
+ return { ok: false, summary: `「语音输入」已经打开,但模型的下载没能开始(${detail})。请用户在电脑的 DSH 网页里点「插件」→「语音输入」→「下载并准备」。` };
230
+ }
231
+ logger.info(`voice-setup: started the download of DSH's ${host.name}`);
232
+ }
233
+ watchPreparation(deps);
234
+ return { ok: true, summary: "已经打开,语音识别模型正在下载(约 240 MB)。下载好了会有一条消息告诉用户;在那之前发的语音我还听不了。告诉用户这两点,不要说已经能听语音了。" };
235
+ }
236
+ const SUMMARY_SCHEMA = {
237
+ type: "object",
238
+ additionalProperties: false,
239
+ properties: { ok: { type: "boolean", required: true }, summary: { type: "string", required: true } },
240
+ };
241
+ /** Register `enable_voice_input` on the WeChat agent. */
242
+ export function registerVoiceSetupTools(agentCtx, deps) {
243
+ agentCtx.tools.register(defineTool({
244
+ name: VOICE_TOOL,
245
+ description: "Make voice messages work on this computer by switching on DSH's own speech recognition (语音输入) for the owner and "
246
+ + "downloading its model. Use it when the owner says 打开语音输入, asks you to be able to hear voice messages, "
247
+ + "or reaches the voice item of the first-time setup. Call it straight away: the tool itself sends the owner a "
248
+ + "fixed question that says exactly what will change (a DSH plugin goes on, about 240 MB is downloaded, audio stays "
249
+ + "on the computer) and waits for their answer, so do NOT ask for permission first and do NOT describe it yourself "
250
+ + "beforehand — that would ask them twice. Nothing is changed unless they answer with a plain yes. Afterwards tell "
251
+ + "them what the result says, no more: when the model is still downloading, voice does not work yet, and a "
252
+ + "separate message will tell them when it does.",
253
+ parameters: {},
254
+ output: { schema: SUMMARY_SCHEMA, render: (_args, value) => [{ type: "text", text: value.summary }] },
255
+ async execute(_args, exec) {
256
+ try {
257
+ return await enableVoiceInput(deps, exec?.signal);
258
+ }
259
+ catch (err) {
260
+ logger.warn(`voice-setup: failed: ${String(err.message ?? err).slice(0, 200)}`);
261
+ return { ok: false, summary: `没有弄成(${String(err.message ?? err).slice(0, 120)})。请用户自己来:${VOICE_BY_HAND}。` };
262
+ }
263
+ },
264
+ }));
265
+ }
266
+ /**
267
+ * One line in the log at start: what a voice message without WeChat's text
268
+ * would be transcribed with, and whether the bot could switch DSH's speech
269
+ * recognition on. The first thing to read when voice does not work.
270
+ */
271
+ export async function logVoiceSetup(deps) {
272
+ try {
273
+ const status = await voiceStatus(deps);
274
+ const manager = service(deps.ctx, "pluginManager");
275
+ const can = manager !== undefined && typeof manager.setBundleEnabled === "function";
276
+ const host = status.host.state === "absent" ? "not switched on" : `${status.host.name} ${status.host.phase}`;
277
+ logger.info(`voice: without WeChat's transcript -> ${status.engine === "dsh" ? "DSH's speech recognition" : status.engine === "mac" ? "this Mac's own models" : "nothing can transcribe"}`
278
+ + ` (DSH 语音输入: ${host}; this Mac: ${status.mac}; the bot ${can ? "can" : "cannot"} switch 语音输入 on)`);
279
+ }
280
+ catch (err) {
281
+ logger.warn(`voice: could not read the voice setup: ${String(err.message ?? err).slice(0, 160)}`);
282
+ }
283
+ }
284
+ /** Tests start each case with no watcher left over. */
285
+ export function resetVoiceSetupForTests() {
286
+ watching = false;
287
+ macCache = null;
288
+ }
289
+ //# sourceMappingURL=voice-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice-setup.js","sourceRoot":"","sources":["../src/voice-setup.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIpD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,kBAAkB,GAEjF,MAAM,YAAY,CAAC;AAEpB,qFAAqF;AACrF,MAAM,CAAC,MAAM,YAAY,GAAG,kDAAkD,CAAC;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAE/C,8CAA8C;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,yCAAyC,CAAC;AAkCvE,SAAS,OAAO,CAAI,GAAyB,EAAE,IAAY;IACzD,IAAI,CAAC;QACH,OAAQ,GAAG,CAAC,GAAgC,CAAC,IAAI,CAAkB,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,GAAyB;IAClD,OAAO,OAAO,CAAa,GAAG,EAAE,cAAc,CAAC,CAAC;AAClD,CAAC;AAED,IAAI,QAAQ,GAAuE,IAAI,CAAC;AAExF,8GAA8G;AAC9G,KAAK,UAAU,YAAY,CAAC,QAAgB;IAC1C,IAAI,CAAC,sBAAsB,EAAE;QAAE,OAAO,aAAa,CAAC;IACpD,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,EAAE,GAAG,MAAM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CAAC,IAAI,CACT,yCAAyC,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,wBAAwB,EAAE;cAC5K,eAAe,IAAI,eAAe,MAAM,CAAC,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,kBAAkB,CACpG,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,0CAA0C,MAAM,CAAE,GAAa,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/G,CAAC;AACH,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,uBAAuB;IACrC,QAAQ,GAAG,KAAK,CAAC;IACjB,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC"}
package/lib/voice.d.ts ADDED
@@ -0,0 +1,182 @@
1
+ import type { MessageItem } from "./ilink/api/types.js";
2
+ /** Why a voice message got no transcript. */
3
+ export type VoiceFailure =
4
+ /** The setting is off. */
5
+ "off"
6
+ /** Nothing on this machine can transcribe: DSH's speech recognition is not switched on, and this is not a Mac with the on-device models. */
7
+ | "no-engine"
8
+ /** DSH's speech recognition is switched on, but its model is not on disk yet (or is on its way). */
9
+ | "host-unprepared"
10
+ /** The item has no audio to fetch. */
11
+ | "no-media" | "download" | "decode"
12
+ /** No Xcode command line tools to compile the helper with. */
13
+ | "tools" | "build"
14
+ /** No on-device model for the language on this Mac. */
15
+ | "language" | "failed"
16
+ /** Transcribed, and nothing was said (or nothing was understood). */
17
+ | "empty";
18
+ export type VoiceOutcome = {
19
+ ok: true;
20
+ text: string;
21
+ engine: string;
22
+ } | {
23
+ ok: false;
24
+ reason: VoiceFailure;
25
+ detail?: string;
26
+ host?: HostSpeechStatus["state"];
27
+ };
28
+ /** As much of DSH's speech recognition service (`ctx.speechToText`) as is used here. */
29
+ export type HostSpeech = {
30
+ snapshot(): {
31
+ providers: ReadonlyArray<{
32
+ id: string;
33
+ name?: string;
34
+ location?: string;
35
+ preparation?: {
36
+ phase?: string;
37
+ message?: string;
38
+ completedBytes?: number;
39
+ totalBytes?: number;
40
+ };
41
+ }>;
42
+ selection?: {
43
+ providerId?: string;
44
+ language?: string;
45
+ };
46
+ };
47
+ /** Pins the selected recognizer for one recording: a canonical 16 kHz mono 16-bit WAV. */
48
+ resolve(request: {
49
+ audio: Uint8Array;
50
+ }): unknown;
51
+ transcribe(spec: unknown, signal: AbortSignal): Promise<{
52
+ text?: unknown;
53
+ }>;
54
+ /** Start (or join) the download of the recognizer's model. */
55
+ prepare?(id: string, options?: unknown): void;
56
+ };
57
+ /** Where DSH's speech recognition stands. */
58
+ export type HostSpeechStatus =
59
+ /** The 语音输入 bundle is not switched on (or this DSH has none). */
60
+ {
61
+ state: "absent";
62
+ } | {
63
+ /** ready: can transcribe now. preparing: the model is being fetched or loaded. unprepared: no model yet. */
64
+ state: "ready" | "preparing" | "unprepared" | "failed";
65
+ providerId: string;
66
+ name: string;
67
+ phase: string;
68
+ /** Whether the recognizer runs on this machine (false: the owner configured a cloud one in DSH). */
69
+ local: boolean;
70
+ message?: string;
71
+ completedBytes?: number;
72
+ totalBytes?: number;
73
+ };
74
+ /** Read DSH's speech recognition without trusting it to be there or to be the version this was written against. */
75
+ export declare function hostSpeechStatus(speech: HostSpeech | undefined): HostSpeechStatus;
76
+ /** True for a voice item WeChat sent without its transcript. */
77
+ export declare function voiceLacksTranscript(item: MessageItem | undefined): boolean;
78
+ /** Whether this machine can transcribe at all (a Mac on macOS 26 or later). */
79
+ export declare function voicePlatformSupported(platform?: string, release?: string): boolean;
80
+ /**
81
+ * A transcript as a person would have typed it. The newer speech model sets
82
+ * Chinese apart with spaces of its own ("下午 3:00提醒我 ,然后"); none belongs
83
+ * next to a Chinese character or Chinese punctuation. Spaces between words in
84
+ * another script are left alone.
85
+ */
86
+ export declare function tidyTranscript(text: string): string;
87
+ /** 16-bit little-endian PCM (mono unless told otherwise) in a WAV container. */
88
+ export declare function pcmToWav(pcm: Uint8Array, sampleRate: number, channels?: number): Buffer;
89
+ export type AudioKind = "silk" | "opus-raw" | "wav" | "mp3" | "m4a" | "amr" | "unknown";
90
+ /** What the downloaded bytes are, by their first bytes (the item's encode_type is not always filled in). */
91
+ export declare function sniffAudio(buf: Buffer): AudioKind;
92
+ /**
93
+ * WeChat's `#!OPUS_RAW_V1` voice as 16-bit PCM with the channel count its
94
+ * header names, at `outputRate` (Opus decodes to any of its rates; default:
95
+ * the rate the header names).
96
+ */
97
+ export declare function decodeOpusRaw(buf: Buffer, outputRate?: number): Promise<{
98
+ pcm: Buffer;
99
+ sampleRate: number;
100
+ channels: number;
101
+ }>;
102
+ /** Two interleaved 16-bit channels averaged into one. */
103
+ export declare function stereoToMono(pcm: Buffer): Buffer;
104
+ /** True for exactly the WAV DSH's recognizer takes: a 44-byte header, PCM, mono, 16 kHz, 16-bit, lengths that add up. */
105
+ export declare function isCanonicalWav(buf: Buffer): boolean;
106
+ /**
107
+ * The audio as a file a speech model can open: its bytes, the extension to
108
+ * save them under, and whether it is the canonical WAV (16 kHz, mono, 16-bit)
109
+ * that DSH's recognizer takes. WeChat's own two formats always come out that way.
110
+ */
111
+ export declare function playableAudio(buf: Buffer): Promise<{
112
+ bytes: Buffer;
113
+ ext: string;
114
+ canonical: boolean;
115
+ }>;
116
+ /** Builds `clawbot-speech` on first use and runs it. */
117
+ export declare class SpeechHelper {
118
+ private readonly root;
119
+ private readonly source;
120
+ private building;
121
+ private buildFailure;
122
+ constructor(root?: string, source?: string);
123
+ get exePath(): string;
124
+ private fingerprint;
125
+ /** Whether the helper exists and was built from the current source. */
126
+ isBuilt(): boolean;
127
+ /**
128
+ * Compile the helper when it is missing or the plugin's Swift source changed.
129
+ * No permission hangs on this binary, so a stale one is simply replaced; when
130
+ * the rebuild fails, the old one goes on working.
131
+ */
132
+ ensureBuilt(): Promise<void>;
133
+ private build;
134
+ /** Run one helper command and read its JSON answer. */
135
+ run(args: readonly string[], timeoutMs: number): Promise<Record<string, unknown>>;
136
+ /** What this Mac can transcribe `language` with, without transcribing anything. */
137
+ status(language: string): Promise<Record<string, unknown>>;
138
+ /**
139
+ * Have macOS download the newer speech model's pack for `language` (a few
140
+ * hundred megabytes from Apple). Only ever on the owner's word; transcribing
141
+ * never calls this.
142
+ */
143
+ install(language: string): Promise<Record<string, unknown>>;
144
+ /** Transcribe one audio file. */
145
+ transcribe(file: string, language: string, timeoutMs?: number): Promise<VoiceOutcome>;
146
+ }
147
+ export declare function sharedSpeechHelper(): SpeechHelper;
148
+ /**
149
+ * Compile the helper ahead of the first voice message that needs it, so that
150
+ * message waits for a transcript and not for a compiler. Once per process, a
151
+ * little after start, and quietly: a Mac without the tools just goes without.
152
+ */
153
+ export declare function prewarmSpeechHelper(delayMs?: number): void;
154
+ export type VoiceDeps = {
155
+ cdnBaseUrl: string;
156
+ /** BCP 47 tag of the language people speak to the bot in. */
157
+ language: string;
158
+ helper: SpeechHelper;
159
+ /** DSH's speech recognition, looked up per message: the owner can switch it on or off while DSH runs. */
160
+ hostSpeech?: () => HostSpeech | undefined;
161
+ /** Tests stand in for the CDN and the platform. */
162
+ download?: (item: MessageItem) => Promise<Buffer>;
163
+ downloadTimeoutMs?: number;
164
+ platformSupported?: () => boolean;
165
+ };
166
+ /**
167
+ * Transcribe a voice item on this machine: DSH's speech recognition when it is
168
+ * ready, else this Mac's own. Never throws. For the Mac's helper the audio is
169
+ * written to a private temporary folder and removed afterwards; DSH's
170
+ * recognizer takes it from memory.
171
+ */
172
+ export declare function transcribeVoiceItem(item: MessageItem, deps: VoiceDeps): Promise<VoiceOutcome>;
173
+ /** What the bot answers to when asked to switch DSH's speech recognition on (voice-setup.ts). */
174
+ export declare const VOICE_SETUP_PHRASE = "\u6253\u5F00\u8BED\u97F3\u8F93\u5165";
175
+ /**
176
+ * What to tell the sender when a voice message has no transcript from either
177
+ * side. Says it is a voice message (it used to be called a video), why there
178
+ * is no text, and what to do — above all how to get voice working: DSH's own
179
+ * 语音输入, which the bot can switch on for the owner.
180
+ */
181
+ export declare function voiceNotice(outcome: VoiceOutcome | undefined): string;
182
+ //# sourceMappingURL=voice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice.d.ts","sourceRoot":"","sources":["../src/voice.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKxD,6CAA6C;AAC7C,MAAM,MAAM,YAAY;AACtB,0BAA0B;AACxB,KAAK;AACP,4IAA4I;GAC1I,WAAW;AACb,oGAAoG;GAClG,iBAAiB;AACnB,sCAAsC;GACpC,UAAU,GACV,UAAU,GACV,QAAQ;AACV,8DAA8D;GAC5D,OAAO,GACP,OAAO;AACT,uDAAuD;GACrD,UAAU,GACV,QAAQ;AACV,qEAAqE;GACnE,OAAO,CAAC;AAEZ,MAAM,MAAM,YAAY,GACpB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC;AAE3F,wFAAwF;AACxF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,IAAI;QACV,SAAS,EAAE,aAAa,CAAC;YACvB,EAAE,EAAE,MAAM,CAAC;YACX,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,WAAW,CAAC,EAAE;gBAAE,KAAK,CAAC,EAAE,MAAM,CAAC;gBAAC,OAAO,CAAC,EAAE,MA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