@oadank/dsh-input-tools 0.3.4 → 0.3.5
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 +1 -1
- package/scripts/install-asr.ps1 +54 -9
- package/scripts/install-local-tts.ps1 +51 -9
package/package.json
CHANGED
package/scripts/install-asr.ps1
CHANGED
|
@@ -58,6 +58,39 @@ New-Item -ItemType Directory -Force -Path "$InstallDir\models" | Out-Null
|
|
|
58
58
|
New-Item -ItemType Directory -Force -Path "$InstallDir\bin" | Out-Null
|
|
59
59
|
New-Item -ItemType Directory -Force -Path "$InstallDir\tmp" | Out-Null
|
|
60
60
|
|
|
61
|
+
# ---- 1b. 下载/解压工具函数(2026-08-21 增强:断点续传 + 完整性校验 + 损坏自动重试)----
|
|
62
|
+
# 之前 XDN 实测:GitHub 大文件下载中断 → 只下了 42.7MB/230MB → tar 报 Truncated → 脚本抛错退出,
|
|
63
|
+
# 用户只看到"跑到最后报错"毫无提示。现在 curl -C - 断点续传 + 解压后校验,损坏文件自动删除重下。
|
|
64
|
+
function Download-Resume {
|
|
65
|
+
param([string]$Url, [string]$OutFile)
|
|
66
|
+
for ($attempt = 1; $attempt -le 3; $attempt++) {
|
|
67
|
+
Write-Host " 下载(第 $attempt 次尝试): $Url" -ForegroundColor Yellow
|
|
68
|
+
# Windows 10+ 自带 curl.exe;-C - 断点续传;--retry 网络层重试
|
|
69
|
+
& curl.exe -L -C - --retry 3 --retry-delay 2 --connect-timeout 20 -o $OutFile $Url 2>$null
|
|
70
|
+
if ($LASTEXITCODE -eq 0) { return $true }
|
|
71
|
+
Write-Host " 下载中断(exit=$LASTEXITCODE),3 秒后重试..." -ForegroundColor Yellow
|
|
72
|
+
Start-Sleep -Seconds 3
|
|
73
|
+
}
|
|
74
|
+
return $false
|
|
75
|
+
}
|
|
76
|
+
function Expand-TarBz2 {
|
|
77
|
+
param([string]$Archive, [string]$Dest, [int]$Strip = 0)
|
|
78
|
+
$tmpDir = Join-Path $Dest ".extract-tmp"
|
|
79
|
+
New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
|
|
80
|
+
$tarArgs = @('-xjf', $Archive, '-C', $tmpDir)
|
|
81
|
+
if ($Strip -gt 0) { $tarArgs += "--strip-components=$Strip" }
|
|
82
|
+
tar @tarArgs 2>$null
|
|
83
|
+
if ($LASTEXITCODE -ne 0) {
|
|
84
|
+
Write-Host " 解压失败:压缩包损坏或不完整($Archive)" -ForegroundColor Red
|
|
85
|
+
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
|
86
|
+
Remove-Item -Force $Archive -ErrorAction SilentlyContinue
|
|
87
|
+
return $false
|
|
88
|
+
}
|
|
89
|
+
Get-ChildItem $tmpDir | Move-Item -Destination $Dest -Force -ErrorAction SilentlyContinue
|
|
90
|
+
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
|
91
|
+
return $true
|
|
92
|
+
}
|
|
93
|
+
|
|
61
94
|
# ---- 2. 检查 ffmpeg(ASR 转码必需)----
|
|
62
95
|
Write-Host "`n[1/4] 检查 ffmpeg..." -ForegroundColor Yellow
|
|
63
96
|
$ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue
|
|
@@ -79,12 +112,15 @@ Write-Host "`n[2/4] 下载 sherpa-onnx $Version ..." -ForegroundColor Yellow
|
|
|
79
112
|
$pkgUrl = "https://github.com/k2-fsa/sherpa-onnx/releases/download/$Version/sherpa-onnx-$Version-win-x64-shared-MD-Release.tar.bz2"
|
|
80
113
|
$pkgFile = "$InstallDir\tmp\sherpa-onnx.tar.bz2"
|
|
81
114
|
if (-not (Test-Path "$InstallDir\bin\sherpa-onnx-offline.exe")) {
|
|
82
|
-
if (-not (
|
|
83
|
-
Write-Host "
|
|
84
|
-
|
|
115
|
+
if (-not (Download-Resume $pkgUrl $pkgFile)) {
|
|
116
|
+
Write-Host " sherpa-onnx 下载失败(网络不稳定)。请检查网络后重跑本脚本" -ForegroundColor Red
|
|
117
|
+
exit 1
|
|
85
118
|
}
|
|
86
119
|
Write-Host " 解压..."
|
|
87
|
-
|
|
120
|
+
if (-not (Expand-TarBz2 $pkgFile "$InstallDir\tmp")) {
|
|
121
|
+
Write-Host " sherpa-onnx 压缩包损坏已删除,请重跑本脚本自动重新下载" -ForegroundColor Red
|
|
122
|
+
exit 1
|
|
123
|
+
}
|
|
88
124
|
# 解压后目录结构:sherpa-onnx-v1.13.6-win-x64-shared-MD-Release/ 内含 bin/ lib/
|
|
89
125
|
$extracted = Get-ChildItem "$InstallDir\tmp" -Directory | Where-Object { $_.Name -like "sherpa-onnx-*win*" } | Select-Object -First 1
|
|
90
126
|
if ($extracted) {
|
|
@@ -99,19 +135,28 @@ if (-not (Test-Path "$InstallDir\bin\sherpa-onnx-offline.exe")) {
|
|
|
99
135
|
Write-Host " sherpa-onnx 已存在,跳过下载" -ForegroundColor Green
|
|
100
136
|
}
|
|
101
137
|
|
|
102
|
-
# ---- 4. 下载 SenseVoice
|
|
138
|
+
# ---- 4. 下载 SenseVoice 模型(断点续传 + 完整性校验)----
|
|
103
139
|
Write-Host "`n[3/4] 下载 SenseVoice int8 模型..." -ForegroundColor Yellow
|
|
104
140
|
$modelDir = "$InstallDir\models\sensevoice-int8"
|
|
105
141
|
$modelUrl = "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-int8-2025-09-09.tar.bz2"
|
|
106
142
|
$modelFile = "$InstallDir\tmp\sensevoice.tar.bz2"
|
|
107
143
|
if (-not (Test-Path "$modelDir\model.int8.onnx")) {
|
|
108
|
-
if (-not (
|
|
109
|
-
Write-Host "
|
|
110
|
-
|
|
144
|
+
if (-not (Download-Resume $modelUrl $modelFile)) {
|
|
145
|
+
Write-Host " SenseVoice 模型下载失败(网络不稳定)。请检查网络后重跑本脚本" -ForegroundColor Red
|
|
146
|
+
exit 1
|
|
111
147
|
}
|
|
112
148
|
New-Item -ItemType Directory -Force -Path $modelDir | Out-Null
|
|
113
149
|
Write-Host " 解压模型..."
|
|
114
|
-
|
|
150
|
+
if (-not (Expand-TarBz2 $modelFile $modelDir 1)) {
|
|
151
|
+
Write-Host " 模型压缩包损坏已删除,请重跑本脚本自动重新下载" -ForegroundColor Red
|
|
152
|
+
exit 1
|
|
153
|
+
}
|
|
154
|
+
if (-not (Test-Path "$modelDir\model.int8.onnx")) {
|
|
155
|
+
Write-Host " 解压后未找到 model.int8.onnx(压缩包异常),已清理。请重跑本脚本" -ForegroundColor Red
|
|
156
|
+
Remove-Item -Recurse -Force $modelDir -ErrorAction SilentlyContinue
|
|
157
|
+
Remove-Item -Force $modelFile -ErrorAction SilentlyContinue
|
|
158
|
+
exit 1
|
|
159
|
+
}
|
|
115
160
|
Write-Host " 模型解压完成" -ForegroundColor Green
|
|
116
161
|
} else {
|
|
117
162
|
Write-Host " 模型已存在,跳过下载" -ForegroundColor Green
|
|
@@ -17,6 +17,36 @@
|
|
|
17
17
|
$ErrorActionPreference = "Stop"
|
|
18
18
|
$Version = "v1.13.6"
|
|
19
19
|
|
|
20
|
+
# ---- 下载/解压工具函数(2026-08-21 增强:断点续传 + 完整性校验 + 损坏自动重试)----
|
|
21
|
+
function Download-Resume {
|
|
22
|
+
param([string]$Url, [string]$OutFile)
|
|
23
|
+
for ($attempt = 1; $attempt -le 3; $attempt++) {
|
|
24
|
+
Write-Host " 下载(第 $attempt 次尝试): $Url" -ForegroundColor Yellow
|
|
25
|
+
& curl.exe -L -C - --retry 3 --retry-delay 2 --connect-timeout 20 -o $OutFile $Url 2>$null
|
|
26
|
+
if ($LASTEXITCODE -eq 0) { return $true }
|
|
27
|
+
Write-Host " 下载中断(exit=$LASTEXITCODE),3 秒后重试..." -ForegroundColor Yellow
|
|
28
|
+
Start-Sleep -Seconds 3
|
|
29
|
+
}
|
|
30
|
+
return $false
|
|
31
|
+
}
|
|
32
|
+
function Expand-TarBz2 {
|
|
33
|
+
param([string]$Archive, [string]$Dest, [int]$Strip = 0)
|
|
34
|
+
$tmpDir = Join-Path $Dest ".extract-tmp"
|
|
35
|
+
New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
|
|
36
|
+
$tarArgs = @('-xjf', $Archive, '-C', $tmpDir)
|
|
37
|
+
if ($Strip -gt 0) { $tarArgs += "--strip-components=$Strip" }
|
|
38
|
+
tar @tarArgs 2>$null
|
|
39
|
+
if ($LASTEXITCODE -ne 0) {
|
|
40
|
+
Write-Host " 解压失败:压缩包损坏或不完整($Archive)" -ForegroundColor Red
|
|
41
|
+
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
|
42
|
+
Remove-Item -Force $Archive -ErrorAction SilentlyContinue
|
|
43
|
+
return $false
|
|
44
|
+
}
|
|
45
|
+
Get-ChildItem $tmpDir | Move-Item -Destination $Dest -Force -ErrorAction SilentlyContinue
|
|
46
|
+
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
|
47
|
+
return $true
|
|
48
|
+
}
|
|
49
|
+
|
|
20
50
|
# ---- 0. 自动推导安装目录:脚本在 <插件包>/scripts/,安装到 <插件包>/sherpa-onnx/ ----
|
|
21
51
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
22
52
|
$PluginRoot = Split-Path -Parent $ScriptDir
|
|
@@ -62,12 +92,15 @@ $pkgUrl = "https://github.com/k2-fsa/sherpa-onnx/releases/download/$Version/sher
|
|
|
62
92
|
$pkgFile = "$InstallDir\tmp\sherpa-onnx.tar.bz2"
|
|
63
93
|
if (-not (Test-Path "$InstallDir\bin\sherpa-onnx-offline-tts.exe")) {
|
|
64
94
|
if (-not (Test-Path "$InstallDir\bin\sherpa-onnx-offline.exe")) {
|
|
65
|
-
if (-not (
|
|
66
|
-
Write-Host "
|
|
67
|
-
|
|
95
|
+
if (-not (Download-Resume $pkgUrl $pkgFile)) {
|
|
96
|
+
Write-Host " sherpa-onnx 下载失败(网络不稳定)。请检查网络后重跑本脚本" -ForegroundColor Red
|
|
97
|
+
exit 1
|
|
68
98
|
}
|
|
69
99
|
Write-Host " 解压..."
|
|
70
|
-
|
|
100
|
+
if (-not (Expand-TarBz2 $pkgFile "$InstallDir\tmp")) {
|
|
101
|
+
Write-Host " sherpa-onnx 压缩包损坏已删除,请重跑本脚本自动重新下载" -ForegroundColor Red
|
|
102
|
+
exit 1
|
|
103
|
+
}
|
|
71
104
|
$extracted = Get-ChildItem "$InstallDir\tmp" -Directory | Where-Object { $_.Name -like "sherpa-onnx-*win*" } | Select-Object -First 1
|
|
72
105
|
if ($extracted) {
|
|
73
106
|
Copy-Item "$($extracted.FullName)\bin\*" "$InstallDir\bin\" -Force
|
|
@@ -84,19 +117,28 @@ if (-not (Test-Path "$InstallDir\bin\sherpa-onnx-offline-tts.exe")) {
|
|
|
84
117
|
Write-Host " sherpa-onnx 已存在,跳过下载" -ForegroundColor Green
|
|
85
118
|
}
|
|
86
119
|
|
|
87
|
-
# ---- 4. 下载 MeloTTS
|
|
120
|
+
# ---- 4. 下载 MeloTTS 中文模型(断点续传 + 完整性校验)----
|
|
88
121
|
Write-Host "`n[3/3] 下载中文 MeloTTS VITS 模型..." -ForegroundColor Yellow
|
|
89
122
|
$modelDir = "$InstallDir\models\melo"
|
|
90
123
|
$modelUrl = "https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-melo-tts-zh_en.tar.bz2"
|
|
91
124
|
$modelFile = "$InstallDir\tmp\melo.tar.bz2"
|
|
92
125
|
if (-not (Test-Path "$modelDir\model.onnx")) {
|
|
93
|
-
if (-not (
|
|
94
|
-
Write-Host "
|
|
95
|
-
|
|
126
|
+
if (-not (Download-Resume $modelUrl $modelFile)) {
|
|
127
|
+
Write-Host " MeloTTS 模型下载失败(网络不稳定)。请检查网络后重跑本脚本" -ForegroundColor Red
|
|
128
|
+
exit 1
|
|
96
129
|
}
|
|
97
130
|
New-Item -ItemType Directory -Force -Path $modelDir | Out-Null
|
|
98
131
|
Write-Host " 解压模型..."
|
|
99
|
-
|
|
132
|
+
if (-not (Expand-TarBz2 $modelFile $modelDir 1)) {
|
|
133
|
+
Write-Host " 模型压缩包损坏已删除,请重跑本脚本自动重新下载" -ForegroundColor Red
|
|
134
|
+
exit 1
|
|
135
|
+
}
|
|
136
|
+
if (-not (Test-Path "$modelDir\model.onnx")) {
|
|
137
|
+
Write-Host " 解压后未找到 model.onnx(压缩包异常),已清理。请重跑本脚本" -ForegroundColor Red
|
|
138
|
+
Remove-Item -Recurse -Force $modelDir -ErrorAction SilentlyContinue
|
|
139
|
+
Remove-Item -Force $modelFile -ErrorAction SilentlyContinue
|
|
140
|
+
exit 1
|
|
141
|
+
}
|
|
100
142
|
Write-Host " 模型解压完成" -ForegroundColor Green
|
|
101
143
|
} else {
|
|
102
144
|
Write-Host " 模型已存在,跳过下载" -ForegroundColor Green
|