cortico-world-doubao-tts 0.2.2 → 0.2.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/dist/webui.js CHANGED
@@ -170,6 +170,7 @@ const settings = {
170
170
 
171
171
  const previewInput = document.createElement('input');
172
172
  previewInput.type = 'text';
173
+ previewInput.maxLength = 500;
173
174
  previewInput.style.cssText = CSS.input;
174
175
  previewInput.placeholder = t ? '要播放/保存的文字,例如:你好,我是Coopanion。' : 'Text to play or save';
175
176
  previewInput.value = t ? '你好,我是Coopanion。' : 'Hello, this is Coopanion.';
@@ -507,7 +508,7 @@ const settings = {
507
508
  saveKeepInput.value = String(s.saveKeep ?? 200);
508
509
  savedHint.textContent = s.lastSaved
509
510
  ? (t ? `最近保存:${s.lastSaved}` : `Last saved: ${s.lastSaved}`)
510
- : (t ? '保存后这里会显示文件路径;文件名带时间和正文前几个字。' : 'The saved file path appears here; the name carries the time and the first words.');
511
+ : (t ? '保存后这里会显示文件路径;文件名带时间和正文前几个字。单段最多 500 字。' : 'The saved file path appears here; the name carries the time and the first words. Up to 500 characters.');
511
512
  savedHint.style.color = s.lastSaved ? '#37b24d' : '';
512
513
  savedHint.style.fontWeight = s.lastSaved ? '600' : '';
513
514
  shortLimitInput.style.display = s.shortOnly === true ? '' : 'none';
@@ -536,7 +537,6 @@ const settings = {
536
537
  quietHoursEnabled: '生效时间段',
537
538
  quietStart: '生效开始',
538
539
  quietEnd: '生效结束',
539
- saveAudio: '保存音频',
540
540
  saveDir: '保存目录',
541
541
  saveKeep: '保留数量',
542
542
  speechRate: '语速',
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "cortico-world-doubao-tts",
3
- "version": "0.2.2",
4
- "type": "module",
5
- "description": "让桌宠用豆包(火山引擎)TTS 2.0 读出气泡内容:360 个 2.0 音色可按场景、语种、标签筛选,支持语音指令(方言/情绪)、语速音量音调调节;配置页还能试听并把任意文字导出成 mp3。",
6
- "author": "lotice",
7
- "license": "MIT",
8
- "os": [
9
- "win32"
10
- ],
11
- "engines": {
12
- "node": ">=22"
13
- },
14
- "keywords": [
15
- "cortico-world",
16
- "cortico",
17
- "coopanion",
18
- "tts",
19
- "doubao",
20
- "volcengine",
21
- "豆包语音",
22
- "语音合成",
23
- "方言",
24
- "voice"
25
- ],
26
- "main": "./src/index.ts",
27
- "files": [
28
- "src",
29
- "dist",
30
- "assets",
31
- "describe.json",
32
- "README.md",
33
- "LICENSE"
34
- ],
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "cortico": {
39
- "kind": "world",
40
- "api": 6,
41
- "displayName": "豆包语音",
42
- "icon": "assets/icon.png",
43
- "tags": [
44
- "voice",
45
- "coopanion",
46
- "requires-key",
47
- "internet"
48
- ],
49
- "describe": "describe.json",
50
- "webUiClient": "dist/webui.js",
51
- "locales": {
52
- "zh": {
53
- "displayName": "豆包语音",
54
- "description": "让桌宠用豆包(火山引擎)TTS 2.0 读出气泡内容:360 个 2.0 音色可按场景、语种、标签筛选;支持语音指令(四川话、情绪)、语速/音量/音调/句尾静音调节;配置页可试听,也能把文字导出成 mp3(方便发 QQ),同一句先听后存只合成一次。"
55
- },
56
- "en": {
57
- "displayName": "Doubao voice",
58
- "description": "Reads the pet's bubbles aloud with Doubao (Volcengine) TTS 2.0: 360 voices filterable by scene, language and tag; instruction control for dialect, emotion and tone; adjustable rate, loudness and pitch; and an in-panel preview that can also export any text to mp3 (handy for QQ) — preview then save synthesizes only once."
59
- }
60
- }
61
- }
62
- }
1
+ {
2
+ "name": "cortico-world-doubao-tts",
3
+ "version": "0.2.3",
4
+ "type": "module",
5
+ "description": "让桌宠用豆包(火山引擎)TTS 2.0 读出气泡内容:360 个 2.0 音色可按场景、语种、标签筛选,支持语音指令(方言/情绪)、语速音量音调调节;配置页还能试听并把任意文字导出成 mp3。",
6
+ "author": "lotice",
7
+ "license": "MIT",
8
+ "os": [
9
+ "win32"
10
+ ],
11
+ "engines": {
12
+ "node": ">=22"
13
+ },
14
+ "keywords": [
15
+ "cortico-world",
16
+ "cortico",
17
+ "coopanion",
18
+ "tts",
19
+ "doubao",
20
+ "volcengine",
21
+ "豆包语音",
22
+ "语音合成",
23
+ "方言",
24
+ "voice"
25
+ ],
26
+ "main": "./src/index.ts",
27
+ "files": [
28
+ "src",
29
+ "dist",
30
+ "assets",
31
+ "describe.json",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "cortico": {
39
+ "kind": "world",
40
+ "api": 6,
41
+ "displayName": "豆包语音",
42
+ "icon": "assets/icon.png",
43
+ "tags": [
44
+ "voice",
45
+ "coopanion",
46
+ "requires-key",
47
+ "internet"
48
+ ],
49
+ "describe": "describe.json",
50
+ "webUiClient": "dist/webui.js",
51
+ "locales": {
52
+ "zh": {
53
+ "displayName": "豆包语音",
54
+ "description": "让桌宠用豆包(火山引擎)TTS 2.0 读出气泡内容:360 个 2.0 音色可按场景、语种、标签筛选;支持语音指令(四川话、情绪)、语速/音量/音调/句尾静音调节;配置页可试听,也能把文字导出成 mp3(方便发 QQ),同一句先听后存只合成一次。"
55
+ },
56
+ "en": {
57
+ "displayName": "Doubao voice",
58
+ "description": "Reads the pet's bubbles aloud with Doubao (Volcengine) TTS 2.0: 360 voices filterable by scene, language and tag; instruction control for dialect, emotion and tone; adjustable rate, loudness and pitch; and an in-panel preview that can also export any text to mp3 (handy for QQ) — preview then save synthesizes only once."
59
+ }
60
+ }
61
+ }
62
+ }
package/src/config.ts CHANGED
@@ -82,8 +82,6 @@ export interface DoubaoTtsConfig {
82
82
  quietStart: string;
83
83
  /** 生效时间段结束,HH:mm。 */
84
84
  quietEnd: string;
85
- /** 保存音频:每次合成后把 mp3 另存到磁盘。 */
86
- saveAudio: boolean;
87
85
  /** 保存目录;空表示 <数据目录>/saved-audio。 */
88
86
  saveDir: string;
89
87
  /** 最多保留多少个文件,超出删最旧的。 */
@@ -113,7 +111,6 @@ export const DEFAULTS: DoubaoTtsConfig = {
113
111
  quietHoursEnabled: false,
114
112
  quietStart: '23:00',
115
113
  quietEnd: '08:00',
116
- saveAudio: false,
117
114
  saveDir: '',
118
115
  saveKeep: 200,
119
116
  promptLanguage: 'zh',
package/src/world.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import { mkdir, readdir, rm, writeFile } from 'node:fs/promises';
9
9
  import { join } from 'node:path';
10
10
  import { fileURLToPath } from 'node:url';
11
- import { execFile, type ChildProcess } from 'node:child_process';
11
+ import { execFile, spawn, type ChildProcess } from 'node:child_process';
12
12
  import { promisify } from 'node:util';
13
13
  import type { Language } from 'cortico/core/language.ts';
14
14
  import type { ToolDef, ToolOutcome, World, WorldHost, WorldLamp, WorldWebUiDecl } from 'cortico/core/types.ts';
@@ -149,13 +149,22 @@ export class DoubaoWorld implements World {
149
149
  private async openFolder(): Promise<string> {
150
150
  const dir = (this.cfg.saveDir || '').trim() || join(this.opts.dataDir, 'saved-audio');
151
151
  await mkdir(dir, { recursive: true });
152
- const run = promisify(execFile);
153
- try {
154
- await run('explorer.exe', [dir], { windowsHide: false });
155
- } catch {
156
- // explorer 有时不认直接参数,改用 start
157
- await run('cmd.exe', ['/c', 'start', '', dir], { windowsHide: false });
158
- }
152
+ // explorer 打开成功后也常返回非 0;只有真的启动失败(ENOENT)才退回 start,
153
+ // 否则会弹两个窗口。
154
+ await new Promise<void>((resolve) => {
155
+ const child = spawn('explorer.exe', [dir], { windowsHide: false, stdio: 'ignore' });
156
+ let done = false;
157
+ const fallback = () => {
158
+ if (done) return;
159
+ done = true;
160
+ const alt = spawn('cmd.exe', ['/c', 'start', '', dir], { windowsHide: false, stdio: 'ignore' });
161
+ alt.once('exit', () => resolve());
162
+ alt.once('error', () => resolve());
163
+ };
164
+ child.once('error', fallback);
165
+ child.once('exit', () => { if (!done) { done = true; resolve(); } });
166
+ child.once('close', () => { if (!done) { done = true; resolve(); } });
167
+ });
159
168
  return dir;
160
169
  }
161
170
 
@@ -211,7 +220,7 @@ export class DoubaoWorld implements World {
211
220
  await mkdir(dir, { recursive: true });
212
221
  const d = new Date();
213
222
  const pad = (n: number) => String(n).padStart(2, '0');
214
- const stamp = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
223
+ const stamp = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}${String(d.getMilliseconds()).padStart(3, '0')}`;
215
224
  const slug = text.replace(/[\\/:*?"<>|\s]+/g, '').slice(0, 12) || 'audio';
216
225
  const file = join(dir, `${stamp}-${slug}.mp3`);
217
226
  await writeFile(file, audio);
@@ -226,27 +235,6 @@ export class DoubaoWorld implements World {
226
235
  return { ok: true, path: file };
227
236
  }
228
237
 
229
- /** 保存音频:把合成好的 mp3 另存一份,并按 saveKeep 删旧文件。 */
230
- private async saveCopy(audio: Buffer, text: string): Promise<void> {
231
- if (!this.cfg.saveAudio) return;
232
- const dir = (this.cfg.saveDir || '').trim() || join(this.opts.dataDir, 'saved-audio');
233
- await mkdir(dir, { recursive: true });
234
- const d = new Date();
235
- const pad = (n: number) => String(n).padStart(2, '0');
236
- const stamp = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
237
- const slug = text.replace(/[\\/:*?"<>|\s]+/g, '').slice(0, 12) || 'audio';
238
- const file = join(dir, `${stamp}-${slug}.mp3`);
239
- await writeFile(file, audio);
240
- this.lastSaved = file;
241
- const keep = Math.max(1, Math.min(5000, Number(this.cfg.saveKeep) || 200));
242
- try {
243
- const names = (await readdir(dir)).filter((n) => n.endsWith('.mp3')).sort();
244
- for (const old of names.slice(0, Math.max(0, names.length - keep))) {
245
- await rm(join(dir, old), { force: true }).catch(() => {});
246
- }
247
- } catch { /* 清理失败不影响保存 */ }
248
- }
249
-
250
238
  /** 省消耗:只念短句 / 只在生效时间段出声。返回跳过原因,或 null 表示照常念。 */
251
239
  private skipReason(text: string): string | null {
252
240
  const zh = this.text().zh;
@@ -404,7 +392,6 @@ export class DoubaoWorld implements World {
404
392
  quietHoursEnabled: this.cfg.quietHoursEnabled === true,
405
393
  quietStart: this.cfg.quietStart,
406
394
  quietEnd: this.cfg.quietEnd,
407
- saveAudio: this.cfg.saveAudio === true,
408
395
  saveDir: this.cfg.saveDir,
409
396
  saveKeep: this.cfg.saveKeep,
410
397
  lastSaved: this.lastSaved,
@@ -420,7 +407,7 @@ export class DoubaoWorld implements World {
420
407
  'speechRate', 'loudnessRate', 'pitch', 'volume', 'promptLanguage',
421
408
  'explicitLanguage', 'explicitDialect', 'silenceDuration', 'filterEmoji', 'bitRate',
422
409
  'shortOnly', 'shortLimit', 'quietHoursEnabled', 'quietStart', 'quietEnd',
423
- 'saveAudio', 'saveDir', 'saveKeep',
410
+ 'saveDir', 'saveKeep',
424
411
  ]);
425
412
 
426
413
  private setValues(patch: Record<string, unknown>): Record<string, unknown> {