dsh-podwave 0.0.0-stage → 0.10.19

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/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "dsh-podwave",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.19",
4
+ "description": "DeepSeek Harness 插件:本地优先的播客播放器 + 转写 + 双语字幕 + 字幕翻译。",
5
+ "type": "module",
6
+ "main": "./src/host.js",
7
+ "exports": {
8
+ ".": "./src/host.js",
9
+ "./client": "./dist/client.js",
10
+ "./cordis.patch.yml": "./cordis.patch.yml",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "dsh": {
14
+ "bundle": {
15
+ "patch": "./cordis.patch.yml"
16
+ },
17
+ "client": {
18
+ "platform": "web",
19
+ "inject": [
20
+ "@deepseek-ai/dsh-client-runtime"
21
+ ]
22
+ }
23
+ },
24
+ "engines": {
25
+ "node": ">=20",
26
+ "dsh": ">=0.2.1-rc.5 <0.3.0 || >=0.2.2-rc.0 <0.3.0 || >=0.2.3-rc.0 <0.3.0 || >=0.2.4-rc.0 <0.3.0"
27
+ },
28
+ "keywords": [
29
+ "dsh",
30
+ "deepseek-harness",
31
+ "dsh-plugin",
32
+ "podcast",
33
+ "player"
34
+ ],
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/Watchcats211/dsh-podwave.git"
39
+ },
40
+ "homepage": "https://github.com/Watchcats211/dsh-podwave#readme",
41
+ "scripts": {
42
+ "build": "node build.mjs",
43
+ "prepack": "npm run build",
44
+ "test": "node --test test/*.test.mjs"
45
+ },
46
+ "dependencies": {
47
+ "music-metadata": "^10.6.0"
48
+ },
49
+ "devDependencies": {
50
+ "esbuild": "^0.25.0",
51
+ "postcss": "^8.5.0"
52
+ },
53
+ "files": [
54
+ "src",
55
+ "dist",
56
+ "cordis.patch.yml",
57
+ "README.md",
58
+ "scripts"
59
+ ]
60
+ }
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env python3
2
+ """sherpa-onnx 离线转写(SenseVoice)。跨平台:Windows / Linux / Intel Mac 通用。
3
+
4
+ 输出 JSON:{ "text": str, "tokens": [{"text", "start", "end"}], "language": str }
5
+ """
6
+ import argparse
7
+ import json
8
+ import re
9
+ import sys
10
+ import wave
11
+
12
+ import numpy as np
13
+ import sherpa_onnx
14
+
15
+
16
+ def read_wav(path):
17
+ with wave.open(path, "rb") as handle:
18
+ if handle.getnchannels() != 1 or handle.getframerate() != 16000:
19
+ raise ValueError("需要 16kHz 单声道 wav")
20
+ frames = handle.readframes(handle.getnframes())
21
+ return np.frombuffer(frames, dtype=np.int16).astype(np.float32) / 32768.0
22
+
23
+
24
+ def transcribe_file(model_dir, wav, threads=4):
25
+ recognizer = sherpa_onnx.OfflineRecognizer.from_sense_voice(
26
+ model=f"{model_dir}/model.int8.onnx",
27
+ tokens=f"{model_dir}/tokens.txt",
28
+ num_threads=threads,
29
+ use_itn=True,
30
+ language="auto",
31
+ debug=False,
32
+ )
33
+ samples = read_wav(wav)
34
+ stream = recognizer.create_stream()
35
+ stream.accept_waveform(16000, samples)
36
+ recognizer.decode_stream(stream)
37
+ result = stream.result
38
+ text = re.sub(r"<\|[^|]+\|>", "", result.text or "").strip()
39
+ tokens = []
40
+ stamps = list(getattr(result, "timestamps", []) or [])
41
+ for index, token in enumerate(getattr(result, "tokens", []) or []):
42
+ piece = re.sub(r"<\|[^|]+\|>", "", token)
43
+ if not piece.strip():
44
+ continue
45
+ start = float(stamps[index]) if index < len(stamps) else 0.0
46
+ end = float(stamps[index + 1]) if index + 1 < len(stamps) else start + 0.2
47
+ tokens.append({"text": piece, "start": start, "end": end})
48
+ return {"text": text, "tokens": tokens, "language": "auto"}
49
+
50
+
51
+ def main():
52
+ parser = argparse.ArgumentParser()
53
+ parser.add_argument("--wav", required=True)
54
+ parser.add_argument("--model-dir", required=True)
55
+ parser.add_argument("--out", required=True)
56
+ parser.add_argument("--threads", type=int, default=4)
57
+ args = parser.parse_args()
58
+ payload = transcribe_file(args.model_dir, args.wav, args.threads)
59
+ with open(args.out, "w", encoding="utf-8") as handle:
60
+ json.dump(payload, handle, ensure_ascii=False)
61
+ print(json.dumps(payload, ensure_ascii=False))
62
+
63
+
64
+ if __name__ == "__main__":
65
+ try:
66
+ main()
67
+ except Exception as error: # noqa: BLE001
68
+ print(json.dumps({"error": str(error)}), file=sys.stderr)
69
+ sys.exit(1)
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python3
2
+ """批量 SenseVoice 转写:一次加载模型,顺序处理多个 wav,每完成一个写一个 JSON。
3
+ 输出文件名与 MLX CLI 保持一致(与输入 wav 同名、扩展名换成 .json),便于复用 ingest 逻辑。
4
+ """
5
+ import argparse
6
+ import json
7
+ import os
8
+ import sys
9
+
10
+ from asr_sherpa import transcribe_file
11
+
12
+
13
+ def main():
14
+ parser = argparse.ArgumentParser()
15
+ parser.add_argument("files", nargs="+")
16
+ parser.add_argument("--model-dir", required=True)
17
+ parser.add_argument("--out-dir", required=True)
18
+ parser.add_argument("--threads", type=int, default=4)
19
+ parser.add_argument("--hotwords", default="")
20
+ args = parser.parse_args()
21
+ if args.hotwords.strip():
22
+ print("note: SenseVoice 模型不支持热词,已忽略 --hotwords", file=sys.stderr)
23
+ os.makedirs(args.out_dir, exist_ok=True)
24
+ for wav in args.files:
25
+ base = os.path.splitext(os.path.basename(wav))[0]
26
+ out = os.path.join(args.out_dir, base + ".json")
27
+ if os.path.exists(out):
28
+ continue
29
+ payload = transcribe_file(args.model_dir, wav, args.threads)
30
+ with open(out, "w", encoding="utf-8") as handle:
31
+ json.dump(payload, handle, ensure_ascii=False)
32
+ print(f"done {base}", flush=True)
33
+
34
+
35
+ if __name__ == "__main__":
36
+ try:
37
+ main()
38
+ except Exception as error: # noqa: BLE001
39
+ print(json.dumps({"error": str(error)}), file=sys.stderr)
40
+ sys.exit(1)
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env python3
2
+ """离线说话人分离:sherpa-onnx(pyannote segmentation + 3D-Speaker embedding)。
3
+
4
+ 输入音频文件,输出 JSON:{"segments":[{"start":..,"end":..,"speaker":N}],"numSpeakers":N,"duration":..}
5
+ """
6
+ import argparse
7
+ import json
8
+ import os
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+ import wave
13
+
14
+ import numpy as np
15
+
16
+
17
+ def convert(ffmpeg, audio, out):
18
+ subprocess.run(
19
+ [ffmpeg, '-hide_banner', '-loglevel', 'error', '-y', '-i', audio, '-ac', '1', '-ar', '16000', '-f', 'wav', out],
20
+ check=True,
21
+ )
22
+
23
+
24
+ def read_wav(path):
25
+ with wave.open(path, 'rb') as handle:
26
+ rate = handle.getframerate()
27
+ channels = handle.getnchannels()
28
+ width = handle.getsampwidth()
29
+ frames = handle.readframes(handle.getnframes())
30
+ if width != 2:
31
+ raise RuntimeError(f'只支持 16-bit PCM,收到 {width * 8}-bit')
32
+ data = np.frombuffer(frames, dtype=np.int16).astype(np.float32) / 32768.0
33
+ if channels > 1:
34
+ data = data.reshape(-1, channels).mean(axis=1)
35
+ return rate, data
36
+
37
+
38
+ def main():
39
+ parser = argparse.ArgumentParser()
40
+ parser.add_argument('--audio', required=True)
41
+ parser.add_argument('--seg-model', required=True)
42
+ parser.add_argument('--emb-model', required=True)
43
+ parser.add_argument('--threshold', type=float, default=0.6)
44
+ parser.add_argument('--num-speakers', type=int, default=-1)
45
+ parser.add_argument('--ffmpeg', default=os.environ.get('PODWAVE_FFMPEG', '/opt/homebrew/bin/ffmpeg'))
46
+ args = parser.parse_args()
47
+
48
+ import sherpa_onnx as so
49
+
50
+ config = so.OfflineSpeakerDiarizationConfig(
51
+ segmentation=so.OfflineSpeakerSegmentationModelConfig(
52
+ pyannote=so.OfflineSpeakerSegmentationPyannoteModelConfig(model=args.seg_model)
53
+ ),
54
+ embedding=so.SpeakerEmbeddingExtractorConfig(model=args.emb_model),
55
+ clustering=so.FastClusteringConfig(num_clusters=args.num_speakers, threshold=args.threshold),
56
+ min_duration_on=0.3,
57
+ min_duration_off=0.5,
58
+ )
59
+ diarizer = so.OfflineSpeakerDiarization(config)
60
+
61
+ with tempfile.TemporaryDirectory(prefix='podwave-diarize-') as tmp:
62
+ wav = os.path.join(tmp, 'audio.wav')
63
+ convert(args.ffmpeg, args.audio, wav)
64
+ rate, samples = read_wav(wav)
65
+ result = diarizer.process(samples)
66
+ segments = [
67
+ {'start': round(float(seg.start), 3), 'end': round(float(seg.end), 3), 'speaker': int(seg.speaker)}
68
+ for seg in result.sort_by_start_time()
69
+ ]
70
+ speakers = {seg['speaker'] for seg in segments}
71
+ print(json.dumps({'segments': segments, 'numSpeakers': len(speakers), 'duration': round(len(samples) / rate, 3)}, ensure_ascii=False))
72
+
73
+
74
+ if __name__ == '__main__':
75
+ try:
76
+ main()
77
+ except Exception as error: # noqa: BLE001
78
+ print(json.dumps({'error': str(error)}, ensure_ascii=False), file=sys.stderr)
79
+ sys.exit(1)
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ // 发布脚本:node scripts/release.mjs 0.8.0
3
+ // 只做一条链路:改版本号 → 跑测试 → 构建 → 打包 → 提交 → 打 tag → 推送 → 建 Release。
4
+ // Release 说明取自 CHANGELOG.md 里对应的 "## <version> — <date>" 小节。
5
+ import { execSync } from 'node:child_process'
6
+ import fs from 'node:fs'
7
+ import path from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+
10
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
11
+ const version = process.argv[2]
12
+ if (!version || !/^\d+\.\d+\.\d+(-[\w.]+)?$/.test(version)) {
13
+ console.error('用法: node scripts/release.mjs <version>,例如 0.8.0')
14
+ process.exit(1)
15
+ }
16
+ const [major, minor] = version.split('.')
17
+ const tag = `v${version}`
18
+
19
+ function run(command) {
20
+ console.log(`\n$ ${command}`)
21
+ execSync(command, { cwd: root, stdio: 'inherit' })
22
+ }
23
+ function read(rel) {
24
+ return fs.readFileSync(path.join(root, rel), 'utf8')
25
+ }
26
+ function write(rel, content) {
27
+ fs.writeFileSync(path.join(root, rel), content)
28
+ }
29
+
30
+ // 1. CHANGELOG 小节
31
+ const changelog = read('CHANGELOG.md')
32
+ const heading = new RegExp(`^## ${version.replace(/\./g, '\\.')} — .+$`, 'm')
33
+ if (!heading.test(changelog)) {
34
+ console.error(`CHANGELOG.md 里没有 ${version} 的小节(## ${version} — YYYY-MM-DD)`)
35
+ process.exit(1)
36
+ }
37
+ const start = changelog.search(heading)
38
+ const rest = changelog.slice(start)
39
+ const end = rest.indexOf('\n## ', 1)
40
+ const notes = rest.slice(0, end === -1 ? undefined : end).trim()
41
+ const lines = notes.split('\n')
42
+ const headingText = lines[0].replace(/^##\s*/, '')
43
+ const descLine = lines.slice(1).map((line) => line.trim()).find(Boolean) || headingText
44
+ const title = `${tag} ${descLine.replace(/^[-*]\s*/, '').replace(/\*\*/g, '').slice(0, 90)}`
45
+
46
+ // 2. 版本号:package.json / host health / 客户端 brand
47
+ write('package.json', read('package.json').replace(/"version": "[^"]+"/, `"version": "${version}"`))
48
+ let host = read('src/host.js')
49
+ if (!/version: '\d+\.\d+\.\d+'/.test(host)) throw new Error('host.js 里找不到 version 字面量')
50
+ host = host.replace(/version: '\d+\.\d+\.\d+'/, `version: '${version}'`)
51
+ write('src/host.js', host)
52
+ let app = read('client/src/App.jsx')
53
+ if (!/<span className="brand-version">[\d.]+<\/span>/.test(app)) throw new Error('App.jsx 里找不到 brand-version')
54
+ app = app.replace(/<span className="brand-version">[\d.]+<\/span>/, `<span className="brand-version">${major}.${minor}</span>`)
55
+ write('client/src/App.jsx', app)
56
+
57
+ // 3. 测试 + 构建
58
+ run('npm test')
59
+ run('npm run build')
60
+
61
+ // 4. 打包(产物只用于 Release 附件,不提交)
62
+ const packDir = fs.mkdtempSync('/tmp/podwave-release-')
63
+ run(`npm pack --pack-destination "${packDir}"`)
64
+ const tgz = path.join(packDir, `dsh-podwave-${version}.tgz`)
65
+ if (!fs.existsSync(tgz)) throw new Error(`没有找到打包产物 ${tgz}`)
66
+
67
+ // 5. 提交、打 tag、推送
68
+ run('git add -A')
69
+ const description = title.replace(/^v\S+\s+/, '').replace(/"/g, "'")
70
+ run(`git commit -m "v${version}: ${description}"`)
71
+ run(`git tag -f ${tag}`)
72
+ run('git push')
73
+ run(`git push -f origin ${tag}`)
74
+
75
+ // 6. Release
76
+ const notesFile = path.join(packDir, 'notes.md')
77
+ fs.writeFileSync(notesFile, notes)
78
+ run(`gh release create ${tag} "${tgz}" --title "${title.replace(/"/g, "'")}" --notes-file "${notesFile}"`)
79
+ console.log(`\n完成:https://github.com/Watchcats211/dsh-podwave/releases/tag/${tag}`)
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env python3
2
+ """本地字幕翻译:读取 JSON 任务,用 MLX 模型逐批翻译,结果以 JSON 写到 stdout。"""
3
+ import json
4
+ import re
5
+ import sys
6
+
7
+ from mlx_lm import generate, load
8
+
9
+
10
+ def main() -> int:
11
+ with open(sys.argv[1], "r", encoding="utf-8") as handle:
12
+ config = json.load(handle)
13
+
14
+ model, tokenizer = load(config["model_dir"])
15
+ target = config["target"]
16
+ language = "Simplified Chinese" if target == "zh" else "English"
17
+ items = config["items"]
18
+ results = {}
19
+
20
+ batch_size = 15
21
+ for start in range(0, len(items), batch_size):
22
+ batch = items[start:start + batch_size]
23
+ numbered = "\n".join(f"{index + 1}. {item['text']}" for index, item in enumerate(batch))
24
+ messages = [
25
+ {
26
+ "role": "system",
27
+ "content": (
28
+ "You are a professional subtitle translator. Translate each numbered line into "
29
+ f"{language}. Preserve proper names, numbers and terminology. Output only the translated "
30
+ "numbered lines in the same order, one per line, in the format '1. translation'. "
31
+ "Do not add explanations."
32
+ ),
33
+ },
34
+ {"role": "user", "content": numbered},
35
+ ]
36
+ prompt = tokenizer.apply_chat_template(
37
+ messages, add_generation_prompt=True, enable_thinking=False, tokenize=False
38
+ )
39
+ output = generate(model, tokenizer, prompt=prompt, max_tokens=1024, verbose=False)
40
+ parsed = {}
41
+ for line in output.splitlines():
42
+ match = re.match(r"^\s*(\d+)[.、)]\s*(.+?)\s*$", line)
43
+ if match:
44
+ index = int(match.group(1))
45
+ if 1 <= index <= len(batch) and index not in parsed:
46
+ parsed[index] = match.group(2)
47
+ if not parsed:
48
+ lines = [line.strip() for line in output.splitlines() if line.strip()]
49
+ if len(lines) == len(batch):
50
+ parsed = {index: line for index, line in enumerate(lines, 1)}
51
+ for index, item in enumerate(batch, 1):
52
+ results[str(item["id"])] = parsed.get(index, "")
53
+
54
+ json.dump(results, sys.stdout, ensure_ascii=False)
55
+ return 0
56
+
57
+
58
+ if __name__ == "__main__":
59
+ raise SystemExit(main())
package/src/catalog.js ADDED
@@ -0,0 +1,238 @@
1
+ // 可安装模型与运行时目录:体积、来源(国际 / 国内镜像 / ModelScope)。
2
+ // 所有下载都由 setup.js 读取这里的元数据,UI 直接展示给用户。
3
+ export const LLAMA_TAG = 'b12317'
4
+
5
+ const skipPatterns = [/^\.gitattributes$/, /^README/, /^LICENSE/, /^imgs\//, /^train\//, /\.md$/i, /\.png$/i, /\.jpg$/i]
6
+
7
+ export const CATALOG = {
8
+ 'qwen3-asr-1.7b-8bit': {
9
+ id: 'qwen3-asr-1.7b-8bit',
10
+ label: 'Qwen3-ASR-1.7B-8bit',
11
+ kind: 'asr',
12
+ engine: 'mlx',
13
+ platforms: ['darwin-arm64'],
14
+ dir: 'qwen3-asr-1.7b-8bit',
15
+ approxBytes: 2_466_000_000,
16
+ note: '中英混说、22 种中文方言,Apple Silicon 上质量最好。',
17
+ source: {
18
+ type: 'hf-repo',
19
+ repo: 'mlx-community/Qwen3-ASR-1.7B-8bit',
20
+ skip: skipPatterns,
21
+ files: [
22
+ 'chat_template.json',
23
+ 'config.json',
24
+ 'generation_config.json',
25
+ 'merges.txt',
26
+ 'model.safetensors',
27
+ 'model.safetensors.index.json',
28
+ 'preprocessor_config.json',
29
+ 'tokenizer_config.json',
30
+ 'vocab.json',
31
+ ],
32
+ },
33
+ },
34
+ 'sensevoice-int8': {
35
+ id: 'sensevoice-int8',
36
+ label: 'SenseVoice Small(int8)',
37
+ kind: 'asr',
38
+ engine: 'onnx',
39
+ platforms: ['*'],
40
+ dir: 'sensevoice-small-int8',
41
+ approxBytes: 239_500_000,
42
+ note: 'Windows / Linux / Intel Mac 使用;中文、英文、粤语、日韩,速度快。',
43
+ source: {
44
+ type: 'hf-repo',
45
+ repo: 'csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17',
46
+ include: ['model.int8.onnx', 'tokens.txt'],
47
+ },
48
+ },
49
+ 'hy-mt2-1.8b-4bit-mlx': {
50
+ id: 'hy-mt2-1.8b-4bit-mlx',
51
+ label: 'Hy-MT2-1.8B-4bit(MLX)',
52
+ kind: 'translate',
53
+ engine: 'mlx',
54
+ platforms: ['darwin-arm64'],
55
+ dir: 'hy-mt2-1.8b-4bit',
56
+ approxBytes: 961_100_000,
57
+ note: '最轻的 Hy 翻译模型,33 种语言;Mac 上约 0.2 秒一行。',
58
+ source: {
59
+ type: 'hf-repo',
60
+ repo: 'mlx-community/Hy-MT2-1.8B-4bit',
61
+ skip: skipPatterns,
62
+ files: [
63
+ 'chat_template.jinja',
64
+ 'config.json',
65
+ 'generation_config.json',
66
+ 'mlx_manifest.json',
67
+ 'model.safetensors',
68
+ 'model.safetensors.index.json',
69
+ 'tokenizer.json',
70
+ 'tokenizer_config.json',
71
+ ],
72
+ },
73
+ },
74
+ 'hy-mt2-1.8b-1.25bit': {
75
+ id: 'hy-mt2-1.8b-1.25bit',
76
+ label: 'Hy-MT2-1.8B-1.25-bit(GGUF)',
77
+ kind: 'translate',
78
+ engine: 'llama',
79
+ platforms: ['*'],
80
+ dir: 'hy-mt2-1.8b-1.25bit',
81
+ file: 'Hy-MT2-1.8B-1.25Bit.gguf',
82
+ approxBytes: 461_860_800,
83
+ note: '最小的 Hy 模型(约 440 MB),适合 8–16 GB 内存的 Windows / Linux。',
84
+ source: {
85
+ type: 'hf-file',
86
+ repo: 'tencent/Hy-MT2-1.8B-1.25Bit-GGUF',
87
+ file: 'Hy-MT2-1.8B-1.25Bit.gguf',
88
+ ms: 'Tencent-Hunyuan/Hy-MT2-1.8B-1.25Bit-GGUF',
89
+ },
90
+ },
91
+ 'hy-mt2-1.8b-2bit': {
92
+ id: 'hy-mt2-1.8b-2bit',
93
+ label: 'Hy-MT2-1.8B-2-bit(GGUF)',
94
+ kind: 'translate',
95
+ engine: 'llama',
96
+ platforms: ['*'],
97
+ dir: 'hy-mt2-1.8b-2bit',
98
+ file: 'Hy-MT2-1.8B-2Bit.gguf',
99
+ approxBytes: 600_534_880,
100
+ note: '平衡档:比 1.25-bit 稳,约 570 MB。',
101
+ source: {
102
+ type: 'hf-file',
103
+ repo: 'tencent/Hy-MT2-1.8B-2Bit-GGUF',
104
+ file: 'Hy-MT2-1.8B-2Bit.gguf',
105
+ ms: 'Tencent-Hunyuan/Hy-MT2-1.8B-2Bit-GGUF',
106
+ },
107
+ },
108
+ 'hy-mt2-1.8b-q4km': {
109
+ id: 'hy-mt2-1.8b-q4km',
110
+ label: 'Hy-MT2-1.8B-Q4_K_M(GGUF)',
111
+ kind: 'translate',
112
+ engine: 'llama',
113
+ platforms: ['*'],
114
+ dir: 'hy-mt2-1.8b-q4km',
115
+ file: 'Hy-MT2-1.8B-Q4_K_M.gguf',
116
+ approxBytes: 1_133_080_448,
117
+ note: '质量最好,约 1.1 GB;适合 24 GB 以上内存。',
118
+ source: {
119
+ type: 'hf-file',
120
+ repo: 'tencent/Hy-MT2-1.8B-GGUF',
121
+ file: 'Hy-MT2-1.8B-Q4_K_M.gguf',
122
+ ms: 'Tencent-Hunyuan/Hy-MT2-1.8B-GGUF',
123
+ },
124
+ },
125
+ 'diarization': {
126
+ id: 'diarization',
127
+ label: '说话人分离模型(pyannote + 3D-Speaker)',
128
+ kind: 'diarization',
129
+ engine: 'onnx',
130
+ platforms: ['*'],
131
+ dir: 'diarization',
132
+ approxBytes: 33_600_000,
133
+ note: '约 34 MB,本地离线,不上传音频。',
134
+ source: {
135
+ type: 'github-assets',
136
+ assets: [
137
+ {
138
+ url: 'https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-segmentation-models/sherpa-onnx-pyannote-segmentation-3-0.tar.bz2',
139
+ file: 'sherpa-onnx-pyannote-segmentation-3-0.tar.bz2',
140
+ extract: true,
141
+ },
142
+ {
143
+ url: 'https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-recongition-models/3dspeaker_speech_campplus_sv_zh_en_16k-common_advanced.onnx',
144
+ file: '3dspeaker_speech_campplus_sv_zh_en_16k-common_advanced.onnx',
145
+ },
146
+ ],
147
+ },
148
+ },
149
+ }
150
+
151
+ export const FFMPEG_BINARY = {
152
+ id: 'ffmpeg',
153
+ label: 'ffmpeg / ffprobe',
154
+ kind: 'tool',
155
+ dir: '../runtime/ffmpeg-download',
156
+ note: '切块、时长探测与说话人分离需要;Windows / Linux 可自动下载,macOS 优先用 Homebrew。',
157
+ assets: {
158
+ 'win32-x64': {
159
+ file: 'ffmpeg-master-latest-win64-gpl.zip',
160
+ bytes: 201_918_539,
161
+ url: 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip',
162
+ },
163
+ 'linux-x64': {
164
+ file: 'ffmpeg-master-latest-linux64-gpl.tar.xz',
165
+ bytes: 157_285_360,
166
+ url: 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz',
167
+ },
168
+ 'linux-arm64': {
169
+ file: 'ffmpeg-master-latest-linuxarm64-gpl.tar.xz',
170
+ bytes: 92_000_000,
171
+ url: 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz',
172
+ },
173
+ },
174
+ }
175
+
176
+ export function ffmpegAsset(platform) {
177
+ return FFMPEG_BINARY.assets[platformKey(platform)] || null
178
+ }
179
+
180
+ export const LLAMA_BINARY = {
181
+ id: 'llama-cpp',
182
+ label: 'llama.cpp 运行时',
183
+ kind: 'engine',
184
+ dir: 'runtime/llama',
185
+ note: 'Windows / Linux 上跑 GGUF 翻译模型;约 20–40 MB。',
186
+ assets: {
187
+ 'darwin-arm64': `llama-${LLAMA_TAG}-bin-macos-arm64.tar.gz`,
188
+ 'darwin-x64': `llama-${LLAMA_TAG}-bin-macos-x64.tar.gz`,
189
+ 'win32-x64': `llama-${LLAMA_TAG}-bin-win-cpu-x64.zip`,
190
+ 'win32-arm64': `llama-${LLAMA_TAG}-bin-win-cpu-arm64.zip`,
191
+ 'linux-x64': `llama-${LLAMA_TAG}-bin-ubuntu-x64.tar.gz`,
192
+ 'linux-arm64': `llama-${LLAMA_TAG}-bin-ubuntu-arm64.tar.gz`,
193
+ },
194
+ base: `https://github.com/ggml-org/llama.cpp/releases/download/${LLAMA_TAG}`,
195
+ }
196
+
197
+ export const SOURCE_LABELS = {
198
+ auto: '自动选择(先测速)',
199
+ intl: '国际线路(Hugging Face / GitHub)',
200
+ cn: '国内线路(hf-mirror / gh-proxy / ModelScope)',
201
+ }
202
+
203
+ export function platformKey(platform) {
204
+ return `${platform.os}-${platform.arch}`
205
+ }
206
+
207
+ export function artifactFor(platform, engine) {
208
+ return {
209
+ asr: CATALOG[engine.asr],
210
+ translate: CATALOG[engine.translate],
211
+ diarization: CATALOG.diarization,
212
+ }
213
+ }
214
+
215
+ export function llamaAsset(platform) {
216
+ const name = LLAMA_BINARY.assets[platformKey(platform)]
217
+ if (!name) return null
218
+ return { name, url: `${LLAMA_BINARY.base}/${name}` }
219
+ }
220
+
221
+ // 返回某个资源的候选来源(id / label / base)。
222
+ export function sourcesFor(source) {
223
+ if (source.type === 'hf-repo' || source.type === 'hf-file') {
224
+ const list = [
225
+ { id: 'intl', label: 'Hugging Face', base: 'https://huggingface.co' },
226
+ { id: 'cn', label: 'hf-mirror.com', base: 'https://hf-mirror.com' },
227
+ ]
228
+ if (source.ms) list.push({ id: 'ms', label: 'ModelScope(魔搭)', base: 'https://modelscope.cn', ms: source.ms })
229
+ return list
230
+ }
231
+ if (source.type === 'github-assets') {
232
+ return [
233
+ { id: 'intl', label: 'GitHub', base: 'https://github.com' },
234
+ { id: 'cn', label: 'gh-proxy.com', base: 'https://gh-proxy.com' },
235
+ ]
236
+ }
237
+ return []
238
+ }