dsh-voice-mode 0.7.39 → 0.7.41
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.
- package/README.en.md +70 -44
- package/README.md +112 -39
- package/SECURITY.md +20 -16
- package/lib/client.js +4700 -914
- package/lib/index.js +1912 -402
- package/lib/sense-worker.mjs +5 -1
- package/lib/tts-vits-worker.cjs +21 -6
- package/package.json +5 -3
- package/scripts/check-anchors.mjs +12 -1
- package/scripts/prefetch.mjs +66 -26
package/lib/sense-worker.mjs
CHANGED
|
@@ -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.
|
|
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 ?? "");
|
package/lib/tts-vits-worker.cjs
CHANGED
|
@@ -24,7 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
|
|
25
25
|
// src/tts-vits-worker.ts
|
|
26
26
|
var import_sherpa_onnx = __toESM(require("sherpa-onnx"), 1);
|
|
27
|
-
var import_sherpa_onnx_node = __toESM(require("sherpa-onnx-node"), 1);
|
|
28
27
|
|
|
29
28
|
// src/segmenter.ts
|
|
30
29
|
function sanitizeForTts(text) {
|
|
@@ -33,7 +32,17 @@ function sanitizeForTts(text) {
|
|
|
33
32
|
|
|
34
33
|
// src/tts-vits-worker.ts
|
|
35
34
|
var { createOfflineTts } = import_sherpa_onnx.default;
|
|
36
|
-
var
|
|
35
|
+
var cachedNativeSherpa = null;
|
|
36
|
+
async function loadNativeSherpa() {
|
|
37
|
+
if (cachedNativeSherpa) return cachedNativeSherpa;
|
|
38
|
+
const mod = await import("sherpa-onnx-node");
|
|
39
|
+
const resolved = mod.default ?? mod;
|
|
40
|
+
if (!resolved || typeof resolved.OfflineTts !== "function") {
|
|
41
|
+
throw new Error("sherpa-onnx-node native addon is unavailable on this platform");
|
|
42
|
+
}
|
|
43
|
+
cachedNativeSherpa = resolved;
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
37
46
|
var send = (msg) => {
|
|
38
47
|
if (typeof process.send === "function") process.send(msg);
|
|
39
48
|
};
|
|
@@ -41,8 +50,9 @@ var wasmTts = null;
|
|
|
41
50
|
var nativeTts = null;
|
|
42
51
|
var initKind = "vits";
|
|
43
52
|
var initPaths = {};
|
|
44
|
-
function createEngine() {
|
|
53
|
+
async function createEngine() {
|
|
45
54
|
if (initKind === "kokoro") {
|
|
55
|
+
const { OfflineTts } = await loadNativeSherpa();
|
|
46
56
|
nativeTts = new OfflineTts({
|
|
47
57
|
model: {
|
|
48
58
|
kokoro: {
|
|
@@ -83,18 +93,18 @@ function createEngine() {
|
|
|
83
93
|
function reply(id, payload) {
|
|
84
94
|
send({ id: typeof id === "number" ? id : 0, ...payload });
|
|
85
95
|
}
|
|
86
|
-
|
|
96
|
+
async function handleMessage(msg) {
|
|
87
97
|
try {
|
|
88
98
|
if (msg.type === "init") {
|
|
89
99
|
initKind = msg.kind === "kokoro" ? "kokoro" : "vits";
|
|
90
100
|
initPaths = msg.paths;
|
|
91
|
-
createEngine();
|
|
101
|
+
await createEngine();
|
|
92
102
|
reply(msg.id, { ok: true });
|
|
93
103
|
return;
|
|
94
104
|
}
|
|
95
105
|
if (msg.type === "synth") {
|
|
96
106
|
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")
|
|
107
|
+
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
108
|
);
|
|
99
109
|
if (!text.trim()) {
|
|
100
110
|
const sr = 24e3;
|
|
@@ -113,6 +123,7 @@ process.on("message", (msg) => {
|
|
|
113
123
|
reply(msg.id, { ok: false, error: "tts child not initialized" });
|
|
114
124
|
return;
|
|
115
125
|
}
|
|
126
|
+
const { GenerationConfig } = await loadNativeSherpa();
|
|
116
127
|
const gc = new GenerationConfig({ sid, speed, silenceScale: 0.2 });
|
|
117
128
|
audio = nativeTts.generate({ text, generationConfig: gc });
|
|
118
129
|
} else {
|
|
@@ -144,4 +155,8 @@ process.on("message", (msg) => {
|
|
|
144
155
|
} catch (e) {
|
|
145
156
|
reply(typeof msg?.id === "number" ? msg.id : 0, { ok: false, error: String(e) });
|
|
146
157
|
}
|
|
158
|
+
}
|
|
159
|
+
var msgChain = Promise.resolve();
|
|
160
|
+
process.on("message", (msg) => {
|
|
161
|
+
msgChain = msgChain.then(() => handleMessage(msg));
|
|
147
162
|
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-voice-mode",
|
|
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
|
|
3
|
+
"description": "Voice plugin for DeepSeek Harness: local streaming speech recognition into editable drafts, sentence-by-sentence read-aloud with captions, and voice interruption. Supports Edge, OpenAI-compatible, Xiaomi MiMo, and local VITS/Kokoro TTS; host compatibility is bounded by engines.dsh.",
|
|
4
4
|
"icon": "./icon.svg",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.41",
|
|
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.
|
|
107
|
+
"playwright-core": "1.65.1",
|
|
108
108
|
"typescript": "^5.9.2"
|
|
109
109
|
},
|
|
110
110
|
"keywords": [
|
|
@@ -130,6 +130,8 @@
|
|
|
130
130
|
"sensevoice",
|
|
131
131
|
"kokoro",
|
|
132
132
|
"msedge-tts",
|
|
133
|
+
"openai-tts",
|
|
134
|
+
"mimo",
|
|
133
135
|
"chinese",
|
|
134
136
|
"语音",
|
|
135
137
|
"字幕",
|
|
@@ -28,7 +28,18 @@ import { fileURLToPath } from 'node:url'
|
|
|
28
28
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
29
29
|
const pkg = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'))
|
|
30
30
|
const anchors = pkg?.dsh?.client?.inject ?? []
|
|
31
|
-
const
|
|
31
|
+
const DEFAULT_TARGETS = [
|
|
32
|
+
'0.1.1-rc.2',
|
|
33
|
+
'0.1.2-rc.1',
|
|
34
|
+
'0.1.5-rc.3',
|
|
35
|
+
'0.1.6-alpha.2',
|
|
36
|
+
'0.1.7-rc.2',
|
|
37
|
+
'0.2.0-rc.2',
|
|
38
|
+
'0.2.1-rc.5',
|
|
39
|
+
'0.2.2-rc.1',
|
|
40
|
+
'0.2.2-rc.5',
|
|
41
|
+
]
|
|
42
|
+
const targets = process.argv.slice(2).length ? process.argv.slice(2) : DEFAULT_TARGETS
|
|
32
43
|
|
|
33
44
|
if (anchors.length === 0) {
|
|
34
45
|
console.error('package.json 未声明 dsh.client.inject 锚点')
|
package/scripts/prefetch.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
|
|
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
|
-
|
|
212
|
-
|
|
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
|
}
|