dsh-voice-mode 0.7.39 → 0.7.40

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.
@@ -20,7 +20,11 @@ function createSenseWorkerClient(worker) {
20
20
  if (!p) return;
21
21
  pending.delete(msg.id);
22
22
  if (!msg.ok) {
23
- p.resolve(null);
23
+ if (p.op === "create") {
24
+ p.reject(new Error(msg.error ?? "sense worker create failed"));
25
+ } else {
26
+ p.resolve(null);
27
+ }
24
28
  return;
25
29
  }
26
30
  p.resolve(p.op === "create" ? true : msg.text ?? "");
@@ -94,7 +94,7 @@ process.on("message", (msg) => {
94
94
  }
95
95
  if (msg.type === "synth") {
96
96
  const text = sanitizeForTts(
97
- String(msg.text ?? "").replace(/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}\u{2190}-\u{21FF}\u{2B00}-\u{2BFF}]/gu, " ").replace(/(\d)[..]\s*/g, "$1\u3001")
97
+ String(msg.text ?? "").replace(/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}\u{2190}-\u{21FF}\u{2B00}-\u{2BFF}]/gu, " ").replace(/(\d)[..](?!\d)\s*/g, "$1\u3001")
98
98
  );
99
99
  if (!text.trim()) {
100
100
  const sr = 24e3;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-voice-mode",
3
3
  "description": "Voice plugin for DeepSeek Harness: local streaming speech recognition into editable drafts, sentence-by-sentence read-aloud with captions, and voice interruption. Edge online or local VITS/Kokoro TTS; host compatibility is bounded by engines.dsh.",
4
4
  "icon": "./icon.svg",
5
- "version": "0.7.39",
5
+ "version": "0.7.40",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
8
8
  "repository": {
@@ -104,7 +104,7 @@
104
104
  "@types/react": "^19.3.0",
105
105
  "esbuild": "^0.28.2",
106
106
  "msedge-tts": "^2.1.1",
107
- "playwright-core": "1.65.0",
107
+ "playwright-core": "1.65.1",
108
108
  "typescript": "^5.9.2"
109
109
  },
110
110
  "keywords": [
@@ -67,6 +67,25 @@ const MODELS = {
67
67
  const HOST_PRIMARY = 'https://huggingface.co'
68
68
  const HOST_FALLBACK = 'https://hf-mirror.com'
69
69
 
70
+ // Kokoro revision 必须与 src/tts-local.ts 的 kokoroSpec 一致:上游 main 会替换同名文件,
71
+ // 不锁 revision 时首轮单文件下载与树枚举都会校验失败(E0 报告 2026-11-18)。
72
+ const KOKORO_REPOS = [
73
+ {
74
+ repo: 'csukuangfj/kokoro-int8-multi-lang-v1_1',
75
+ rev: '155831f1b4ba23b1f5c058be6a61df90cefb2a37',
76
+ main: 'model.int8.onnx',
77
+ sha: 'bda15858163726a492d02a9a727bc263551b86ac77f90812c4b30ff41d380e26',
78
+ },
79
+ {
80
+ repo: 'csukuangfj/kokoro-multi-lang-v1_1',
81
+ rev: '914313412b607d95400bcd12446233fbd1248801',
82
+ main: 'model.onnx',
83
+ sha: 'acc4adc175b9d9986106cd20060329673ad5a2e12ef3c557d2d3745b694f8b38',
84
+ },
85
+ ]
86
+ const MODEL_REVS = Object.fromEntries(KOKORO_REPOS.map((k) => [k.repo, k.rev]))
87
+ const encodeRelPath = (rel) => rel.split('/').map(encodeURIComponent).join('/')
88
+
70
89
  const defaultCacheDir = () =>
71
90
  process.platform === 'win32'
72
91
  ? join(process.env.LOCALAPPDATA ?? join(homedir(), 'AppData', 'Local'), 'dsh-voice-mode', 'models')
@@ -100,8 +119,10 @@ async function downloadFile(repo, repoDir, file, expectedSha) {
100
119
  // 子目录文件(如 espeak-ng-data/phontab):确保父目录存在再写流。
101
120
  await mkdir(join(repoDir, file.includes('/') ? file.slice(0, file.lastIndexOf('/')) : ''), { recursive: true }).catch(() => undefined)
102
121
  const partSt = await stat(partPath).catch(() => null)
122
+ const rev = MODEL_REVS[repo] ?? 'main'
123
+ const encodedFile = encodeRelPath(file)
103
124
  for (const host of [HOST_PRIMARY, HOST_FALLBACK]) {
104
- const url = `${host}/${repo}/resolve/main/${file}`
125
+ const url = `${host}/${repo}/resolve/${rev}/${encodedFile}`
105
126
  const headers = { 'user-agent': 'dsh-voice-mode/prefetch' }
106
127
  const resumeFrom = partSt?.size ?? 0
107
128
  if (resumeFrom > 0) headers.range = `bytes=${resumeFrom}-`
@@ -164,11 +185,8 @@ for (const [repo, files] of Object.entries(MODELS)) {
164
185
 
165
186
  // --- Kokoro 中英朗读模型:文件多(含 espeak-ng-data 全目录),走 HF 树枚举批量下载。
166
187
  // int8(默认,CPU 友好)与 fp32(音质更好)两档,主模型文件不同、支持文件同源。 ---
167
- for (const kokoro of [
168
- { repo: 'csukuangfj/kokoro-int8-multi-lang-v1_1', main: 'model.int8.onnx', sha: 'bda15858163726a492d02a9a727bc263551b86ac77f90812c4b30ff41d380e26' },
169
- { repo: 'csukuangfj/kokoro-multi-lang-v1_1', main: 'model.onnx', sha: 'acc4adc175b9d9986106cd20060329673ad5a2e12ef3c557d2d3745b694f8b38' },
170
- ]) {
171
- const { repo, main, sha } = kokoro
188
+ for (const kokoro of KOKORO_REPOS) {
189
+ const { repo, main, sha, rev } = kokoro
172
190
  const repoDir = join(cacheDir, repo)
173
191
  const SENTINELS = {
174
192
  [main]: sha,
@@ -181,13 +199,26 @@ for (const kokoro of [
181
199
  const sentinelOk = await Promise.all(Object.entries(SENTINELS).map(async ([f, sha2]) => (await sha256OfFile(join(repoDir, f)).catch(() => '')) === sha2))
182
200
  if (!sentinelOk.every(Boolean)) {
183
201
  console.log(`Kokoro 模型(${repo}):文件不全,走 HF 树枚举下载`)
184
- const treeRes = await fetch(`${HOST_FALLBACK}/api/models/${repo}/tree/main?recursive=true`, { headers: { 'user-agent': 'dsh-voice-mode/prefetch' } })
185
- if (treeRes.ok) {
186
- const tree = await treeRes.json()
202
+ let tree = null
203
+ let treeHost = HOST_FALLBACK
204
+ for (const host of [HOST_PRIMARY, HOST_FALLBACK]) {
205
+ try {
206
+ const treeRes = await fetch(`${host}/api/models/${repo}/tree/${rev}?recursive=true`, { headers: { 'user-agent': 'dsh-voice-mode/prefetch' } })
207
+ if (treeRes.ok) {
208
+ tree = await treeRes.json()
209
+ treeHost = host
210
+ break
211
+ }
212
+ } catch {
213
+ // 换下一个镜像
214
+ }
215
+ }
216
+ if (tree) {
187
217
  const files = (tree ?? []).map((x) => x.path).filter((p) => !p.endsWith('/') && !['.gitattributes', 'README.md', 'LICENSE'].includes(p))
188
218
  await mkdir(repoDir, { recursive: true })
189
219
  let doneCount = 0
190
220
  const queue = [...files]
221
+ const hostOrder = treeHost === HOST_PRIMARY ? [HOST_PRIMARY, HOST_FALLBACK] : [HOST_FALLBACK, HOST_PRIMARY]
191
222
  async function worker() {
192
223
  for (;;) {
193
224
  const rel = queue.shift()
@@ -196,24 +227,33 @@ for (const kokoro of [
196
227
  const localPath = join(repoDir, rel)
197
228
  const partPath = `${localPath}.part`
198
229
  if (want && (await sha256OfFile(localPath).catch(() => '')) === want) { doneCount++; continue }
199
- try {
200
- await mkdir(localPath.replace(/[\\/][^\\/]*$/, ''), { recursive: true })
201
- const res = await fetch(`${HOST_FALLBACK}/${repo}/resolve/main/${encodeURIComponent(rel)}`, { headers: { 'user-agent': 'dsh-voice-mode/prefetch' } })
202
- if (res.status !== 200) { console.error(` ✗ ${rel} (status ${res.status})`); ok = false; continue }
203
- const sink = createWriteStream(partPath)
204
- const reader = res.body?.getReader()
205
- if (!reader) continue
206
- for (;;) {
207
- const { done, value } = await reader.read()
208
- if (done) break
209
- if (!sink.write(value)) await new Promise((r) => sink.once('drain', r))
230
+ const encodedRel = encodeRelPath(rel)
231
+ let downloaded = false
232
+ for (const host of hostOrder) {
233
+ try {
234
+ await mkdir(localPath.replace(/[\\/][^\\/]*$/, ''), { recursive: true })
235
+ const res = await fetch(`${host}/${repo}/resolve/${rev}/${encodedRel}`, { headers: { 'user-agent': 'dsh-voice-mode/prefetch' } })
236
+ if (res.status !== 200) { await res.body?.cancel().catch(() => undefined); continue }
237
+ const sink = createWriteStream(partPath)
238
+ const reader = res.body?.getReader()
239
+ if (!reader) continue
240
+ for (;;) {
241
+ const { done, value } = await reader.read()
242
+ if (done) break
243
+ if (!sink.write(value)) await new Promise((r) => sink.once('drain', r))
244
+ }
245
+ await new Promise((resolve, reject) => { sink.end(resolve); sink.on('error', reject) })
246
+ const got = await sha256OfFile(partPath)
247
+ if (want && got !== want) { await unlink(partPath).catch(() => undefined); continue }
248
+ await rename(partPath, localPath)
249
+ downloaded = true
250
+ doneCount++
251
+ break
252
+ } catch {
253
+ await unlink(partPath).catch(() => undefined)
210
254
  }
211
- await new Promise((resolve, reject) => { sink.end(resolve); sink.on('error', reject) })
212
- const got = await sha256OfFile(partPath)
213
- if (want && got !== want) { console.error(` ✗ ${rel} 校验失败`); ok = false; await unlink(partPath).catch(() => undefined); continue }
214
- await rename(partPath, localPath)
215
- doneCount++
216
- } catch {
255
+ }
256
+ if (!downloaded) {
217
257
  console.error(` ✗ ${rel} 下载失败`)
218
258
  ok = false
219
259
  }