dsh-voice 0.1.0 → 0.3.0

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
@@ -2,18 +2,33 @@
2
2
 
3
3
  # dsh-voice
4
4
 
5
+ [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
6
+
5
7
  DSH (DeepSeek Harness) voice plugin pair: let the agent **speak and listen**.
6
8
 
7
9
  - **voice_tts**: text-to-speech over the **edge-tts protocol** (Microsoft Edge read-aloud service — free, unlimited, 22+ curated voices)
8
10
  - **voice_stt**: speech-to-text over any **OpenAI-compatible ASR endpoint** (Groq / OpenAI / custom)
9
11
  - **voice_list**: voice catalog
10
12
 
13
+ ## Compatibility
14
+
15
+ Verified against `@deepseek-ai/dsh@0.1.1-rc.2` on 2026-08-26. Built for the cordis patch-bundle plugin model (`cordis.patch.yml` + `dsh.bundle.patch`). No runtime imports of `@deepseek-ai/*` internals.
16
+
11
17
  ## Installation
12
18
 
13
19
  ```bash
14
20
  dsh plugin --profile web add dsh-voice
15
21
  ```
16
22
 
23
+ ## Uninstall
24
+
25
+ ```bash
26
+ dsh plugin --profile web remove dsh-voice
27
+ ```
28
+
29
+ Then restart the web service. To clean up fully, also remove the plugin entry from your profile `cordis.patch.yml` if you overrode it.
30
+
31
+
17
32
  ## Configuration
18
33
 
19
34
  `voice_tts` works with zero config; `voice_stt` needs an ASR key:
@@ -62,4 +77,4 @@ pnpm test # build + 31 tests, including a real-synthesis integration test
62
77
 
63
78
  ## License
64
79
 
65
- MIT
80
+ MIT
package/README.md CHANGED
@@ -2,18 +2,38 @@
2
2
 
3
3
  # dsh-voice
4
4
 
5
+ > **你的 agent 会说话了**:edge-tts 微软神经语音免费无限量 + Whisper 转写。
6
+
7
+ ![npm version](https://img.shields.io/npm/v/dsh-voice?label=npm&color=blue) ![npm downloads](https://img.shields.io/npm/dm/dsh-voice) ![license](https://img.shields.io/npm/l/dsh-voice) ![stars](https://img.shields.io/github/stars/STARDUSTLC666/dsh-voice?style=social)
8
+
9
+ [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
10
+
11
+
5
12
  DSH(DeepSeek Harness)语音双件套插件:让 agent **会说话、能听懂**。
6
13
 
7
14
  - **voice_tts**:文字转语音,走 **edge-tts 协议**(微软 Edge 朗读服务,免费无限量,22+ 常用音色)
8
15
  - **voice_stt**:语音转文字,走 **OpenAI 兼容 ASR 接口**(Groq / OpenAI / 自定义端点)
9
16
  - **voice_list**:音色清单
10
17
 
18
+ ## 兼容性
19
+
20
+ 在 `@deepseek-ai/dsh@0.1.1-rc.2` 上验证(2026-08-26)。遵循 cordis 组合包补丁模型(`cordis.patch.yml` + `dsh.bundle.patch`),运行时不 import 任何 `@deepseek-ai/*` 内部模块。
21
+
11
22
  ## 安装
12
23
 
13
24
  ```bash
14
25
  dsh plugin --profile web add dsh-voice
15
26
  ```
16
27
 
28
+ ## 卸载
29
+
30
+ ```bash
31
+ dsh plugin --profile web remove dsh-voice
32
+ ```
33
+
34
+ 卸载后重启 Web 服务。如需彻底清理,可再手动删除自己 profile `cordis.patch.yml` 中覆盖的插件行。
35
+
36
+
17
37
  ## 配置
18
38
 
19
39
  `voice_tts` 零配置可用;`voice_stt` 需要 ASR 密钥:
@@ -62,4 +82,4 @@ pnpm test # 构建 + 31 个测试(含真实合成集成测试)
62
82
 
63
83
  ## License
64
84
 
65
- MIT
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);
@@ -189,5 +205,99 @@ export function buildVoiceTools(config, deps = {}) {
189
205
  },
190
206
  timeoutMs: timeout + 10000,
191
207
  };
192
- return [voiceList, voiceTts, voiceStt];
208
+ const voicePreview = {
209
+ name: 'voice_preview',
210
+ description: '音色试听:用一段固定试听文本批量生成短样例 MP3,方便挑选音色。voices 为音色 id 数组(可选,缺省 voice_list 前 4 个,最多 8 个);text 可自定义(≤200 字符);样例文件写入输出目录(默认工作目录 voice_previews),文件名含音色 id。单个音色失败不阻断其他。',
211
+ parameters: compileParameters({
212
+ voices: { type: 'array', items: { type: 'string' }, description: '音色 id 数组(可选,缺省 voice_list 前 4 个,最多 8 个)。' },
213
+ text: { type: 'string', description: '试听文本(可选,默认中英混合试听句,≤200 字符)。' },
214
+ outputDir: { type: 'string', description: '输出目录(可选,默认工作目录下 voice_previews)。' },
215
+ }),
216
+ output: {
217
+ schema: previewSchema,
218
+ render: (_args, value) => {
219
+ const rec = asRecord(value);
220
+ const samples = Array.isArray(rec.samples) ? rec.samples : [];
221
+ const failed = Array.isArray(rec.failed) ? rec.failed : [];
222
+ const lines = ['试听样例已生成 ' + samples.length + ' 个(试听文本:' + rec.text + '):'];
223
+ for (const item of samples) {
224
+ const s = asRecord(item);
225
+ lines.push('- ' + s.voice + ' -> ' + s.output);
226
+ }
227
+ for (const item of failed) {
228
+ const f = asRecord(item);
229
+ lines.push('- ' + f.voice + ' 失败:' + String(f.error ?? ''));
230
+ }
231
+ return [{ type: 'text', text: lines.join('\n') }];
232
+ },
233
+ },
234
+ async execute(rawArgs) {
235
+ const args = asRecord(rawArgs);
236
+ const rawVoices = Array.isArray(args.voices)
237
+ ? args.voices.filter((v) => typeof v === 'string' && v.trim() !== '').map((v) => v.trim())
238
+ : [];
239
+ const targets = rawVoices.length > 0 ? rawVoices : VOICES.slice(0, 4).map((v) => v.id);
240
+ if (targets.length > 8)
241
+ throw new Error('voices 最多 8 个(当前 ' + targets.length + ' 个),试听一次别太多,慢且耗资源。');
242
+ const text = optionalString(args, 'text') ?? DEFAULT_PREVIEW_TEXT;
243
+ if (text.length > 200)
244
+ throw new Error('试听文本请控制在 200 字以内(试听要短平快)。');
245
+ const outDir = resolve(optionalString(args, 'outputDir') ?? 'voice_previews');
246
+ mkdirSync(outDir, { recursive: true });
247
+ const samples = [];
248
+ const failed = [];
249
+ for (const voice of targets) {
250
+ if (!isValidVoiceId(voice)) {
251
+ failed.push({ voice, error: '音色 id 不合法(应为 zh-CN-XXXNeural 形式的 edge 音色)' });
252
+ continue;
253
+ }
254
+ try {
255
+ const audio = await (deps.tts ?? synthesizeSpeech)({ text, voice, rate: cfg.ttsRate, pitch: cfg.ttsPitch }, { proxyUrl: cfg.proxyUrl }, timeout);
256
+ const file = join(outDir, 'voice-preview-' + voice.replace(/[^a-zA-Z0-9-]/g, '_') + '.mp3');
257
+ writeFileSync(file, audio);
258
+ samples.push({ voice, output: file, bytes: audio.length });
259
+ }
260
+ catch (error) {
261
+ failed.push({ voice, error: error instanceof Error ? error.message : String(error) });
262
+ }
263
+ }
264
+ return { count: samples.length, samples, failed, text };
265
+ },
266
+ timeoutMs: timeout + 10000,
267
+ };
268
+ const voiceHealth = {
269
+ name: 'voice_health',
270
+ description: 'dsh-voice 自检:检查 TTS 音色合法性、代理配置与 ASR 引擎/密钥就绪状态(不发起网络请求)。遇到问题时先运行本工具定位。',
271
+ parameters: compileParameters({}),
272
+ output: {
273
+ schema: { type: 'object', additionalProperties: true },
274
+ render: (_args, value) => {
275
+ const rec = asRecord(value);
276
+ const checks = Array.isArray(rec.checks) ? rec.checks : [];
277
+ const lines = ['dsh-voice 自检' + (rec.ok === true ? ':正常。' : ':发现问题。')];
278
+ for (const item of checks) {
279
+ const c = asRecord(item);
280
+ lines.push('- ' + c.name + ':' + (c.ok === true ? '✅ ' + String(c.detail ?? '') : '❌ ' + String(c.detail ?? '')));
281
+ }
282
+ return [{ type: 'text', text: lines.join('\n') }];
283
+ },
284
+ },
285
+ async execute() {
286
+ const checks = [];
287
+ let ok = true;
288
+ const voiceOk = isValidVoiceId(cfg.ttsVoice);
289
+ checks.push({ name: 'TTS 音色', ok: voiceOk, detail: voiceOk ? cfg.ttsVoice : '不合法:' + cfg.ttsVoice + '(用 voice_list 查看)' });
290
+ if (!voiceOk)
291
+ ok = false;
292
+ checks.push({ name: '特殊代理', ok: true, detail: cfg.proxyUrl !== '' ? '已配置 ' + cfg.proxyUrl : '未配置' });
293
+ checks.push({ name: 'ASR 引擎', ok: true, detail: cfg.asrEngine });
294
+ const hasKey = cfg.asrApiKey !== '' || typeof process.env.DSH_VOICE_ASR_KEY === 'string' && process.env.DSH_VOICE_ASR_KEY !== '';
295
+ checks.push({ name: 'ASR 密钥', ok: hasKey, detail: hasKey ? '已配置' : '未配置:voice_stt 需要 DSH_VOICE_ASR_KEY 环境变量或配置 asrApiKey' });
296
+ if (!hasKey)
297
+ ok = false;
298
+ return { ok, plugin: 'dsh-voice', checks };
299
+ },
300
+ timeoutMs: 5000,
301
+ };
302
+ return [voiceList, voiceTts, voiceStt, voicePreview, voiceHealth];
193
303
  }
package/package.json CHANGED
@@ -1,67 +1,67 @@
1
- {
2
- "name": "dsh-voice",
3
- "version": "0.1.0",
4
- "description": "DSH 语音双件套插件:voice_tts(edge-tts 协议零成本微软神经语音合成)/ voice_stt(OpenAI 兼容 ASR 语音转文字)/ voice_list(音色列表),原生 WebSocket + 插件级代理。",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "types": "lib/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/index.d.ts",
11
- "default": "./lib/index.js"
12
- },
13
- "./cordis.patch.yml": "./cordis.patch.yml",
14
- "./package.json": "./package.json"
15
- },
16
- "files": [
17
- "lib",
18
- "cordis.patch.yml",
19
- "README.md",
20
- "README.en.md"
21
- ],
22
- "scripts": {
23
- "build": "tsc -p tsconfig.json",
24
- "prepare": "tsc -p tsconfig.json",
25
- "typecheck": "tsc -p tsconfig.json --noEmit",
26
- "test": "pnpm run build && node --test \"test/*.test.mjs\"",
27
- "prepublishOnly": "pnpm run build"
28
- },
29
- "dsh": {
30
- "bundle": {
31
- "patch": "./cordis.patch.yml"
32
- }
33
- },
34
- "keywords": [
35
- "dsh",
36
- "deepseek-harness",
37
- "plugin",
38
- "tts",
39
- "stt",
40
- "whisper",
41
- "voice"
42
- ],
43
- "license": "MIT",
44
- "engines": {
45
- "node": ">=22"
46
- },
47
- "dependencies": {
48
- "https-proxy-agent": "^9.1.0",
49
- "undici": "^8.10.0",
50
- "ws": "^8.21.3"
51
- },
52
- "devDependencies": {
53
- "@types/node": "^24.0.0",
54
- "@types/ws": "^8.18.1",
55
- "typescript": "^5.6.0"
56
- },
57
- "repository": {
58
- "type": "git",
59
- "url": "https://github.com/STARDUSTLC666/dsh-voice"
60
- },
61
- "bugs": {
62
- "url": "https://github.com/STARDUSTLC666/dsh-voice/issues"
63
- },
64
- "homepage": "https://github.com/STARDUSTLC666/dsh-voice#readme",
65
- "author": "stardustlc",
66
- "packageManager": "pnpm@11.7.0"
67
- }
1
+ {
2
+ "name": "dsh-voice",
3
+ "version": "0.3.0",
4
+ "description": "DSH 语音双件套插件:voice_tts(edge-tts 协议零成本微软神经语音合成)/ voice_stt(OpenAI 兼容 ASR 语音转文字)/ voice_list(音色列表),原生 WebSocket + 插件级代理。",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./cordis.patch.yml": "./cordis.patch.yml",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "lib",
18
+ "cordis.patch.yml",
19
+ "README.md",
20
+ "README.en.md"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.json",
24
+ "typecheck": "tsc -p tsconfig.json --noEmit",
25
+ "test": "pnpm run build && node --test \"test/*.test.mjs\"",
26
+ "prepublishOnly": "pnpm run build"
27
+ },
28
+ "dsh": {
29
+ "bundle": {
30
+ "patch": "./cordis.patch.yml"
31
+ }
32
+ },
33
+ "keywords": [
34
+ "dsh",
35
+ "deepseek-harness",
36
+ "plugin",
37
+ "tts",
38
+ "stt",
39
+ "whisper",
40
+ "voice",
41
+ "dsh-plugin"
42
+ ],
43
+ "license": "MIT",
44
+ "engines": {
45
+ "node": ">=22"
46
+ },
47
+ "dependencies": {
48
+ "https-proxy-agent": "^9.1.0",
49
+ "undici": "^8.10.0",
50
+ "ws": "^8.21.3"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^24.0.0",
54
+ "@types/ws": "^8.18.1",
55
+ "typescript": "^5.6.0"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/STARDUSTLC666/dsh-voice.git"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/STARDUSTLC666/dsh-voice/issues"
63
+ },
64
+ "homepage": "https://github.com/STARDUSTLC666/dsh-voice#readme",
65
+ "author": "stardustlc",
66
+ "packageManager": "pnpm@11.7.0"
67
+ }