dsh-audiogen 0.2.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/src/protocol.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  export const AUDIOGEN_SETTINGS_NAMESPACE = 'dsh-audiogen'
9
9
 
10
10
  /** Published package version shared by the host updater and the client UI. */
11
- export const PLUGIN_VERSION = '0.2.0'
11
+ export const PLUGIN_VERSION = '0.3.0'
12
12
 
13
13
  /** Same-origin route family (loopback-only, mirroring dsh-imagegen). */
14
14
  export const SETTINGS_API = {
@@ -45,7 +45,7 @@ export const HISTORY_API = {
45
45
  export const HISTORY_MAX = 50
46
46
 
47
47
  /** Audio generation modes. */
48
- export type AudioMode = 'tts' | 'music' | 'sfx'
48
+ export type AudioMode = 'tts' | 'music' | 'sfx' | 'voice_design'
49
49
 
50
50
  /** The capability category of an audio model/voice. */
51
51
  export type AudioModelCategory =
@@ -106,6 +106,8 @@ export interface GenerateAudioRequest {
106
106
  prompt: string
107
107
  /** Optional voice alias for TTS. */
108
108
  voice?: string
109
+ /** Optional preview text for voice-design APIs. */
110
+ previewText?: string
109
111
  /** Optional speaking rate / speed multiplier. */
110
112
  speed?: number
111
113
  /** Requested duration in seconds (music/sfx). */
@@ -134,6 +136,8 @@ export interface GeneratedAudio {
134
136
  url: string
135
137
  /** Stable audio id / file name. */
136
138
  id: string
139
+ /** Optional voice id returned by a voice-design API. */
140
+ voiceId?: string
137
141
  }
138
142
 
139
143
  /** Successful generate outcome. */
@@ -153,6 +157,8 @@ export interface HistoryAudioRef {
153
157
  mime: string
154
158
  /** Duration in seconds when known. */
155
159
  duration?: number
160
+ /** Optional generated voice id. */
161
+ voiceId?: string
156
162
  }
157
163
 
158
164
  /** A saved generation as the browser consumes it. */
@@ -163,6 +169,7 @@ export interface HistoryEntry {
163
169
  model: string
164
170
  prompt: string
165
171
  voice?: string
172
+ voiceId?: string
166
173
  speed?: number
167
174
  duration?: number
168
175
  format?: string
@@ -179,6 +186,7 @@ export interface HistoryEntryInput {
179
186
  model: string
180
187
  prompt: string
181
188
  voice?: string
189
+ voiceId?: string
182
190
  speed?: number
183
191
  duration?: number
184
192
  format?: string
package/src/routes.ts CHANGED
@@ -90,7 +90,7 @@ function messageOf(error: unknown): string {
90
90
  }
91
91
 
92
92
  function parseGenerateRequest(body: Record<string, unknown>): GenerateAudioRequest | undefined {
93
- const mode = body.mode === 'music' ? 'music' : body.mode === 'sfx' ? 'sfx' : 'tts'
93
+ const mode = body.mode === 'music' ? 'music' : body.mode === 'sfx' ? 'sfx' : body.mode === 'voice_design' ? 'voice_design' : 'tts'
94
94
  const prompt = typeof body.prompt === 'string' ? body.prompt.trim() : ''
95
95
  if (prompt === '') return undefined
96
96
  return {
@@ -98,6 +98,7 @@ function parseGenerateRequest(body: Record<string, unknown>): GenerateAudioReque
98
98
  model: typeof body.model === 'string' ? body.model.trim() : '',
99
99
  prompt,
100
100
  ...(typeof body.voice === 'string' && body.voice.trim() !== '' ? { voice: body.voice.trim() } : {}),
101
+ ...(typeof body.previewText === 'string' && body.previewText.trim() !== '' ? { previewText: body.previewText.trim() } : {}),
101
102
  ...(typeof body.speed === 'number' ? { speed: body.speed } : {}),
102
103
  ...(typeof body.duration === 'number' ? { duration: body.duration } : {}),
103
104
  ...(typeof body.format === 'string' && body.format.trim() !== '' ? { format: body.format.trim() } : {}),
@@ -141,6 +142,10 @@ function resolveChannelRequest(
141
142
  const target = explicit ?? defaults
142
143
  const asked = request.model.trim()
143
144
  if (asked === '') {
145
+ if (request.mode === 'voice_design') {
146
+ if (target === undefined) return { ok: false, code: 'no-channels', message: '尚未配置任何渠道' }
147
+ return { ok: true, request: { ...request, channelId: target.id, channel: target.name } }
148
+ }
144
149
  const alias = target?.models[0]?.alias ?? ''
145
150
  if (alias === '') {
146
151
  return { ok: false, code: 'no-models', message: `渠道「${target?.name ?? ''}」尚未配置模型/音色,请先在设置中添加` }
@@ -300,6 +305,7 @@ export function makeRoutes(deps: AudiogenRoutesDeps): WebRoute[] {
300
305
  mime: saved.mime,
301
306
  bytes: saved.bytes,
302
307
  url: `${AUDIO_API.file}/${encodeURIComponent(saved.file)}`,
308
+ ...(output.voiceId === undefined ? {} : { voiceId: output.voiceId }),
303
309
  })
304
310
  }
305
311
  let history