@oadank/dsh-input-tools 0.3.1 → 0.3.3

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/lib/index.js CHANGED
@@ -961,22 +961,6 @@ async function apply(ctx) {
961
961
  return sendJson(res, 404, { ok: false, error: '安装脚本不存在' })
962
962
  }
963
963
  }
964
- // [2026-08-21] 本地 TTS 一键安装命令(与 ASR 同款交互;脚本 install-local-tts.ps1 同目录)
965
- if (url.pathname === '/tts/install-script' && req.method === 'GET') {
966
- const here = join(fileURLToPath(import.meta.url), '..') // .../lib
967
- const scriptPath = join(here, '..', 'scripts', 'install-local-tts.ps1') // .../scripts
968
- try {
969
- await readFile(scriptPath, 'utf8') // 确认脚本存在
970
- return sendJson(res, 200, {
971
- ok: true,
972
- scriptPath,
973
- installDir: join(here, '..', 'sherpa-onnx'),
974
- command: `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`,
975
- })
976
- } catch {
977
- return sendJson(res, 404, { ok: false, error: '安装脚本不存在' })
978
- }
979
- }
980
964
  // VoiceDesign 官方示例音频:用真实的 MiMo-V2.5-TTS-VoiceDesign 模型生成(instruct=音色描述 / text=正文),缓存到 ~/.dsh/voice-design-samples/
981
965
  // 注意:必须走 voicedesign 模型(user=音色描述,无 voice 参数)才是真音色,绝不能降级到 edge 假造
982
966
  if (url.pathname === '/asr/voice-design-samples' && req.method === 'GET') {
@@ -1026,6 +1010,34 @@ async function apply(ctx) {
1026
1010
  }
1027
1011
  },
1028
1012
  }))
1013
+ // [2026-08-21] 本地 TTS 配置与安装脚本路由(独立 prefix,勿放进 /asr)
1014
+ disposers.push(ctx.webServer.register({
1015
+ kind: 'prefix',
1016
+ path: '/tts',
1017
+ handler: async (req, res) => {
1018
+ const url = new URL(req.url ?? '/', 'http://x')
1019
+ try {
1020
+ if (url.pathname === '/tts/install-script' && req.method === 'GET') {
1021
+ const here = join(fileURLToPath(import.meta.url), '..') // .../lib
1022
+ const scriptPath = join(here, '..', 'scripts', 'install-local-tts.ps1') // .../scripts
1023
+ try {
1024
+ await readFile(scriptPath, 'utf8') // 确认脚本存在
1025
+ return sendJson(res, 200, {
1026
+ ok: true,
1027
+ scriptPath,
1028
+ installDir: join(here, '..', 'sherpa-onnx'),
1029
+ command: `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`,
1030
+ })
1031
+ } catch {
1032
+ return sendJson(res, 404, { ok: false, error: '安装脚本不存在' })
1033
+ }
1034
+ }
1035
+ return sendJson(res, 404, { ok: false, error: 'not found' })
1036
+ } catch (error) {
1037
+ return sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : 'unknown' })
1038
+ }
1039
+ },
1040
+ }))
1029
1041
  }
1030
1042
 
1031
1043
  // 1) turn/end 自动语音回复(规则同 api-proxy 原实现)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oadank/dsh-input-tools",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -170,7 +170,9 @@ const server = http.createServer(async (req, res) => {
170
170
  });
171
171
  server.listen(PORT, () => console.log('[ASR] listening on ' + PORT));
172
172
  "@
173
- $serviceFile = "$InstallDir\asr-service.js"
173
+ # 服务脚本用 .cjs:插件包 package.json 声明了 "type":"module",.js 会被当 ESM 解析导致 require 报错
174
+ # (2026-08-21 XDN 实测:asr-service.js 抛 ReferenceError: require is not defined)
175
+ $serviceFile = "$InstallDir\asr-service.cjs"
174
176
  Set-Content -Path $serviceFile -Value $serviceScript -Encoding UTF8
175
177
 
176
178
  # ---- 6. 注册 nssm 服务 ----