dsh-podwave 0.11.19 → 0.11.21
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.md +6 -1
- package/dist/client.js +5 -3
- package/package.json +1 -1
- package/scripts/diarize.py +3 -1
- package/src/catalog.js +23 -0
- package/src/config.js +53 -5
- package/src/downloader.js +47 -3
- package/src/host.js +10 -3
- package/src/jobs.js +34 -0
- package/src/library.js +8 -2
- package/src/llama.js +4 -6
- package/src/platform.js +36 -1
- package/src/setup.js +54 -17
- package/src/transcribe.js +88 -39
- package/src/translate.js +8 -2
- package/src/xyz.js +31 -13
package/scripts/diarize.py
CHANGED
|
@@ -42,7 +42,9 @@ def main():
|
|
|
42
42
|
parser.add_argument('--emb-model', required=True)
|
|
43
43
|
parser.add_argument('--threshold', type=float, default=0.6)
|
|
44
44
|
parser.add_argument('--num-speakers', type=int, default=-1)
|
|
45
|
-
|
|
45
|
+
# 默认走 PATH 上的 ffmpeg。之前写死 /opt/homebrew/bin/ffmpeg,
|
|
46
|
+
# 在 Windows 上是 [WinError 2] 系统找不到指定的文件。
|
|
47
|
+
parser.add_argument('--ffmpeg', default=os.environ.get('PODWAVE_FFMPEG') or 'ffmpeg')
|
|
46
48
|
args = parser.parse_args()
|
|
47
49
|
|
|
48
50
|
import sherpa_onnx as so
|
package/src/catalog.js
CHANGED
|
@@ -212,6 +212,29 @@ export function artifactFor(platform, engine) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
// 配置里存的是目录名(artifact.dir),不是 catalog 的 key。
|
|
216
|
+
// 靠正则猜「这是不是 SenseVoice」在换模型后必错,所以按元数据反查。
|
|
217
|
+
export function artifactByDir(dir, kind) {
|
|
218
|
+
if (!dir) return null
|
|
219
|
+
const name = String(dir)
|
|
220
|
+
for (const artifact of Object.values(CATALOG)) {
|
|
221
|
+
if (kind && artifact.kind !== kind) continue
|
|
222
|
+
if (artifact.dir === name || artifact.id === name) return artifact
|
|
223
|
+
}
|
|
224
|
+
return null
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 当前平台「应该用哪个模型/引擎」——配置默认值、安装检查、运行时判定都以它为准。
|
|
228
|
+
export function expectedModels(platform, engine) {
|
|
229
|
+
const artifacts = artifactFor(platform, engine)
|
|
230
|
+
return {
|
|
231
|
+
asrModel: artifacts.asr.dir,
|
|
232
|
+
translateModel: artifacts.translate.dir,
|
|
233
|
+
asrEngine: artifacts.asr.engine,
|
|
234
|
+
translateEngine: artifacts.translate.engine,
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
215
238
|
export function llamaAsset(platform) {
|
|
216
239
|
const name = LLAMA_BINARY.assets[platformKey(platform)]
|
|
217
240
|
if (!name) return null
|
package/src/config.js
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
// 统一配置:~/.podwave/config.json(schemaVersion 1)。
|
|
2
2
|
// 首次启动时把旧的 ui.json / translate.json / models.json 迁入,并把旧文件改名为 *.bak。
|
|
3
|
+
//
|
|
4
|
+
// 两条容易踩的坑,都在这里兜住:
|
|
5
|
+
// 1. 默认模型必须按平台算,不能写死 MLX——那套模型只有 Apple Silicon 能装。
|
|
6
|
+
// 2. 缓存不能盲信。宿主进程常驻,而「一键安装」是另一个进程写盘;如果保存时拿内存里的
|
|
7
|
+
// 旧快照整份写回,安装结果就被吞掉了。所以每次保存都先比对磁盘是否被别人改过。
|
|
3
8
|
import fs from 'node:fs'
|
|
4
9
|
import path from 'node:path'
|
|
5
10
|
import { DATA_DIR } from './state.js'
|
|
11
|
+
import { detectPlatform, recommendEngine } from './platform.js'
|
|
12
|
+
import { expectedModels } from './catalog.js'
|
|
6
13
|
|
|
7
14
|
export const CONFIG_PATH = path.join(DATA_DIR, 'config.json')
|
|
8
15
|
|
|
16
|
+
function defaultModels() {
|
|
17
|
+
const platform = detectPlatform()
|
|
18
|
+
const engine = recommendEngine(platform)
|
|
19
|
+
const models = expectedModels(platform, engine)
|
|
20
|
+
return { asrModel: models.asrModel, translateModel: models.translateModel }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// detectPlatform() 会去探测 GPU(可能 spawn 子进程),不能放在模块顶层每次求值。
|
|
24
|
+
// 用惰性 getter + 缓存:既保证「默认模型按平台算」,又不会拖慢 import。
|
|
25
|
+
let defaultsCache = null
|
|
26
|
+
function cachedDefaultModels() {
|
|
27
|
+
if (!defaultsCache) defaultsCache = defaultModels()
|
|
28
|
+
return defaultsCache
|
|
29
|
+
}
|
|
30
|
+
|
|
9
31
|
export const CONFIG_DEFAULTS = {
|
|
10
32
|
schemaVersion: 1,
|
|
11
33
|
ui: { showSidebarPanel: true, sidebarCollapsed: false },
|
|
@@ -16,7 +38,10 @@ export const CONFIG_DEFAULTS = {
|
|
|
16
38
|
apiModel: 'deepseek-chat',
|
|
17
39
|
apiKey: '',
|
|
18
40
|
},
|
|
19
|
-
|
|
41
|
+
// 默认模型绝不能写死 MLX:那套模型 platform 是 darwin-arm64,Windows 装不了。
|
|
42
|
+
get models() {
|
|
43
|
+
return { ...cachedDefaultModels() }
|
|
44
|
+
},
|
|
20
45
|
transcribe: { hotwords: [], chunkMinutes: 1, diarize: true },
|
|
21
46
|
import: { mode: 'copy' },
|
|
22
47
|
}
|
|
@@ -48,6 +73,16 @@ function readJson(file) {
|
|
|
48
73
|
}
|
|
49
74
|
}
|
|
50
75
|
|
|
76
|
+
// 磁盘指纹:别的进程改过 config.json 时,缓存必须失效。
|
|
77
|
+
function statKey() {
|
|
78
|
+
try {
|
|
79
|
+
const stat = fs.statSync(CONFIG_PATH)
|
|
80
|
+
return `${stat.mtimeMs}:${stat.size}`
|
|
81
|
+
} catch {
|
|
82
|
+
return 'missing'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
51
86
|
function writeConfig(config) {
|
|
52
87
|
fs.mkdirSync(DATA_DIR, { recursive: true })
|
|
53
88
|
const tmp = `${CONFIG_PATH}.tmp`
|
|
@@ -74,19 +109,24 @@ function migrateLegacy() {
|
|
|
74
109
|
}
|
|
75
110
|
|
|
76
111
|
let cache = null
|
|
112
|
+
let cacheKey = null
|
|
77
113
|
|
|
78
114
|
export function loadConfig() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
115
|
+
const key = statKey()
|
|
116
|
+
if (cache && cacheKey === key) return clone(cache)
|
|
117
|
+
const stored = key === 'missing' ? null : readJson(CONFIG_PATH)
|
|
118
|
+
cache = stored ? merge(clone(CONFIG_DEFAULTS), stored) : migrateLegacy()
|
|
119
|
+
cacheKey = statKey()
|
|
83
120
|
return clone(cache)
|
|
84
121
|
}
|
|
85
122
|
|
|
86
123
|
export function saveConfig(patch) {
|
|
124
|
+
// 先 loadConfig():它会比对磁盘指纹,把别的进程(比如安装器)刚写进去的模型名读进来,
|
|
125
|
+
// 再和这次 patch 合并,避免用旧快照覆盖安装结果。
|
|
87
126
|
const next = merge(loadConfig(), patch)
|
|
88
127
|
cache = next
|
|
89
128
|
writeConfig(next)
|
|
129
|
+
cacheKey = statKey()
|
|
90
130
|
return clone(next)
|
|
91
131
|
}
|
|
92
132
|
|
|
@@ -101,3 +141,11 @@ export function updateSection(name, patch) {
|
|
|
101
141
|
export function configFile() {
|
|
102
142
|
return CONFIG_PATH
|
|
103
143
|
}
|
|
144
|
+
|
|
145
|
+
// 测试与诊断用:当前平台推荐的模型组合。
|
|
146
|
+
export function platformDefaults() {
|
|
147
|
+
const platform = detectPlatform()
|
|
148
|
+
const engine = recommendEngine(platform)
|
|
149
|
+
const models = expectedModels(platform, engine)
|
|
150
|
+
return { platform: { os: platform.os, arch: platform.arch, osLabel: platform.osLabel }, engine: engine.id, models }
|
|
151
|
+
}
|
package/src/downloader.js
CHANGED
|
@@ -94,6 +94,10 @@ function runCapture(cmd, args) {
|
|
|
94
94
|
})
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// 非 zip 压缩包(.tar.bz2 / .tar.gz / .tar.xz)的条目列表。
|
|
98
|
+
// GNU tar(Git for Windows、MSYS、Cygwin 会把它的目录排到 PATH 前面)会把 C:/... 当成
|
|
99
|
+
// host:path 远程语法,直接 `tar -tf C:/...` 会报 "Cannot connect to C: resolve failed"。
|
|
100
|
+
// 所以这里也要多候选,否则安全检查会被静默跳过。
|
|
97
101
|
async function listArchiveEntries(file) {
|
|
98
102
|
const lower = file.toLowerCase()
|
|
99
103
|
if (lower.endsWith('.zip')) {
|
|
@@ -108,8 +112,43 @@ async function listArchiveEntries(file) {
|
|
|
108
112
|
}
|
|
109
113
|
return null
|
|
110
114
|
}
|
|
111
|
-
const
|
|
112
|
-
|
|
115
|
+
for (const [cmd, args] of tarListAttempts(file)) {
|
|
116
|
+
const output = await runCapture(cmd, args)
|
|
117
|
+
if (output) return output.split(/\r?\n/).filter(Boolean)
|
|
118
|
+
}
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function systemTar() {
|
|
123
|
+
if (process.platform !== 'win32') return null
|
|
124
|
+
const root = process.env.SystemRoot || process.env.windir || 'C:\\Windows'
|
|
125
|
+
return path.join(root, 'System32', 'tar.exe')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 解压/列目录的候选命令。顺序有意义:
|
|
129
|
+
// 1. 裸 tar:bsdtar(Windows 自带、macOS 自带)与 GNU tar 都能跑相对路径。
|
|
130
|
+
// 2. --force-local:只有 GNU tar 认,用来救「绝对路径被当成远程主机」的情况。
|
|
131
|
+
// bsdtar 会明确拒绝这个选项,所以必须放在裸 tar 之后、失败后才轮到。
|
|
132
|
+
// 3. Windows 自带的 System32\tar.exe:显式绕开 PATH 上被 Git-Bash 顶掉的 GNU tar。
|
|
133
|
+
// 4. python -m tarfile:最后兜底,不依赖任何外部 tar。
|
|
134
|
+
function tarAttempts(file, destDir) {
|
|
135
|
+
const list = [['tar', ['-xf', file, '-C', destDir]]]
|
|
136
|
+
list.push(['tar', ['--force-local', '-xf', file, '-C', destDir]])
|
|
137
|
+
const sysTar = systemTar()
|
|
138
|
+
if (sysTar) list.push([sysTar, ['-xf', file, '-C', destDir]])
|
|
139
|
+
list.push(['python', ['-m', 'tarfile', '-e', file, destDir]])
|
|
140
|
+
list.push(['python3', ['-m', 'tarfile', '-e', file, destDir]])
|
|
141
|
+
return list
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function tarListAttempts(file) {
|
|
145
|
+
const list = [['tar', ['-tf', file]]]
|
|
146
|
+
list.push(['tar', ['--force-local', '-tf', file]])
|
|
147
|
+
const sysTar = systemTar()
|
|
148
|
+
if (sysTar) list.push([sysTar, ['-tf', file]])
|
|
149
|
+
list.push(['python', ['-c', 'import sys,tarfile;print("\n".join(tarfile.open(sys.argv[1]).getnames()))', file]])
|
|
150
|
+
list.push(['python3', ['-c', 'import sys,tarfile;print("\n".join(tarfile.open(sys.argv[1]).getnames()))', file]])
|
|
151
|
+
return list
|
|
113
152
|
}
|
|
114
153
|
|
|
115
154
|
async function sha256File(file) {
|
|
@@ -343,8 +382,13 @@ export async function extractArchive(file, destDir) {
|
|
|
343
382
|
attempts.push(['tar', ['-xf', file, '-C', destDir]])
|
|
344
383
|
attempts.push(['powershell.exe', ['-NoProfile', '-Command', `Expand-Archive -LiteralPath '${file}' -DestinationPath '${destDir}' -Force`]])
|
|
345
384
|
attempts.push(['python3', ['-m', 'zipfile', '-e', file, destDir]])
|
|
385
|
+
attempts.push(['python', ['-m', 'zipfile', '-e', file, destDir]])
|
|
346
386
|
} else {
|
|
347
|
-
|
|
387
|
+
// 之前这里只有一次裸 tar:只要 PATH 上的 tar 是 GNU tar(Git for Windows / MSYS / Cygwin
|
|
388
|
+
// 都会排到前面),Windows 的 C:/ 绝对路径就会被当成 host:path,报
|
|
389
|
+
// "tar: Cannot connect to C: resolve failed"(exit 128)。而这发生在安装最后一步
|
|
390
|
+
// (说话人分离模型),前面 1.6 GB 都下完了,整次安装却被判失败。
|
|
391
|
+
attempts.push(...tarAttempts(file, destDir))
|
|
348
392
|
}
|
|
349
393
|
let lastError = null
|
|
350
394
|
for (const [cmd, args] of attempts) {
|
package/src/host.js
CHANGED
|
@@ -465,7 +465,7 @@ async function route(ctx, req, res) {
|
|
|
465
465
|
return json(res, 200, {
|
|
466
466
|
ok: true,
|
|
467
467
|
generatedAt: new Date().toISOString(),
|
|
468
|
-
version: '0.11.
|
|
468
|
+
version: '0.11.21',
|
|
469
469
|
platform,
|
|
470
470
|
engine: recommendEngine(platform),
|
|
471
471
|
paths: {
|
|
@@ -494,7 +494,7 @@ async function route(ctx, req, res) {
|
|
|
494
494
|
}
|
|
495
495
|
if ((method === 'GET' || method === 'HEAD') && routePath === 'api/health') {
|
|
496
496
|
await mediaReady
|
|
497
|
-
return json(res, 200, { ok: true, app: 'podwave', version: '0.11.
|
|
497
|
+
return json(res, 200, { ok: true, app: 'podwave', version: '0.11.21', mediaBase, transcribe: runtimeInfo(), diarize: diarizeInfo(), translate: publicConfig() })
|
|
498
498
|
}
|
|
499
499
|
if (method === 'GET' && routePath === 'api/state') {
|
|
500
500
|
const state = getState()
|
|
@@ -581,7 +581,14 @@ async function route(ctx, req, res) {
|
|
|
581
581
|
return json(res, 200, localAppStatus())
|
|
582
582
|
}
|
|
583
583
|
if (method === 'POST' && routePath === 'api/xyz/auth/from-app') {
|
|
584
|
-
|
|
584
|
+
try {
|
|
585
|
+
return json(res, 200, await loginFromLocalApp())
|
|
586
|
+
} catch (error) {
|
|
587
|
+
// 「这台机器上没有小宇宙 App / 登录已失效」是环境与凭据问题,不是服务器故障:
|
|
588
|
+
// 用 400 让前端能直接展示原因,而不是当成 500 崩掉。
|
|
589
|
+
if (!error.status) error.status = 400
|
|
590
|
+
throw error
|
|
591
|
+
}
|
|
585
592
|
}
|
|
586
593
|
if (method === 'POST' && routePath === 'api/xyz/auth/logout') {
|
|
587
594
|
return json(res, 200, logout())
|
package/src/jobs.js
CHANGED
|
@@ -36,6 +36,17 @@ function schedule() {
|
|
|
36
36
|
if (typeof saveTimer.unref === 'function') saveTimer.unref()
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
function isAlive(pid) {
|
|
40
|
+
const target = Number(pid)
|
|
41
|
+
if (!Number.isInteger(target) || target <= 1) return false
|
|
42
|
+
try {
|
|
43
|
+
process.kill(target, 0)
|
|
44
|
+
return true
|
|
45
|
+
} catch {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
function load() {
|
|
40
51
|
let changed = false
|
|
41
52
|
try {
|
|
@@ -49,8 +60,17 @@ function load() {
|
|
|
49
60
|
}
|
|
50
61
|
for (const job of jobs.values()) {
|
|
51
62
|
if (job.status === 'queued' || job.status === 'running') {
|
|
63
|
+
// 宿主热重载(disable/enable 插件)时,旧的转写子进程可能还在跑。
|
|
64
|
+
// 只要它活着就保持 running,否则界面会显示「已中断」而取消按钮点不动。
|
|
65
|
+
if (job.pid && isAlive(job.pid)) {
|
|
66
|
+
job.orphan = true
|
|
67
|
+
job.updatedAt = Date.now()
|
|
68
|
+
changed = true
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
52
71
|
job.status = 'interrupted'
|
|
53
72
|
job.error = '进程重启,任务已中断'
|
|
73
|
+
job.pid = null
|
|
54
74
|
job.updatedAt = Date.now()
|
|
55
75
|
changed = true
|
|
56
76
|
}
|
|
@@ -71,6 +91,20 @@ export function getJob(key) {
|
|
|
71
91
|
return jobs.get(key) || null
|
|
72
92
|
}
|
|
73
93
|
|
|
94
|
+
// 宿主热重载后会有两份模块实例共享同一个 jobs.json:
|
|
95
|
+
// 取消可能由新实例写入磁盘,而仍在跑 runJob 的旧实例内存里还是 running。
|
|
96
|
+
// 收尾时必须看磁盘上的真实状态,避免旧实例把「已取消」覆写成「进程退出码 -15」。
|
|
97
|
+
export function getJobFresh(key) {
|
|
98
|
+
try {
|
|
99
|
+
const data = JSON.parse(fs.readFileSync(JOBS_PATH, 'utf8'))
|
|
100
|
+
const found = (data.jobs || []).find((job) => job && job.key === key)
|
|
101
|
+
if (found) return found
|
|
102
|
+
} catch {
|
|
103
|
+
/* 读不到就用内存里的 */
|
|
104
|
+
}
|
|
105
|
+
return jobs.get(key) || null
|
|
106
|
+
}
|
|
107
|
+
|
|
74
108
|
export function listJobs() {
|
|
75
109
|
return [...jobs.values()].sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0))
|
|
76
110
|
}
|
package/src/library.js
CHANGED
|
@@ -19,11 +19,17 @@ const metaCache = new Map()
|
|
|
19
19
|
let scanPromise = null
|
|
20
20
|
let scanState = { running: false, startedAt: null, finishedAt: null, error: null }
|
|
21
21
|
|
|
22
|
+
// Windows 用户经常直接粘资源管理器地址栏里的 %USERPROFILE%\Music、%HOMEPATH%,
|
|
23
|
+
// 之前只认 ~ 和 ~/,这类路径会原样返回然后扫描失败。顺带支持 ~\ 与 %NAME%。
|
|
22
24
|
export function expandHome(input) {
|
|
23
|
-
|
|
25
|
+
let value = String(input || '').trim()
|
|
24
26
|
if (!value) return ''
|
|
27
|
+
value = value.replace(/%([^%\\/]+)%/g, (whole, name) => {
|
|
28
|
+
const resolved = process.env[name] || process.env[name.toUpperCase()] || process.env[name.toLowerCase()]
|
|
29
|
+
return resolved || whole
|
|
30
|
+
})
|
|
25
31
|
if (value === '~') return os.homedir()
|
|
26
|
-
if (value.startsWith('~/')) return path.join(os.homedir(), value.slice(2))
|
|
32
|
+
if (value.startsWith('~/') || value.startsWith('~\\')) return path.join(os.homedir(), value.slice(2))
|
|
27
33
|
return path.resolve(value)
|
|
28
34
|
}
|
|
29
35
|
|
package/src/llama.js
CHANGED
|
@@ -7,7 +7,7 @@ import { DATA_DIR } from './state.js'
|
|
|
7
7
|
import { getSection } from './config.js'
|
|
8
8
|
import { llamaBinary } from './setup.js'
|
|
9
9
|
import { CATALOG } from './catalog.js'
|
|
10
|
-
import { detectPlatform, isWindows } from './platform.js'
|
|
10
|
+
import { detectPlatform, isWindows, killTree } from './platform.js'
|
|
11
11
|
|
|
12
12
|
const TARGET_NAMES = { zh: 'Simplified Chinese', en: 'English' }
|
|
13
13
|
const IDLE_MS = 90_000
|
|
@@ -91,11 +91,9 @@ export async function ensureLlamaServer() {
|
|
|
91
91
|
|
|
92
92
|
export function stopLlamaServer() {
|
|
93
93
|
if (!server) return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// ignore
|
|
98
|
-
}
|
|
94
|
+
// Windows 上 SIGTERM 等于 TerminateProcess,llama-server 的临时文件不会清理;
|
|
95
|
+
// killTree 在 Windows 走 taskkill /T,其它平台仍是优雅 SIGTERM。
|
|
96
|
+
killTree(server.child.pid)
|
|
99
97
|
server = null
|
|
100
98
|
}
|
|
101
99
|
|
package/src/platform.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import fs from 'node:fs'
|
|
4
4
|
import os from 'node:os'
|
|
5
5
|
import path from 'node:path'
|
|
6
|
-
import { execFileSync } from 'node:child_process'
|
|
6
|
+
import { execFileSync, spawn } from 'node:child_process'
|
|
7
7
|
|
|
8
8
|
export const isWindows = process.platform === 'win32'
|
|
9
9
|
export const isMac = process.platform === 'darwin'
|
|
@@ -109,6 +109,41 @@ export function venvBin(name, dir = venvDir()) {
|
|
|
109
109
|
return isWindows ? path.join(dir, 'Scripts', name + ext) : path.join(dir, 'bin', name + ext)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// Windows 上 SIGTERM 实际上是 TerminateProcess(硬杀),子进程(ffmpeg 之类)会变成孤儿。
|
|
113
|
+
// 统一走这里:Windows 用 taskkill /T 连子孙一起收,其它平台照常 SIGTERM,超时再 SIGKILL。
|
|
114
|
+
export function killTree(pid, { signal = 'SIGTERM', timeoutMs = 5000, onForce } = {}) {
|
|
115
|
+
const target = Number(pid)
|
|
116
|
+
if (!Number.isInteger(target) || target <= 1) return false
|
|
117
|
+
try {
|
|
118
|
+
process.kill(target, 0)
|
|
119
|
+
} catch {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
if (isWindows) {
|
|
123
|
+
try {
|
|
124
|
+
spawn('taskkill', ['/PID', String(target), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
|
|
125
|
+
} catch {
|
|
126
|
+
/* ignore */
|
|
127
|
+
}
|
|
128
|
+
return true
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
process.kill(target, signal)
|
|
132
|
+
} catch {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
const timer = setTimeout(() => {
|
|
136
|
+
try {
|
|
137
|
+
process.kill(target, 'SIGKILL')
|
|
138
|
+
} catch {
|
|
139
|
+
/* 已经退出 */
|
|
140
|
+
}
|
|
141
|
+
onForce?.()
|
|
142
|
+
}, timeoutMs)
|
|
143
|
+
timer.unref?.()
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
112
147
|
export function detectGpu() {
|
|
113
148
|
if (isAppleSilicon()) return 'metal'
|
|
114
149
|
try {
|
package/src/setup.js
CHANGED
|
@@ -7,9 +7,9 @@ import { execFile, spawn } from 'node:child_process'
|
|
|
7
7
|
import { DATA_DIR } from './state.js'
|
|
8
8
|
import { getSection, updateSection } from './config.js'
|
|
9
9
|
import { getJob, upsertJob } from './jobs.js'
|
|
10
|
-
import { CATALOG, FFMPEG_BINARY, LLAMA_BINARY, SOURCE_LABELS, artifactFor, ffmpegAsset, llamaAsset, sourcesFor } from './catalog.js'
|
|
10
|
+
import { CATALOG, FFMPEG_BINARY, LLAMA_BINARY, SOURCE_LABELS, artifactFor, expectedModels, ffmpegAsset, llamaAsset, sourcesFor } from './catalog.js'
|
|
11
11
|
import { downloadArtifact, extractArchive } from './downloader.js'
|
|
12
|
-
import { detectPlatform, findExecutable, ffmpegPath, ffprobePath, recommendEngine, venvDir, venvPython, isWindows, isMac } from './platform.js'
|
|
12
|
+
import { detectPlatform, findExecutable, ffmpegPath, ffprobePath, killTree, recommendEngine, venvDir, venvPython, isWindows, isMac } from './platform.js'
|
|
13
13
|
|
|
14
14
|
const RUNTIME_DIR = path.join(DATA_DIR, 'runtime')
|
|
15
15
|
const SETUP_PATH = path.join(DATA_DIR, 'setup.json')
|
|
@@ -27,7 +27,8 @@ export function setupJob() {
|
|
|
27
27
|
export function cancelSetup() {
|
|
28
28
|
if (!current) return false
|
|
29
29
|
current.cancelled = true
|
|
30
|
-
|
|
30
|
+
// Windows 上 SIGTERM 等于硬杀,uv/Python 拉起的子进程会变孤儿;killTree 处理平台差异。
|
|
31
|
+
killTree(current.child?.pid)
|
|
31
32
|
return true
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -247,12 +248,22 @@ export async function verify() {
|
|
|
247
248
|
})
|
|
248
249
|
}
|
|
249
250
|
|
|
251
|
+
// 只判「非空」等于没判:Mac 专用模型名、甚至是瞎编的名字都会亮绿,
|
|
252
|
+
// 用户看到「检查通过」却在转写时报「运行环境未安装」。这里比对本平台应有的模型。
|
|
250
253
|
const config = getSection('models')
|
|
254
|
+
const expected = expectedModels(platform, engine)
|
|
255
|
+
const problems = []
|
|
256
|
+
if (config.asrModel !== expected.asrModel) {
|
|
257
|
+
problems.push(`转写模型应为 ${expected.asrModel},当前 ${config.asrModel || '未设置'}`)
|
|
258
|
+
}
|
|
259
|
+
if (config.translateModel !== expected.translateModel) {
|
|
260
|
+
problems.push(`翻译模型应为 ${expected.translateModel},当前 ${config.translateModel || '未设置'}`)
|
|
261
|
+
}
|
|
251
262
|
checks.push({
|
|
252
263
|
id: 'config',
|
|
253
|
-
label: '
|
|
254
|
-
ok:
|
|
255
|
-
detail: `${config.asrModel
|
|
264
|
+
label: '模型配置与当前平台匹配',
|
|
265
|
+
ok: problems.length === 0,
|
|
266
|
+
detail: problems.length ? problems.join(';') : `${config.asrModel} / ${config.translateModel}`,
|
|
256
267
|
})
|
|
257
268
|
|
|
258
269
|
return {
|
|
@@ -503,25 +514,51 @@ export async function install({ source = 'auto' } = {}) {
|
|
|
503
514
|
}
|
|
504
515
|
|
|
505
516
|
// 3. 模型
|
|
517
|
+
// 说话人分离是可选组件:它失败不该把已经下完的 1.6 GB 判定成整次安装失败。
|
|
518
|
+
// 之前任何一个 tar 解压失败都会让整个 install 走到 catch,用户看到「安装失败」。
|
|
519
|
+
const optionalFailures = []
|
|
506
520
|
for (const artifact of targets) {
|
|
507
521
|
if (current.cancelled) throw new Error('用户取消了安装')
|
|
522
|
+
const optional = artifact.kind === 'diarization'
|
|
508
523
|
report({ stage: `下载 ${artifact.label}` })
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
524
|
+
try {
|
|
525
|
+
const result = await downloadArtifact(artifact, {
|
|
526
|
+
sourceId: source,
|
|
527
|
+
signal: current.signal,
|
|
528
|
+
onProgress: (event) => {
|
|
529
|
+
doneBytes += event.delta || 0
|
|
530
|
+
report({ stage: `下载 ${artifact.label}` })
|
|
531
|
+
},
|
|
532
|
+
})
|
|
533
|
+
doneBytes = Math.max(doneBytes, summary.reduce((sum, item) => sum + item.bytes, 0) + result.bytes)
|
|
534
|
+
summary.push({ id: artifact.id, label: artifact.label, bytes: result.bytes, source: result.sourceLabel })
|
|
535
|
+
} catch (error) {
|
|
536
|
+
if (current.cancelled) throw new Error('用户取消了安装')
|
|
537
|
+
if (!optional) throw error
|
|
538
|
+
const message = String(error?.message || error)
|
|
539
|
+
optionalFailures.push({ id: artifact.id, label: artifact.label, error: message })
|
|
540
|
+
summary.push({ id: artifact.id, label: artifact.label, bytes: 0, optional: true, skipped: true, error: message })
|
|
541
|
+
report({ stage: `跳过可选组件:${artifact.label}(${message})` })
|
|
542
|
+
}
|
|
519
543
|
}
|
|
520
544
|
|
|
521
545
|
// 4. 写配置
|
|
522
546
|
updateSection('models', { asrModel: artifacts.asr.dir, translateModel: artifacts.translate.dir })
|
|
523
547
|
writeSetup({ engine: engine.id, source, installedAt: Date.now(), lastSummary: summary })
|
|
524
|
-
const
|
|
548
|
+
const warning = optionalFailures.length
|
|
549
|
+
? `可选组件失败,已跳过:${optionalFailures.map((item) => `${item.label}(${item.error})`).join(';')}。核心转写与翻译已就绪,可以正常使用。`
|
|
550
|
+
: null
|
|
551
|
+
const job = updateJob({
|
|
552
|
+
status: 'done',
|
|
553
|
+
stage: warning ? '完成(部分可选组件已跳过)' : '完成',
|
|
554
|
+
progress: 100,
|
|
555
|
+
bytes: doneBytes,
|
|
556
|
+
expected: totalBytes || doneBytes,
|
|
557
|
+
summary,
|
|
558
|
+
error: null,
|
|
559
|
+
warning,
|
|
560
|
+
optionalFailures,
|
|
561
|
+
})
|
|
525
562
|
current.running = false
|
|
526
563
|
return job
|
|
527
564
|
} catch (error) {
|