dsh-voice 0.1.1 → 0.3.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 stardustlc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md CHANGED
@@ -1,5 +1,7 @@
1
1
  [中文](README.md)
2
2
 
3
+ ![npm](https://img.shields.io/npm/v/dsh-voice) ![downloads](https://img.shields.io/npm/dm/dsh-voice) ![license](https://img.shields.io/github/license/STARDUSTLC666/dsh-voice) ![stars](https://img.shields.io/github/stars/STARDUSTLC666/dsh-voice?style=social)
4
+
3
5
  # dsh-voice
4
6
 
5
7
  [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
@@ -10,12 +12,25 @@ DSH (DeepSeek Harness) voice plugin pair: let the agent **speak and listen**.
10
12
  - **voice_stt**: speech-to-text over any **OpenAI-compatible ASR endpoint** (Groq / OpenAI / custom)
11
13
  - **voice_list**: voice catalog
12
14
 
15
+ ## Compatibility
16
+
17
+ Verified against `@deepseek-ai/dsh@0.1.2-alpha.2` on 2026-08-31. Built for the cordis patch-bundle plugin model (`cordis.patch.yml` + `dsh.bundle.patch`). No runtime imports of `@deepseek-ai/*` internals.
18
+
13
19
  ## Installation
14
20
 
15
21
  ```bash
16
22
  dsh plugin --profile web add dsh-voice
17
23
  ```
18
24
 
25
+ ## Uninstall
26
+
27
+ ```bash
28
+ dsh plugin --profile web remove dsh-voice
29
+ ```
30
+
31
+ Then restart the web service. To clean up fully, also remove the plugin entry from your profile `cordis.patch.yml` if you overrode it.
32
+
33
+
19
34
  ## Configuration
20
35
 
21
36
  `voice_tts` works with zero config; `voice_stt` needs an ASR key:
package/README.md CHANGED
@@ -15,12 +15,25 @@ DSH(DeepSeek Harness)语音双件套插件:让 agent **会说话、能听
15
15
  - **voice_stt**:语音转文字,走 **OpenAI 兼容 ASR 接口**(Groq / OpenAI / 自定义端点)
16
16
  - **voice_list**:音色清单
17
17
 
18
+ ## 兼容性
19
+
20
+ 在 `@deepseek-ai/dsh@0.1.2-alpha.2` 上验证(2026-08-31)。遵循 cordis 组合包补丁模型(`cordis.patch.yml` + `dsh.bundle.patch`),运行时不 import 任何 `@deepseek-ai/*` 内部模块。
21
+
18
22
  ## 安装
19
23
 
20
24
  ```bash
21
25
  dsh plugin --profile web add dsh-voice
22
26
  ```
23
27
 
28
+ ## 卸载
29
+
30
+ ```bash
31
+ dsh plugin --profile web remove dsh-voice
32
+ ```
33
+
34
+ 卸载后重启 Web 服务。如需彻底清理,可再手动删除自己 profile `cordis.patch.yml` 中覆盖的插件行。
35
+
36
+
24
37
  ## 配置
25
38
 
26
39
  `voice_tts` 零配置可用;`voice_stt` 需要 ASR 密钥:
@@ -69,5 +82,4 @@ pnpm test # 构建 + 31 个测试(含真实合成集成测试)
69
82
 
70
83
  ## License
71
84
 
72
- MIT
73
-
85
+ MIT
package/lib/edge-tts.js CHANGED
@@ -84,7 +84,10 @@ export async function synthesizeSpeech(options, deps = {}, timeoutMs = 30000) {
84
84
  catch { /* 忽略 */ }
85
85
  reject(new Error('语音合成超时(' + timeoutMs + ' 毫秒无完整音频),请重试或检查网络。'));
86
86
  }, timeoutMs);
87
- const finish = () => { clearTimeout(timer); resolvePromise(); };
87
+ const finish = () => { clearTimeout(timer); try {
88
+ socket.close();
89
+ }
90
+ catch { /* 忽略 */ } resolvePromise(); };
88
91
  socket.addEventListener('open', () => {
89
92
  const config = protocolHeader('speech.config', { 'Content-Type': 'application/json; charset=utf-8' })
90
93
  + JSON.stringify({
package/lib/index.d.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  import { type VoiceConfig } from './config.js';
11
11
  import { type VoiceToolDefinition } from './tools.js';
12
12
  /** cordis 服务注入:apply 里要用 ctx.tools,必须显式声明。 */
13
+ export declare const name = "voice";
13
14
  export declare const inject: string[];
14
15
  /** 插件所需的最小 ctx 面。 */
15
16
  export interface VoicePluginContext {
package/lib/index.js CHANGED
@@ -10,6 +10,7 @@
10
10
  import { resolveConfig } from './config.js';
11
11
  import { buildVoiceTools } from './tools.js';
12
12
  /** cordis 服务注入:apply 里要用 ctx.tools,必须显式声明。 */
13
+ export const name = 'voice';
13
14
  export const inject = ['tools'];
14
15
  /**
15
16
  * 插件入口:解析配置并注册三个语音工具。
package/lib/tools.d.ts CHANGED
@@ -22,6 +22,8 @@ export interface VoiceToolDefinition {
22
22
  execute(args: unknown, exec: unknown): Promise<unknown>;
23
23
  timeoutMs?: number;
24
24
  }
25
+ /** 默认试听文本(中英混合,便于感知发音差异)。 */
26
+ export declare const DEFAULT_PREVIEW_TEXT = "\u4F60\u597D\uFF0C\u8FD9\u662F\u97F3\u8272\u8BD5\u542C\u3002Hello, this is a voice preview.";
25
27
  /** 可注入依赖(测试用假实现)。 */
26
28
  export interface VoiceToolDeps {
27
29
  tts?: typeof synthesizeSpeech;
package/lib/tools.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * 三个面向模型的语音工具:voice_tts / voice_stt / voice_list。
2
+ * 五个面向模型的语音工具:voice_tts / voice_stt / voice_list / voice_preview
3
3
  *
4
4
  * @module dsh-voice/tools
5
5
  */
6
- import { readFileSync, writeFileSync } from 'node:fs';
7
- import { basename } from 'node:path';
6
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { basename, join, resolve } from 'node:path';
8
8
  import { synthesizeSpeech } from './edge-tts.js';
9
9
  import { assertAudioFile, resolveOutputPath } from './paths.js';
10
10
  import { createProxyFetch } from './proxy-fetch.js';
@@ -71,6 +71,18 @@ const sttSchema = {
71
71
  },
72
72
  additionalProperties: true,
73
73
  };
74
+ const previewSchema = {
75
+ type: 'object',
76
+ properties: {
77
+ count: { type: 'integer' },
78
+ samples: { type: 'array', items: { type: 'object', additionalProperties: true } },
79
+ failed: { type: 'array', items: { type: 'object', additionalProperties: true } },
80
+ text: { type: 'string' },
81
+ },
82
+ additionalProperties: true,
83
+ };
84
+ /** 默认试听文本(中英混合,便于感知发音差异)。 */
85
+ export const DEFAULT_PREVIEW_TEXT = '你好,这是音色试听。Hello, this is a voice preview.';
74
86
  /**
75
87
  * 构建三个工具定义。
76
88
  */
@@ -126,6 +138,10 @@ export function buildVoiceTools(config, deps = {}) {
126
138
  throw new Error('音色 id 不合法:' + voice + '。请用 voice_list 查看常用音色,或使用 zh-CN-XXXNeural 形式的 edge 音色。');
127
139
  const rate = optionalString(args, 'rate') ?? cfg.ttsRate;
128
140
  const pitch = optionalString(args, 'pitch') ?? cfg.ttsPitch;
141
+ for (const [value, label] of [[rate, '语速 rate'], [pitch, '音调 pitch']]) {
142
+ if (!/^[+-]?\d+(\.\d+)?(%|Hz|st)$/.test(value))
143
+ throw new Error(label + ' 不合法:' + value + '。合法格式如 +10%、-2Hz、+1st。');
144
+ }
129
145
  const output = resolveOutputPath(optionalString(args, 'output'), 'voice_output.mp3', cfg.overwrite);
130
146
  const audio = await (deps.tts ?? synthesizeSpeech)({ text, voice, rate, pitch }, { proxyUrl: cfg.proxyUrl }, timeout);
131
147
  writeFileSync(output, audio);
@@ -178,16 +194,112 @@ export function buildVoiceTools(config, deps = {}) {
178
194
  language: optionalString(args, 'language'),
179
195
  prompt: optionalString(args, 'prompt'),
180
196
  }, fetchImpl ?? globalThis.fetch, timeout);
181
- let transcriptFile = null;
197
+ let transcriptFile = '';
182
198
  const output = optionalString(args, 'output');
183
199
  if (output !== undefined) {
184
200
  const target = resolveOutputPath(output, '', cfg.overwrite);
185
201
  writeFileSync(target, text, 'utf8');
186
202
  transcriptFile = target;
187
203
  }
188
- return { text, model, language: optionalString(args, 'language') ?? null, audio: audioPath, transcriptFile };
204
+ // The output schema declares these as strings never return null, or
205
+ // dsh rejects the whole tool result (issue #1).
206
+ return { text, model, language: optionalString(args, 'language') ?? '', audio: audioPath, transcriptFile };
189
207
  },
190
208
  timeoutMs: timeout + 10000,
191
209
  };
192
- return [voiceList, voiceTts, voiceStt];
210
+ const voicePreview = {
211
+ name: 'voice_preview',
212
+ description: '音色试听:用一段固定试听文本批量生成短样例 MP3,方便挑选音色。voices 为音色 id 数组(可选,缺省 voice_list 前 4 个,最多 8 个);text 可自定义(≤200 字符);样例文件写入输出目录(默认工作目录 voice_previews),文件名含音色 id。单个音色失败不阻断其他。',
213
+ parameters: compileParameters({
214
+ voices: { type: 'array', items: { type: 'string' }, description: '音色 id 数组(可选,缺省 voice_list 前 4 个,最多 8 个)。' },
215
+ text: { type: 'string', description: '试听文本(可选,默认中英混合试听句,≤200 字符)。' },
216
+ outputDir: { type: 'string', description: '输出目录(可选,默认工作目录下 voice_previews)。' },
217
+ }),
218
+ output: {
219
+ schema: previewSchema,
220
+ render: (_args, value) => {
221
+ const rec = asRecord(value);
222
+ const samples = Array.isArray(rec.samples) ? rec.samples : [];
223
+ const failed = Array.isArray(rec.failed) ? rec.failed : [];
224
+ const lines = ['试听样例已生成 ' + samples.length + ' 个(试听文本:' + rec.text + '):'];
225
+ for (const item of samples) {
226
+ const s = asRecord(item);
227
+ lines.push('- ' + s.voice + ' -> ' + s.output);
228
+ }
229
+ for (const item of failed) {
230
+ const f = asRecord(item);
231
+ lines.push('- ' + f.voice + ' 失败:' + String(f.error ?? ''));
232
+ }
233
+ return [{ type: 'text', text: lines.join('\n') }];
234
+ },
235
+ },
236
+ async execute(rawArgs) {
237
+ const args = asRecord(rawArgs);
238
+ const rawVoices = Array.isArray(args.voices)
239
+ ? args.voices.filter((v) => typeof v === 'string' && v.trim() !== '').map((v) => v.trim())
240
+ : [];
241
+ const targets = rawVoices.length > 0 ? rawVoices : VOICES.slice(0, 4).map((v) => v.id);
242
+ if (targets.length > 8)
243
+ throw new Error('voices 最多 8 个(当前 ' + targets.length + ' 个),试听一次别太多,慢且耗资源。');
244
+ const text = optionalString(args, 'text') ?? DEFAULT_PREVIEW_TEXT;
245
+ if (text.length > 200)
246
+ throw new Error('试听文本请控制在 200 字以内(试听要短平快)。');
247
+ const outDir = resolve(optionalString(args, 'outputDir') ?? 'voice_previews');
248
+ mkdirSync(outDir, { recursive: true });
249
+ const samples = [];
250
+ const failed = [];
251
+ for (const voice of targets) {
252
+ if (!isValidVoiceId(voice)) {
253
+ failed.push({ voice, error: '音色 id 不合法(应为 zh-CN-XXXNeural 形式的 edge 音色)' });
254
+ continue;
255
+ }
256
+ try {
257
+ const audio = await (deps.tts ?? synthesizeSpeech)({ text, voice, rate: cfg.ttsRate, pitch: cfg.ttsPitch }, { proxyUrl: cfg.proxyUrl }, timeout);
258
+ const file = join(outDir, 'voice-preview-' + voice.replace(/[^a-zA-Z0-9-]/g, '_') + '.mp3');
259
+ writeFileSync(file, audio);
260
+ samples.push({ voice, output: file, bytes: audio.length });
261
+ }
262
+ catch (error) {
263
+ failed.push({ voice, error: error instanceof Error ? error.message : String(error) });
264
+ }
265
+ }
266
+ return { count: samples.length, samples, failed, text };
267
+ },
268
+ timeoutMs: timeout + 10000,
269
+ };
270
+ const voiceHealth = {
271
+ name: 'voice_health',
272
+ description: 'dsh-voice 自检:检查 TTS 音色合法性、代理配置与 ASR 引擎/密钥就绪状态(不发起网络请求)。遇到问题时先运行本工具定位。',
273
+ parameters: compileParameters({}),
274
+ output: {
275
+ schema: { type: 'object', additionalProperties: true },
276
+ render: (_args, value) => {
277
+ const rec = asRecord(value);
278
+ const checks = Array.isArray(rec.checks) ? rec.checks : [];
279
+ const lines = ['dsh-voice 自检' + (rec.ok === true ? ':正常。' : ':发现问题。')];
280
+ for (const item of checks) {
281
+ const c = asRecord(item);
282
+ lines.push('- ' + c.name + ':' + (c.ok === true ? '✅ ' + String(c.detail ?? '') : '❌ ' + String(c.detail ?? '')));
283
+ }
284
+ return [{ type: 'text', text: lines.join('\n') }];
285
+ },
286
+ },
287
+ async execute() {
288
+ const checks = [];
289
+ let ok = true;
290
+ const voiceOk = isValidVoiceId(cfg.ttsVoice);
291
+ checks.push({ name: 'TTS 音色', ok: voiceOk, detail: voiceOk ? cfg.ttsVoice : '不合法:' + cfg.ttsVoice + '(用 voice_list 查看)' });
292
+ if (!voiceOk)
293
+ ok = false;
294
+ checks.push({ name: '特殊代理', ok: true, detail: cfg.proxyUrl !== '' ? '已配置 ' + cfg.proxyUrl : '未配置' });
295
+ checks.push({ name: 'ASR 引擎', ok: true, detail: cfg.asrEngine });
296
+ const hasKey = cfg.asrApiKey !== '' || typeof process.env.DSH_VOICE_ASR_KEY === 'string' && process.env.DSH_VOICE_ASR_KEY !== '';
297
+ checks.push({ name: 'ASR 密钥', ok: hasKey, detail: hasKey ? '已配置' : '未配置:voice_stt 需要 DSH_VOICE_ASR_KEY 环境变量或配置 asrApiKey' });
298
+ if (!hasKey)
299
+ ok = false;
300
+ return { ok, plugin: 'dsh-voice', checks };
301
+ },
302
+ timeoutMs: 5000,
303
+ };
304
+ return [voiceList, voiceTts, voiceStt, voicePreview, voiceHealth];
193
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-voice",
3
- "version": "0.1.1",
3
+ "version": "0.3.1",
4
4
  "description": "DSH 语音双件套插件:voice_tts(edge-tts 协议零成本微软神经语音合成)/ voice_stt(OpenAI 兼容 ASR 语音转文字)/ voice_list(音色列表),原生 WebSocket + 插件级代理。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -21,7 +21,6 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "build": "tsc -p tsconfig.json",
24
- "prepare": "tsc -p tsconfig.json",
25
24
  "typecheck": "tsc -p tsconfig.json --noEmit",
26
25
  "test": "pnpm run build && node --test \"test/*.test.mjs\"",
27
26
  "prepublishOnly": "pnpm run build"