dsh-audiogen 0.4.22 → 0.4.24

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
@@ -1,9 +1,9 @@
1
- import { SettingsConflictError, installSettingsSection, settingsNamespace } from "@deepseek-ai/dsh-settings";
2
1
  import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
3
2
  import { fileURLToPath } from "node:url";
4
3
  import path, { dirname, join } from "node:path";
5
- import z from "schemastery";
4
+ import z from "@deepseek-ai/schemastery";
6
5
  import { randomUUID } from "node:crypto";
6
+ import { SettingsConflictError } from "@deepseek-ai/dsh-settings";
7
7
  import { mkdir, readFile, rename, rmdir, unlink, writeFile } from "node:fs/promises";
8
8
  import os from "node:os";
9
9
  import { defineTool } from "@deepseek-ai/dsh-tools";
@@ -342,6 +342,82 @@ async function openAITTS(channel, request, signal) {
342
342
  fallbackMime: "audio/mpeg"
343
343
  });
344
344
  }
345
+ const ELEVENLABS_OUTPUT_FORMATS = {
346
+ mp3: {
347
+ sampleRates: [
348
+ 22050,
349
+ 24e3,
350
+ 44100
351
+ ],
352
+ bitrates: {
353
+ 22050: [32],
354
+ 24e3: [48],
355
+ 44100: [
356
+ 32,
357
+ 64,
358
+ 96,
359
+ 128,
360
+ 192
361
+ ]
362
+ },
363
+ defaultSampleRate: 44100,
364
+ defaultBitrate: 128
365
+ },
366
+ pcm: {
367
+ sampleRates: [
368
+ 8e3,
369
+ 16e3,
370
+ 22050,
371
+ 24e3,
372
+ 32e3,
373
+ 44100,
374
+ 48e3
375
+ ],
376
+ defaultSampleRate: 44100
377
+ },
378
+ ulaw: {
379
+ sampleRates: [8e3],
380
+ defaultSampleRate: 8e3
381
+ },
382
+ alaw: {
383
+ sampleRates: [8e3],
384
+ defaultSampleRate: 8e3
385
+ },
386
+ opus: {
387
+ sampleRates: [48e3],
388
+ bitrates: { 48e3: [32] },
389
+ defaultSampleRate: 48e3,
390
+ defaultBitrate: 32
391
+ }
392
+ };
393
+ /**
394
+ * 把「格式 + 采样率 + 码率」组合为 ElevenLabs 的 output_format(codec_sample_rate_bitrate)。
395
+ * 三个参数都不给时返回 undefined(不发送该字段,交给上游默认)。
396
+ * 组合非法时给出可操作错误(列出合法值),而不是静默修改用户选择的参数。
397
+ * 注意码率单位:ElevenLabs 为 kbps(32/48/64/96/128/192),与 MiniMax 的 bps 不同。
398
+ */
399
+ function elevenLabsOutputFormat(request) {
400
+ const format = (request.format ?? "").trim().toLowerCase();
401
+ const sampleRate = request.sampleRate;
402
+ const bitrate = request.bitrate;
403
+ if (format === "" && sampleRate === void 0 && bitrate === void 0) return void 0;
404
+ const codec = format === "" ? "mp3" : format;
405
+ const spec = ELEVENLABS_OUTPUT_FORMATS[codec];
406
+ if (spec === void 0) throw new AudioGenError(`ElevenLabs 输出格式不支持「${codec}」:可用 ${Object.keys(ELEVENLABS_OUTPUT_FORMATS).join("/")}(output_format 为 codec_sample_rate_bitrate 组合枚举)`, "audio-bad-format");
407
+ let resolvedRate = sampleRate;
408
+ if (resolvedRate !== void 0 && !spec.sampleRates.includes(resolvedRate)) throw new AudioGenError(`ElevenLabs ${codec} 输出采样率仅支持 ${spec.sampleRates.join("/")}Hz(实际 ${resolvedRate}Hz)`, "audio-bad-format");
409
+ if (resolvedRate === void 0) resolvedRate = spec.defaultSampleRate;
410
+ let resolvedBitrate = bitrate;
411
+ if (resolvedBitrate !== void 0) {
412
+ const allowed = spec.bitrates?.[resolvedRate] ?? [];
413
+ if (allowed.length === 0 || !allowed.includes(resolvedBitrate)) throw new AudioGenError(`ElevenLabs ${codec}_${resolvedRate} 输出码率仅支持 ${allowed.length === 0 ? "无(该编码不带码率)" : allowed.join("/")}kbps(实际 ${resolvedBitrate}kbps)`, "audio-bad-format");
414
+ }
415
+ if (resolvedBitrate === void 0) {
416
+ const rates = spec.bitrates?.[resolvedRate] ?? [];
417
+ resolvedBitrate = spec.defaultBitrate !== void 0 && rates.includes(spec.defaultBitrate) ? spec.defaultBitrate : rates[0];
418
+ }
419
+ return resolvedBitrate === void 0 ? `${codec}_${resolvedRate}` : `${codec}_${resolvedRate}_${resolvedBitrate}`;
420
+ }
345
421
  async function elevenLabsOfficial(channel, request, signal) {
346
422
  const base = endpointBase(channel.apiUrl);
347
423
  const model = (request.upstream ?? request.model) || "eleven_multilingual_v2";
@@ -416,9 +492,11 @@ async function elevenLabsOfficial(channel, request, signal) {
416
492
  if (request.mode === "sfx") {
417
493
  const endpoint = `${base}/sound-generation`;
418
494
  const sfxModel = (request.upstream ?? request.model) || "eleven_text_to_sound_v2";
495
+ const outputFormat = elevenLabsOutputFormat(request);
419
496
  const body = {
420
497
  text: request.prompt,
421
498
  model_id: sfxModel,
499
+ ...outputFormat === void 0 ? {} : { output_format: outputFormat },
422
500
  ...request.duration !== void 0 && Number.isFinite(request.duration) ? { duration_seconds: Math.min(30, Math.max(.5, request.duration)) } : {},
423
501
  ...request.loop !== void 0 ? { loop: request.loop } : {},
424
502
  ...request.promptInfluence !== void 0 && Number.isFinite(request.promptInfluence) ? { prompt_influence: Math.min(1, Math.max(0, request.promptInfluence)) } : {}
@@ -3012,7 +3090,7 @@ function makeRoutes(deps) {
3012
3090
  }
3013
3091
  const expectedRevision = typeof body.expectedRevision === "number" ? body.expectedRevision : void 0;
3014
3092
  try {
3015
- await deps.settings.mutate(settingsNamespace(ns), body.ops, expectedRevision);
3093
+ await deps.settings.mutate(ns, body.ops, expectedRevision);
3016
3094
  } catch (error) {
3017
3095
  writeJson(res, 200, failureOf(error));
3018
3096
  return;
@@ -4142,7 +4220,7 @@ function registerAgentAudioTools(ctx, resolve) {
4142
4220
  },
4143
4221
  format: {
4144
4222
  type: "string",
4145
- description: "Output format such as mp3 or wav. MiniMax music supports mp3/wav/pcm."
4223
+ description: "Output format. MiniMax music: mp3/wav/pcm. ElevenLabs sound effects: codec name mp3/pcm/ulaw/alaw/opus (combined with sample_rate and bitrate into the single output_format codec_sample_rate_bitrate, e.g. mp3_22050_32; pcm/ulaw/alaw carry no bitrate)."
4146
4224
  },
4147
4225
  emotion: {
4148
4226
  type: "string",
@@ -4171,11 +4249,11 @@ function registerAgentAudioTools(ctx, resolve) {
4171
4249
  },
4172
4250
  sample_rate: {
4173
4251
  type: "integer",
4174
- description: "MiniMax sample rate: music 16000/24000/32000/44100 (default 44100); tts default 32000 (audio_setting.sample_rate)."
4252
+ description: "Sample rate in Hz. MiniMax: music 16000/24000/32000/44100 (default 44100), tts default 32000 (audio_setting.sample_rate). ElevenLabs sound effects: 8000/16000/22050/24000/32000/44100/48000, combined with format and bitrate into the single output_format codec_sample_rate_bitrate."
4175
4253
  },
4176
4254
  bitrate: {
4177
4255
  type: "integer",
4178
- description: "MiniMax bitrate in bps: 32000/64000/128000/256000 (music default 256000, tts default 128000; audio_setting.bitrate)."
4256
+ description: "Bitrate. MiniMax in bps: 32000/64000/128000/256000 (music default 256000, tts default 128000). ElevenLabs sound effects in kbps: 32/48/64/96/128/192 (mp3/opus only; 192 kbps needs Creator plan or above), combined with format and sample_rate into the single output_format codec_sample_rate_bitrate."
4179
4257
  },
4180
4258
  channel: {
4181
4259
  type: "integer",
@@ -5228,8 +5306,8 @@ function resolveVoiceManagementChannel(config, requested) {
5228
5306
  const name = "audiogen";
5229
5307
  /** Services required before the surfaces can mount. */
5230
5308
  const inject = ["webServer", "systemPrompt"];
5231
- /** The branded settings namespace of this plugin. */
5232
- const AudioGenSettingsNamespace = settingsNamespace(AUDIOGEN_SETTINGS_NAMESPACE);
5309
+ /** The settings namespace of this plugin. */
5310
+ const AudioGenSettingsNamespace = AUDIOGEN_SETTINGS_NAMESPACE;
5233
5311
  const DEFAULT_MAX_CONCURRENT = 5;
5234
5312
  const Config = z.object({
5235
5313
  enabled: z.boolean().default(true),
@@ -5466,12 +5544,14 @@ function apply(ctx, config) {
5466
5544
  text: guidanceFor(value.channels, value.defaultChannelId)
5467
5545
  });
5468
5546
  };
5469
- installSettingsSection(ctx, AudioGenSettingsNamespace, Config, config ?? {}, {
5470
- setSource: (source) => {
5471
- current = source;
5472
- sync();
5473
- },
5474
- onChange: sync
5547
+ ctx.inject(["settings"], (settingsCtx) => {
5548
+ settingsCtx.settings.installSection(ctx, AudioGenSettingsNamespace, Config, config ?? {}, {
5549
+ setSource: (source) => {
5550
+ current = source;
5551
+ sync();
5552
+ },
5553
+ onChange: sync
5554
+ });
5475
5555
  });
5476
5556
  sync();
5477
5557
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-audiogen",
3
3
  "description": "AI audio generation plugin for the dsh web GUI: multi-vendor TTS/music/sound-effect channels (OpenAI-compatible, ElevenLabs, MiniMax, Stability AI and custom), per-channel model/voice catalogs, Agent tool and a sidebar AI 音频 panel.",
4
- "version": "0.4.22",
4
+ "version": "0.4.24",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -15,30 +15,30 @@
15
15
  },
16
16
  "client": {
17
17
  "inject": [
18
- "@deepseek-ai/dsh-client-runtime",
19
- "@deepseek-ai/dsh-client-connection",
20
- "@deepseek-ai/dsh-client-ui-settings",
21
- "@deepseek-ai/dsh-client-ui-tool"
18
+ "@deepseek-ai/dsh-client-connection"
22
19
  ],
23
20
  "platform": "web"
24
21
  }
25
22
  },
26
23
  "dependencies": {
27
- "schemastery": "^3.18.0"
24
+ "@deepseek-ai/schemastery": "^3.18.2"
28
25
  },
29
26
  "devDependencies": {
30
27
  "@deepseek-ai/cordis": "^4.0.1",
31
- "@deepseek-ai/dsh-client-connection": "0.1.0-rc.7",
32
- "@deepseek-ai/dsh-client-locale": "0.1.0-rc.7",
33
- "@deepseek-ai/dsh-client-runtime": "0.1.0-rc.7",
34
- "@deepseek-ai/dsh-client-ui-primitives": "0.1.0-rc.7",
35
- "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.7",
36
- "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.7",
37
- "@deepseek-ai/dsh-host-webserver": "0.1.0-rc.7",
38
- "@deepseek-ai/dsh-llm": "0.1.0-rc.7",
39
- "@deepseek-ai/dsh-settings": "0.1.0-rc.7",
40
- "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.7",
41
- "@deepseek-ai/dsh-tools": "0.1.0-rc.7",
28
+ "@deepseek-ai/dsh-client-connection": "0.1.2-alpha.3",
29
+ "@deepseek-ai/dsh-client-locale": "0.1.2-alpha.3",
30
+ "@deepseek-ai/dsh-client-store": "0.1.2-alpha.3",
31
+ "@deepseek-ai/dsh-client-ui-primitives": "0.1.2-alpha.3",
32
+ "@deepseek-ai/dsh-client-ui-renderer": "0.1.2-alpha.3",
33
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.2-alpha.3",
34
+ "@deepseek-ai/dsh-client-ui-settings-plugins": "0.1.2-alpha.3",
35
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.2-alpha.3",
36
+ "@deepseek-ai/dsh-client-ui-tool": "0.1.2-alpha.3",
37
+ "@deepseek-ai/dsh-host-webserver": "0.1.2-alpha.3",
38
+ "@deepseek-ai/dsh-llm": "0.1.2-alpha.3",
39
+ "@deepseek-ai/dsh-settings": "0.1.2-alpha.3",
40
+ "@deepseek-ai/dsh-system-prompt": "0.1.2-alpha.3",
41
+ "@deepseek-ai/dsh-tools": "0.1.2-alpha.3",
42
42
  "@types/node": "^22.20.0",
43
43
  "@types/react": "~18.3.1",
44
44
  "@types/react-dom": "^18.3.5",
@@ -46,9 +46,9 @@
46
46
  "lightningcss": "1.32.0",
47
47
  "react": "^18.3.1",
48
48
  "react-dom": "^18.3.1",
49
- "schemastery": "^3.18.0",
50
49
  "tsdown": "0.22.2",
51
- "typescript": "~5.7.2"
50
+ "typescript": "~5.7.2",
51
+ "vitest": "^3.2.0"
52
52
  },
53
53
  "files": [
54
54
  "lib",
@@ -90,6 +90,8 @@
90
90
  "build": "tsdown",
91
91
  "watch": "tsdown --watch",
92
92
  "typecheck": "tsc --noEmit",
93
- "prepublishOnly": "pnpm run typecheck && pnpm run build"
93
+ "test": "vitest run",
94
+ "test:watch": "vitest",
95
+ "prepublishOnly": "pnpm run typecheck && pnpm run test && pnpm run build"
94
96
  }
95
97
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: dsh-audiogen-sfx
3
- description: DSH AI 音频插件(dsh-audiogen)的音效生成技能:调用 generate_audio(mode=sfx);覆盖 ElevenLabs(/v1/sound-generation,eleven_text_to_sound_v2,loop 无缝循环、prompt_influence 0-1、duration_seconds 0.5-30)与 MiniMax、Stability 等渠道的对应字段与常见错误处理。
3
+ description: DSH AI 音频插件(dsh-audiogen)的音效生成技能:调用 generate_audio(mode=sfx);覆盖 ElevenLabs(/v1/sound-generation,eleven_text_to_sound_v2,loop 无缝循环、prompt_influence 0-1、duration_seconds 0.5-30、output_format 由 format/sample_rate/bitrate 组合)与 MiniMax、Stability 等渠道的对应字段与常见错误处理。
4
4
  whenToUse: 用户请求生成音效、提示音、环境音、UI 音,或触发 /audio:sfx 时使用。
5
5
  ---
6
6
  # 音效生成
@@ -15,7 +15,9 @@ whenToUse: 用户请求生成音效、提示音、环境音、UI 音,或触发
15
15
  - duration: 可选,秒数(ElevenLabs 0.5-30,留空则自动)
16
16
  - loop: 可选,ElevenLabs 无缝循环音效(仅 eleven_text_to_sound_v2)
17
17
  - prompt_influence: 可选,ElevenLabs 提示词影响度 0-1(默认 0.3,越高越贴近提示词、越少随机)
18
- - format: 可选
18
+ - format: 可选,ElevenLabs 编码名(mp3/pcm/ulaw/alaw/opus);与 sample_rate、bitrate 组合成单个 output_format
19
+ - sample_rate: 可选,ElevenLabs 采样率 Hz(mp3: 22050/24000/44100;pcm: 8000/16000/22050/24000/32000/44100/48000;ulaw/alaw: 仅 8000;opus: 仅 48000)
20
+ - bitrate: 可选,ElevenLabs 码率 kbps(mp3: 32/48/64/96/128/192,opus: 仅 32;192 需 Creator 及以上订阅;pcm/ulaw/alaw 无码率)
19
21
 
20
22
  ## 流程
21
23
  1. 确认已配置音效生成渠道。
@@ -28,6 +30,7 @@ whenToUse: 用户请求生成音效、提示音、环境音、UI 音,或触发
28
30
  | --- | --- | --- |
29
31
  | text | prompt | 必填,转换为音效的文本/描述 |
30
32
  | model_id | model | 官方枚举:eleven_text_to_sound_v2(默认) |
33
+ | output_format | format + sample_rate + bitrate | 单个枚举 codec_sample_rate_bitrate(如 mp3_22050_32);面板拆为「格式/采样率/码率」三个参数,引擎自动组合;mp3 默认 44100/128,pcm 默认 44100,opus 仅 48000/32,ulaw/alaw 仅 8000 |
31
34
  | duration_seconds | duration | 0.5-30 秒;留空由提示词推算最优时长 |
32
35
  | loop | loop | 是否生成平滑循环音效(仅 eleven_text_to_sound_v2) |
33
36
  | prompt_influence | prompt_influence | 0-1,默认 0.3;越高越贴提示词,越低越多样 |
@@ -38,4 +41,5 @@ whenToUse: 用户请求生成音效、提示音、环境音、UI 音,或触发
38
41
  > (404 Invalid URL / 401 Invalid token,例如 ai.farmmx.com 未映射 `/v1/sound-generation`),
39
42
  > 引擎自动改用 OpenAI 兼容形态重试:`POST {base}/audio/speech` + `Authorization: Bearer` +
40
43
  > `model=eleven_text_to_sound_v2` + `text/duration_seconds/prompt_influence/loop` 字段。
41
- > 官方地址(api.elevenlabs.io)直连时不触发回退。音色设计在网关无对应兼容端点,会明确报错不便死等。
44
+ > 官方地址(api.elevenlabs.io)直连时不触发回退,`output_format` 仅在官方端点生效。
45
+ > 音色设计在网关无对应兼容端点,会明确报错不便死等。
@@ -185,7 +185,7 @@ export function registerAgentAudioTools(ctx: Context, resolve: () => AgentAudioT
185
185
  seed: { type: 'integer', description: 'Stable Audio random seed 0-4294967294 (default 0 = random); same seed yields reproducible audio.' },
186
186
  steps: { type: 'integer', description: 'Stable Audio sampling steps, model-dependent: stable-audio-2 30-100, stable-audio-2.5/3 4-8 (out-of-range auto-clamped).' },
187
187
  cfg_scale: { type: 'number', description: 'Stable Audio prompt adherence 1-25 (stable-audio-2 default 7, 2.5/3 default 1); higher follows the prompt more strictly.' },
188
- format: { type: 'string', description: 'Output format such as mp3 or wav. MiniMax music supports mp3/wav/pcm.' },
188
+ format: { type: 'string', description: 'Output format. MiniMax music: mp3/wav/pcm. ElevenLabs sound effects: codec name mp3/pcm/ulaw/alaw/opus (combined with sample_rate and bitrate into the single output_format codec_sample_rate_bitrate, e.g. mp3_22050_32; pcm/ulaw/alaw carry no bitrate).' },
189
189
  // ---- MiniMax TTS only (ignored by other providers) ----
190
190
  emotion: { type: 'string', description: 'MiniMax TTS emotion, e.g. happy/sad/angry/nervous/fearful/bored (voice_setting.emotion).' },
191
191
  vol: { type: 'number', description: 'MiniMax TTS volume 0-10, default 1 (voice_setting.vol).' },
@@ -193,8 +193,8 @@ export function registerAgentAudioTools(ctx: Context, resolve: () => AgentAudioT
193
193
  text_normalization: { type: 'boolean', description: 'MiniMax TTS text normalization switch (voice_setting.text_normalization).' },
194
194
  latex_read: { type: 'boolean', description: 'MiniMax TTS math formula reading switch (voice_setting.latex_read).' },
195
195
  pronunciation_tone: { type: 'array', items: { type: 'string' }, description: 'MiniMax TTS pronunciation dictionary tone entries, each "word/pronunciation", e.g. ["处理/(chu3)(li3)", "危险/dangerous"] (pronunciation_dict.tone).' },
196
- sample_rate: { type: 'integer', description: 'MiniMax sample rate: music 16000/24000/32000/44100 (default 44100); tts default 32000 (audio_setting.sample_rate).' },
197
- bitrate: { type: 'integer', description: 'MiniMax bitrate in bps: 32000/64000/128000/256000 (music default 256000, tts default 128000; audio_setting.bitrate).' },
196
+ sample_rate: { type: 'integer', description: 'Sample rate in Hz. MiniMax: music 16000/24000/32000/44100 (default 44100), tts default 32000 (audio_setting.sample_rate). ElevenLabs sound effects: 8000/16000/22050/24000/32000/44100/48000, combined with format and bitrate into the single output_format codec_sample_rate_bitrate.' },
197
+ bitrate: { type: 'integer', description: 'Bitrate. MiniMax in bps: 32000/64000/128000/256000 (music default 256000, tts default 128000). ElevenLabs sound effects in kbps: 32/48/64/96/128/192 (mp3/opus only; 192 kbps needs Creator plan or above), combined with format and sample_rate into the single output_format codec_sample_rate_bitrate.' },
198
198
  channel: { type: 'integer', description: 'MiniMax TTS audio channels: 1 or 2, default 1 (audio_setting.channel).' },
199
199
  force_cbr: { type: 'boolean', description: 'MiniMax TTS force CBR encoding (audio_setting.force_cbr).' },
200
200
  subtitle_enable: { type: 'boolean', description: 'MiniMax TTS subtitle output switch (subtitle_enable).' },
@@ -245,6 +245,77 @@ async function openAITTS(channel: AudioChannel, request: GenerateAudioRequest, s
245
245
  return normalizeAudioResponse(response, { apiKey: channel.apiKey, fallbackMime: 'audio/mpeg' })
246
246
  }
247
247
 
248
+ // ------------- ElevenLabs output_format(codec_sample_rate_bitrate) -------------
249
+ // 官方把输出格式编码为单个枚举(如 mp3_22050_32 / pcm_44100 / opus_48000_32),
250
+ // 面板/工具把「格式、采样率、码率」拆成三个参数,这里负责组合成 output_format。
251
+ // 组合规则见 /v1/sound-generation API 文档:codec_sample_rate_bitrate;
252
+ // MP3 192kbps 需 Creator 及以上订阅、44.1kHz PCM 需 Pro 及以上订阅(由上游校验)。
253
+ export const ELEVENLABS_OUTPUT_FORMATS: Record<string, {
254
+ /** 该编码合法的采样率(Hz)。 */
255
+ sampleRates: number[]
256
+ /** 采样率 → 合法码率(kbps);缺省表示该编码不带码率(pcm/ulaw/alaw)。 */
257
+ bitrates?: Record<number, number[]>
258
+ /** 未指定采样率/码率时使用的默认值。 */
259
+ defaultSampleRate: number
260
+ defaultBitrate?: number
261
+ }> = {
262
+ mp3: {
263
+ sampleRates: [22050, 24000, 44100],
264
+ bitrates: { 22050: [32], 24000: [48], 44100: [32, 64, 96, 128, 192] },
265
+ defaultSampleRate: 44100,
266
+ defaultBitrate: 128,
267
+ },
268
+ pcm: { sampleRates: [8000, 16000, 22050, 24000, 32000, 44100, 48000], defaultSampleRate: 44100 },
269
+ ulaw: { sampleRates: [8000], defaultSampleRate: 8000 },
270
+ alaw: { sampleRates: [8000], defaultSampleRate: 8000 },
271
+ opus: { sampleRates: [48000], bitrates: { 48000: [32] }, defaultSampleRate: 48000, defaultBitrate: 32 },
272
+ }
273
+
274
+ /**
275
+ * 把「格式 + 采样率 + 码率」组合为 ElevenLabs 的 output_format(codec_sample_rate_bitrate)。
276
+ * 三个参数都不给时返回 undefined(不发送该字段,交给上游默认)。
277
+ * 组合非法时给出可操作错误(列出合法值),而不是静默修改用户选择的参数。
278
+ * 注意码率单位:ElevenLabs 为 kbps(32/48/64/96/128/192),与 MiniMax 的 bps 不同。
279
+ */
280
+ export function elevenLabsOutputFormat(request: Pick<GenerateAudioRequest, 'format' | 'sampleRate' | 'bitrate'>): string | undefined {
281
+ const format = (request.format ?? '').trim().toLowerCase()
282
+ const sampleRate = request.sampleRate
283
+ const bitrate = request.bitrate
284
+ if (format === '' && sampleRate === undefined && bitrate === undefined) return undefined
285
+ const codec = format === '' ? 'mp3' : format
286
+ const spec = ELEVENLABS_OUTPUT_FORMATS[codec]
287
+ if (spec === undefined) {
288
+ throw new AudioGenError(
289
+ `ElevenLabs 输出格式不支持「${codec}」:可用 ${Object.keys(ELEVENLABS_OUTPUT_FORMATS).join('/')}(output_format 为 codec_sample_rate_bitrate 组合枚举)`,
290
+ 'audio-bad-format',
291
+ )
292
+ }
293
+ let resolvedRate = sampleRate
294
+ if (resolvedRate !== undefined && !spec.sampleRates.includes(resolvedRate)) {
295
+ throw new AudioGenError(`ElevenLabs ${codec} 输出采样率仅支持 ${spec.sampleRates.join('/')}Hz(实际 ${resolvedRate}Hz)`, 'audio-bad-format')
296
+ }
297
+ if (resolvedRate === undefined) resolvedRate = spec.defaultSampleRate
298
+ let resolvedBitrate: number | undefined = bitrate
299
+ if (resolvedBitrate !== undefined) {
300
+ const allowed = spec.bitrates?.[resolvedRate] ?? []
301
+ if (allowed.length === 0 || !allowed.includes(resolvedBitrate)) {
302
+ throw new AudioGenError(
303
+ `ElevenLabs ${codec}_${resolvedRate} 输出码率仅支持 ${allowed.length === 0 ? '无(该编码不带码率)' : allowed.join('/')}kbps(实际 ${resolvedBitrate}kbps)`,
304
+ 'audio-bad-format',
305
+ )
306
+ }
307
+ }
308
+ if (resolvedBitrate === undefined) {
309
+ // 未给码率:优先编码级默认值(仅当该采样率支持时);否则回填该采样率合法的首个码率
310
+ //(如 mp3_22050 只有 32kbps、mp3_24000 只有 48kbps),避免组合出 mp3_22050_128 这类非法值。
311
+ const rates = spec.bitrates?.[resolvedRate] ?? []
312
+ resolvedBitrate = spec.defaultBitrate !== undefined && rates.includes(spec.defaultBitrate)
313
+ ? spec.defaultBitrate
314
+ : rates[0]
315
+ }
316
+ return resolvedBitrate === undefined ? `${codec}_${resolvedRate}` : `${codec}_${resolvedRate}_${resolvedBitrate}`
317
+ }
318
+
248
319
  async function elevenLabsOfficial(channel: AudioChannel, request: GenerateAudioRequest, signal?: AbortSignal): Promise<Array<{ data: Uint8Array; mime: string; voiceId?: string }>> {
249
320
  const base = endpointBase(channel.apiUrl)
250
321
  const model = (request.upstream ?? request.model) || 'eleven_multilingual_v2'
@@ -331,12 +402,15 @@ async function elevenLabsOfficial(channel: AudioChannel, request: GenerateAudioR
331
402
  // ------------- ElevenLabs Sound Effects(POST /v1/sound-generation) -------------
332
403
  // 官方模型:eleven_text_to_sound_v2;text 必填;duration_seconds 0.5-30;
333
404
  // loop 仅该模型可用;prompt_influence 0-1(默认 0.3)。
405
+ // output_format 由「格式/采样率/码率」三个面板参数组合为 codec_sample_rate_bitrate。
334
406
  if (request.mode === 'sfx') {
335
407
  const endpoint = `${base}/sound-generation`
336
408
  const sfxModel = (request.upstream ?? request.model) || 'eleven_text_to_sound_v2'
409
+ const outputFormat = elevenLabsOutputFormat(request)
337
410
  const body: Record<string, unknown> = {
338
411
  text: request.prompt,
339
412
  model_id: sfxModel,
413
+ ...(outputFormat === undefined ? {} : { output_format: outputFormat }),
340
414
  ...(request.duration !== undefined && Number.isFinite(request.duration)
341
415
  ? { duration_seconds: Math.min(30, Math.max(0.5, request.duration)) }
342
416
  : {}),
@@ -14,7 +14,8 @@
14
14
 
15
15
  import { useEffect, useMemo, useState } from 'react'
16
16
  import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
17
- import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
17
+ import type {} from '@deepseek-ai/dsh-client-ui-settings-plugins/client'
18
+ import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
18
19
  import { CardForm, booleanField, textField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
19
20
  import { ChannelsForm, type ChannelDraft, type ChannelsFormActions, type ChannelsFormState } from './channels-form.ts'
20
21
  import type { AudiogenScope } from './settings-scope.ts'
@@ -5,19 +5,14 @@
5
5
  * URLs; this view turns it into a small audio-player card.
6
6
  */
7
7
 
8
- import type { ClientContext, SessionId } from '@deepseek-ai/dsh-client-runtime/client'
8
+ import type { Context as ClientContext } from '@deepseek-ai/cordis'
9
+ import type { ToolCallViewProps } from '@deepseek-ai/dsh-client-ui-tool/client'
10
+ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
9
11
  import { useEffect, useMemo, useState } from 'react'
10
12
  import css from './audio-toolview.module.css'
11
13
 
12
- export interface AudioToolViewOwnerProps {
13
- callId: string
14
- toolName: string
15
- block: unknown
16
- cwd?: string
17
- home?: string
18
- openFile: (path: string) => void
19
- inspect?: () => void
20
- }
14
+ /** Full props the atomic tool-view contract gives a keyed row renderer. */
15
+ export type AudioToolViewProps = ToolCallViewProps
21
16
 
22
17
  interface AudioFileRef {
23
18
  id?: string
@@ -26,10 +21,6 @@ interface AudioFileRef {
26
21
  bytes: number
27
22
  }
28
23
 
29
- interface AudioToolViewProps extends AudioToolViewOwnerProps {
30
- sessionId: SessionId
31
- }
32
-
33
24
  function isSettled(block: unknown): block is { content?: Array<{ type: string; text?: string }>; isError?: boolean } {
34
25
  return typeof block === 'object' && block !== null && 'content' in block
35
26
  }
@@ -12,7 +12,7 @@
12
12
  * - path ops never navigate *inside* the channels array.
13
13
  */
14
14
 
15
- import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
15
+ import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
16
16
  import type { ChannelConfig, ModelMapping } from '../protocol.ts'
17
17
  import type { AudiogenScope, SettingsOp } from './settings-scope.ts'
18
18
 
@@ -58,7 +58,7 @@ const MUSIC_FORMATS: Record<string, string[]> = {
58
58
 
59
59
  const MUSIC_KEYS: FieldKey[] = ['duration', 'format', 'lyrics', 'instrumental', 'sampleRate', 'bitrate']
60
60
  const TTS_KEYS: FieldKey[] = ['voice', 'speed', 'format', 'emotion', 'vol', 'pitch', 'toneText', 'sampleRate', 'bitrate', 'audioChannel', 'subtitle']
61
- const SFX_KEYS: FieldKey[] = ['duration', 'format', 'loop', 'promptInfluence', 'seed', 'steps', 'cfgScale']
61
+ const SFX_KEYS: FieldKey[] = ['duration', 'format', 'sampleRate', 'bitrate', 'loop', 'promptInfluence', 'seed', 'steps', 'cfgScale']
62
62
 
63
63
  export function presetSupports(preset: string, key: FieldKey, mode: AudioMode): boolean {
64
64
  const p = preset.toLowerCase()
@@ -70,6 +70,8 @@ export function presetSupports(preset: string, key: FieldKey, mode: AudioMode):
70
70
  return p === PRESET_MINIMAX || p === PRESET_ELEVENLABS
71
71
  case 'sampleRate':
72
72
  case 'bitrate':
73
+ // MiniMax:采样率/码率独立字段(audio_setting);ElevenLabs 仅音效:与格式组合为 output_format。
74
+ return p === PRESET_MINIMAX || (mode === 'sfx' && p === PRESET_ELEVENLABS)
73
75
  case 'audioChannel':
74
76
  return p === PRESET_MINIMAX
75
77
  case 'emotion':
@@ -116,6 +118,34 @@ function specOf(key: FieldKey, presets?: string[]): FieldSpec {
116
118
  return { key, ...SPECS[key], ...(presets === undefined ? {} : { presets }) }
117
119
  }
118
120
 
121
+ /** 各 preset 支持的音效输出编码(ElevenLabs 为 output_format 的 codec;Stability 为 mp3/wav)。 */
122
+ const SFX_FORMATS: Record<string, string[]> = {
123
+ [PRESET_ELEVENLABS]: ['mp3', 'pcm', 'ulaw', 'alaw', 'opus'],
124
+ [PRESET_STABILITY]: ['mp3', 'wav'],
125
+ }
126
+
127
+ /** ElevenLabs 音效 output_format 的采样率(Hz)与码率(kbps)枚举。 */
128
+ const ELEVENLABS_SFX_SAMPLE_RATES: string[] = ['8000', '16000', '22050', '24000', '32000', '44100', '48000']
129
+ const ELEVENLABS_SFX_BITRATES: string[] = ['32', '48', '64', '96', '128', '192']
130
+
131
+ /** 按(字段 × 渠道 preset × 模式)给出该字段的选项;未知组合返回 undefined(调用方回退全局选项)。
132
+ * 全局字段与「每模型覆盖」矩阵共用同一份枚举,避免两处选项不一致。 */
133
+ export function fieldOptionsFor(key: FieldKey, preset: string, mode?: AudioMode): string[] | undefined {
134
+ const p = preset.toLowerCase()
135
+ if (key === 'format') {
136
+ if (mode === 'sfx') return SFX_FORMATS[p] ?? ['mp3', 'wav', 'pcm']
137
+ if (mode === 'music') return MUSIC_FORMATS[p] ?? ['mp3', 'wav', 'pcm']
138
+ return undefined
139
+ }
140
+ if (key === 'sampleRate') {
141
+ return p === PRESET_ELEVENLABS ? ELEVENLABS_SFX_SAMPLE_RATES : p === PRESET_MINIMAX ? SPECS.sampleRate.options : undefined
142
+ }
143
+ if (key === 'bitrate') {
144
+ return p === PRESET_ELEVENLABS ? ELEVENLABS_SFX_BITRATES : p === PRESET_MINIMAX ? SPECS.bitrate.options : undefined
145
+ }
146
+ return undefined
147
+ }
148
+
119
149
  /** 当前模式 + 所选模型集合(渠道集合)对应的「全局字段」清单。 */
120
150
  export function globalFieldSpecs(mode: AudioMode | 'voice_recommend', presets: string[]): FieldSpec[] {
121
151
  if (mode === 'voice_recommend') return []
@@ -138,9 +168,30 @@ export function globalFieldSpecs(mode: AudioMode | 'voice_recommend', presets: s
138
168
  if (all('bitrate', MUSIC_KEYS) && presets.length > 0) list.push(specOf('bitrate'))
139
169
  } else if (mode === 'sfx') {
140
170
  list.push(specOf('duration'))
141
- list.push({ ...specOf('format'), options: ['mp3', 'wav', 'pcm'] })
171
+ // 格式选项取所有选中渠道支持的交集(无交集则回退 mp3)
172
+ const supported: string[][] = presets.length === 0 ? [['mp3', 'wav', 'pcm']] : presets.map(preset => SFX_FORMATS[preset.toLowerCase()] ?? ['mp3', 'wav'])
173
+ const intersect: string[] = supported.reduce<string[]>((acc, cur) => acc.filter(item => cur.includes(item)), supported[0] ?? ['mp3'])
174
+ list.push({ ...specOf('format'), options: intersect.length > 0 ? intersect : ['mp3'] })
142
175
  if (all('loop', SFX_KEYS) && presets.length > 0) list.push(specOf('loop'))
143
176
  if (all('promptInfluence', SFX_KEYS) && presets.length > 0) list.push(specOf('promptInfluence'))
177
+ // ElevenLabs 音效:采样率/码率与格式组合为 output_format(codec_sample_rate_bitrate),由引擎统一组合。
178
+ if (all('sampleRate', SFX_KEYS) && presets.length > 0) {
179
+ list.push({
180
+ ...specOf('sampleRate'),
181
+ options: presets.flatMap(preset => fieldOptionsFor('sampleRate', preset, mode) ?? []),
182
+ placeholder: '默认(44100)',
183
+ hint: 'ElevenLabs 音效采样率(Hz):与格式/码率组合为 output_format(如 mp3_22050_32);pcm/ulaw/alaw 不带码率',
184
+ })
185
+ }
186
+ if (all('bitrate', SFX_KEYS) && presets.length > 0) {
187
+ list.push({
188
+ ...specOf('bitrate'),
189
+ label: '码率(kbps)',
190
+ options: presets.flatMap(preset => fieldOptionsFor('bitrate', preset, mode) ?? []),
191
+ placeholder: '默认(128)',
192
+ hint: 'ElevenLabs 音效码率(kbps,注意非 bps):与格式/采样率组合为 output_format;192 需 Creator 及以上订阅',
193
+ })
194
+ }
144
195
  if (all('seed', SFX_KEYS) && presets.length > 0) list.push(specOf('seed'), specOf('steps'), specOf('cfgScale'))
145
196
  }
146
197
  return list
@@ -157,8 +208,9 @@ export function overrideRowSpecs(mode: AudioMode | 'voice_recommend'): Array<Fie
157
208
  ['speed', [PRESET_MINIMAX, PRESET_ELEVENLABS]],
158
209
  ['lyrics', [PRESET_MINIMAX, PRESET_ELEVENLABS]],
159
210
  ['instrumental', [PRESET_MINIMAX, PRESET_ELEVENLABS]],
160
- ['sampleRate', [PRESET_MINIMAX]],
161
- ['bitrate', [PRESET_MINIMAX]],
211
+ // 采样率/码率:MiniMax 独立字段(各模式);ElevenLabs 仅音效与格式组合为 output_format。
212
+ ['sampleRate', mode === 'sfx' ? [PRESET_ELEVENLABS] : [PRESET_MINIMAX]],
213
+ ['bitrate', mode === 'sfx' ? [PRESET_ELEVENLABS] : [PRESET_MINIMAX]],
162
214
  ['audioChannel', [PRESET_MINIMAX]],
163
215
  ['emotion', [PRESET_MINIMAX]],
164
216
  ['vol', [PRESET_MINIMAX]],
@@ -5,9 +5,10 @@
5
5
  * 音频), and mounts the sidebar entry + generation panel. DOM mounting
6
6
  * failures are logged, never thrown.
7
7
  */
8
- import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'
8
+ import type { Context as ClientContext } from '@deepseek-ai/cordis'
9
9
  import type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'
10
10
  import type {} from '@deepseek-ai/dsh-client-locale/client'
11
+ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
11
12
  import type {} from '@deepseek-ai/dsh-client-ui-slots'
12
13
  import { AudiogenApi } from './api.ts'
13
14
  import { AudioGenController } from './controller.ts'
@@ -25,25 +26,6 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
25
26
  interface LocaleNamespaceMap {
26
27
  'dsh-audiogen': AudioGenKey
27
28
  }
28
-
29
- interface SlotMap {
30
- 'settings.plugin.item': { kind: 'keyed'; scope: 'root'; owner: AudioGenPluginItemOwnerProps }
31
- 'tool.call.toolview': { kind: 'keyed'; scope: 'session'; owner: AudioToolViewOwnerProps }
32
- }
33
- }
34
-
35
- export interface AudioGenPluginItemOwnerProps {
36
- children?: never
37
- }
38
-
39
- export type AudioToolViewOwnerProps = {
40
- callId: string
41
- toolName: string
42
- block: unknown
43
- cwd?: string
44
- home?: string
45
- openFile: (path: string) => void
46
- inspect?: () => void
47
29
  }
48
30
 
49
31
  export const inject = ['slots', 'locale', 'connection', 'sessions']
@@ -7,7 +7,8 @@
7
7
  * sibling UI package).
8
8
  */
9
9
 
10
- import { createSnapshotStore, type SettingsScope, type SettingsScopeSnapshot, type SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
10
+ import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
11
+ import type { SettingsScope, SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
11
12
 
12
13
  /** The write one field's staged text performs when the card is saved. */
13
14
  export type FieldWrite =