@plume-canvas/cloud-server 0.0.0-stage → 0.1.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/README.md +18 -2
- package/builtin-manifest.json +28 -0
- package/dist/cli.js +81 -0
- package/dist/index.d.ts +3555 -0
- package/dist/index.js +38 -0
- package/package.json +51 -4
- package/providers/seed-audio-volc.js +402 -0
- package/providers/seed-audio.js +376 -0
- package/providers/web2api-audio.js +500 -0
- package/providers/web2api-image.js +497 -0
- package/providers/web2api-video.js +490 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web2api · 音频生成(provider,自包含单文件)
|
|
3
|
+
*
|
|
4
|
+
* 两条动作都是**同步**完成的:web2api 的 tts / generate-audio 直接返回音频资源,
|
|
5
|
+
* 没有 taskId,所以 submit 拿到产物后直接回 { done: true, urls }。
|
|
6
|
+
* 万一服务端以后改回异步(返回 taskId),这里也能退化到轮询。
|
|
7
|
+
*
|
|
8
|
+
* 环境变量:WEB2API_BASE / WEB2API_API_KEY。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 服务地址与密钥:优先「平台管理」页存的配置(__mcProviderConfig,装载时注入),
|
|
13
|
+
* 回落环境变量(老部署兼容)。多账号:submit 按选中的账号 id 取对应那套值。
|
|
14
|
+
*/
|
|
15
|
+
function injected() {
|
|
16
|
+
return typeof __mcProviderConfig === 'undefined' ? { accounts: [], values: {}, byId: {} } : __mcProviderConfig
|
|
17
|
+
}
|
|
18
|
+
function accountValues(values) {
|
|
19
|
+
const inj = injected()
|
|
20
|
+
const preferred = values && typeof values.__accountId === 'string' ? values.__accountId : ''
|
|
21
|
+
if (preferred && inj.byId && inj.byId[preferred]) return inj.byId[preferred]
|
|
22
|
+
const accounts = inj.accounts || []
|
|
23
|
+
if (accounts.length > 0) return accounts[0].values || {}
|
|
24
|
+
return inj.values || {}
|
|
25
|
+
}
|
|
26
|
+
function baseOf(values) {
|
|
27
|
+
const b = values && typeof values.baseUrl === 'string' && values.baseUrl.trim()
|
|
28
|
+
? values.baseUrl.trim()
|
|
29
|
+
: (process.env.WEB2API_BASE || 'http://localhost:8033')
|
|
30
|
+
return String(b).replace(/\/+$/, '')
|
|
31
|
+
}
|
|
32
|
+
const BASE = baseOf(injected().values || {})
|
|
33
|
+
|
|
34
|
+
async function api(path, init = {}, timeoutMs = 120000, values) {
|
|
35
|
+
const ac = new AbortController()
|
|
36
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs)
|
|
37
|
+
try {
|
|
38
|
+
const headers = { 'Content-Type': 'application/json', Accept: 'application/json', ...(init.headers || {}) }
|
|
39
|
+
const key = values && values.apiKey ? values.apiKey : process.env.WEB2API_API_KEY
|
|
40
|
+
if (key) headers.Authorization = 'Bearer ' + key
|
|
41
|
+
const res = await fetch(baseOf(values) + path, { ...init, headers, signal: ac.signal })
|
|
42
|
+
const text = await res.text()
|
|
43
|
+
let body
|
|
44
|
+
try {
|
|
45
|
+
body = text ? JSON.parse(text) : {}
|
|
46
|
+
} catch {
|
|
47
|
+
throw new Error('web2api 返回的不是 JSON(HTTP ' + res.status + ')')
|
|
48
|
+
}
|
|
49
|
+
if (body && typeof body.code === 'number' && body.code !== 0) {
|
|
50
|
+
throw new Error(body.message || 'web2api 错误 ' + body.code)
|
|
51
|
+
}
|
|
52
|
+
if (!res.ok) throw new Error(body && body.message ? body.message : 'web2api HTTP ' + res.status)
|
|
53
|
+
return body
|
|
54
|
+
} catch (err) {
|
|
55
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
56
|
+
if (err instanceof Error && err.name === 'AbortError') {
|
|
57
|
+
throw new Error('web2api 请求超时(' + baseOf(values) + ')')
|
|
58
|
+
}
|
|
59
|
+
if (/fetch failed|ECONNREFUSED|Failed to fetch|NetworkError/i.test(msg)) {
|
|
60
|
+
throw new Error('连不上 web2api(' + baseOf(values) + ')。请先启动它,或在「平台」页配置服务地址')
|
|
61
|
+
}
|
|
62
|
+
throw new Error(msg || 'web2api 调用失败')
|
|
63
|
+
} finally {
|
|
64
|
+
clearTimeout(timer)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function cleanValues(values) {
|
|
69
|
+
const out = {}
|
|
70
|
+
for (const [k, v] of Object.entries(values || {})) {
|
|
71
|
+
if (v === undefined || v === null || v === '') continue
|
|
72
|
+
out[k] = v
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 上游文本素材 → 带名字的标签块。
|
|
79
|
+
*
|
|
80
|
+
* 用户口径(2026-11-08):文本不要悄悄拼成一大段,要能「按名字引用」——
|
|
81
|
+
* 连进来的文本给一个名字(节点标题优先,没有就 文本1 / 文本2…),
|
|
82
|
+
* 正文包在标籤里交给上游;用户在自己的提示词里写 @标题内容 / @文本1 就能指到它。
|
|
83
|
+
*
|
|
84
|
+
* 为什么用标签而不是纯文本:纯文本拼在一起后,模型分不清哪段是「资料」、
|
|
85
|
+
* 哪段是「我的指令」,也对应不上引用名。标签把边界和名字都写清楚。
|
|
86
|
+
*/
|
|
87
|
+
/** 资源在数组里的位置就是它的引用索引(从 1 开始);平台只认序号,不认节点名 */
|
|
88
|
+
function refLabel(resource, index) {
|
|
89
|
+
const kind = resource && typeof resource.kind === 'string' ? resource.kind : ''
|
|
90
|
+
const prefix =
|
|
91
|
+
kind === 'image' ? '图片'
|
|
92
|
+
: kind === 'video' ? '视频'
|
|
93
|
+
: kind === 'audio' ? '音频'
|
|
94
|
+
: kind === 'text' ? '文本'
|
|
95
|
+
: '资源'
|
|
96
|
+
return prefix + (index + 1)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function textBlocks(input) {
|
|
100
|
+
const out = []
|
|
101
|
+
const resources = input.resources || []
|
|
102
|
+
resources.forEach((r, i) => {
|
|
103
|
+
if (!r || r.kind !== 'text') return
|
|
104
|
+
const value = typeof r.value === 'string' ? r.value : ''
|
|
105
|
+
out.push('<text name="' + refLabel(r, i) + '">\n' + value + '\n</text>')
|
|
106
|
+
})
|
|
107
|
+
return out
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 提示词分段 → 平台要的一段文字(标签按资源在数组里的「类型+序号」展开) */
|
|
111
|
+
function promptText(input) {
|
|
112
|
+
const labels = new Map()
|
|
113
|
+
const resources = input.resources || []
|
|
114
|
+
resources.forEach((r, i) => {
|
|
115
|
+
if (r && typeof r.id === 'string' && r.id) labels.set(r.id, refLabel(r, i))
|
|
116
|
+
})
|
|
117
|
+
let out = ''
|
|
118
|
+
for (const seg of input.prompts || []) {
|
|
119
|
+
if (!seg || typeof seg.value !== 'string') continue
|
|
120
|
+
if (seg.type === 'tag') {
|
|
121
|
+
out += '@' + (labels.get(seg.value) || seg.value)
|
|
122
|
+
} else {
|
|
123
|
+
out += seg.value
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 一张参考音频 → web2api 能读的地址。
|
|
131
|
+
*
|
|
132
|
+
* 为什么不能直接把 data URL 丢给 referenceAudios:火山引擎那条走的是
|
|
133
|
+
* resolveRefPath(只认本机文件 / 相对路径),不像图片那样会落盘 data URL。
|
|
134
|
+
* 所以这里先经 web2api 的上传接口换成它本机的 /<hash>.<ext>,再下单。
|
|
135
|
+
*
|
|
136
|
+
* 三种输入:
|
|
137
|
+
* - 已经是 /<hash>.<ext> 或 /api/resources/uploads/... → 原样(就在它本机)
|
|
138
|
+
* - data:... → 直接上传字节
|
|
139
|
+
* - http(s)://... → 先取字节再上传
|
|
140
|
+
*/
|
|
141
|
+
async function toLocalRef(url) {
|
|
142
|
+
const s = String(url || '').trim()
|
|
143
|
+
if (!s) return ''
|
|
144
|
+
if (s.startsWith('/api/resources/uploads/')) return s
|
|
145
|
+
if (/^\/[^/]/.test(s) && !s.startsWith('/api/')) return s
|
|
146
|
+
|
|
147
|
+
let buf
|
|
148
|
+
let mime = ''
|
|
149
|
+
let filename = ''
|
|
150
|
+
if (/^data:/i.test(s)) {
|
|
151
|
+
const m = /^data:([^;,]*)(;base64)?,([\s\S]*)$/i.exec(s)
|
|
152
|
+
if (!m) throw new Error('参考音频的 data URL 格式不对')
|
|
153
|
+
mime = m[1] || ''
|
|
154
|
+
buf = m[2] ? Buffer.from(m[3], 'base64') : Buffer.from(decodeURIComponent(m[3]), 'utf8')
|
|
155
|
+
} else {
|
|
156
|
+
const res = await fetch(s)
|
|
157
|
+
if (!res.ok) throw new Error('下载参考音频失败 HTTP ' + res.status)
|
|
158
|
+
buf = Buffer.from(await res.arrayBuffer())
|
|
159
|
+
mime = res.headers.get('content-type') || ''
|
|
160
|
+
filename = s.split('?')[0].split('/').pop() || ''
|
|
161
|
+
}
|
|
162
|
+
if (buf.length === 0) throw new Error('参考音频是空文件')
|
|
163
|
+
|
|
164
|
+
const form = new FormData()
|
|
165
|
+
form.append('file', new Blob([buf], { type: mime || 'application/octet-stream' }), filename || 'ref.bin')
|
|
166
|
+
const headers = {}
|
|
167
|
+
const values = accountValues()
|
|
168
|
+
const key = values && values.apiKey ? values.apiKey : process.env.WEB2API_API_KEY
|
|
169
|
+
if (key) headers.Authorization = 'Bearer ' + key
|
|
170
|
+
const res = await fetch(baseOf(values) + '/api/resources/upload', { method: 'POST', headers, body: form })
|
|
171
|
+
const text = await res.text()
|
|
172
|
+
let body
|
|
173
|
+
try {
|
|
174
|
+
body = text ? JSON.parse(text) : {}
|
|
175
|
+
} catch {
|
|
176
|
+
throw new Error('上传参考音频失败:web2api 返回的不是 JSON')
|
|
177
|
+
}
|
|
178
|
+
if (body && typeof body.code === 'number' && body.code !== 0) {
|
|
179
|
+
throw new Error(body.message || '上传参考音频失败(web2api 错误 ' + body.code + ')')
|
|
180
|
+
}
|
|
181
|
+
const data = body && body.data
|
|
182
|
+
const local = data && (data.path || data.relativeUrl)
|
|
183
|
+
if (!local || typeof local !== 'string') throw new Error('上传参考音频失败:web2api 没返回可用地址')
|
|
184
|
+
return local
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 参考素材 → 参数(按动作自己声明的 refFields 分发)。
|
|
189
|
+
*
|
|
190
|
+
* refFields 就是这份 provider 的「这台平台收什么」:
|
|
191
|
+
* { image: 'referenceImages', audio: 'referenceAudios' }
|
|
192
|
+
* 没声明的类型 = 这台平台不收,跳过并记一条日志(不静默吞掉、也不炸掉整单)。
|
|
193
|
+
* 以后接一个「图 / 文 / 视频 / 音频全收」的模型:给那条动作补一行 refFields 就行,
|
|
194
|
+
* 下面的分发逻辑不用动。
|
|
195
|
+
*/
|
|
196
|
+
async function attachRefs(action, input, params) {
|
|
197
|
+
const map = action.refFields || {}
|
|
198
|
+
const buckets = {}
|
|
199
|
+
const skipped = []
|
|
200
|
+
for (const r of input.resources || []) {
|
|
201
|
+
if (r.kind === 'text') continue
|
|
202
|
+
const field = map[r.kind]
|
|
203
|
+
if (!field || typeof r.url !== 'string' || !r.url) {
|
|
204
|
+
if (r.kind) skipped.push(r.kind)
|
|
205
|
+
continue
|
|
206
|
+
}
|
|
207
|
+
if (!buckets[field]) buckets[field] = []
|
|
208
|
+
buckets[field].push(r.url)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
for (const [field, urls] of Object.entries(buckets)) {
|
|
212
|
+
// 上限照平台声明:火山参考音频最多 3 段;图片类各平台最多 16 张
|
|
213
|
+
const limit = field === 'referenceAudios' ? 3 : 16
|
|
214
|
+
const picked = urls.slice(0, limit)
|
|
215
|
+
if (urls.length > limit) {
|
|
216
|
+
console.warn('[web2api-audio] ' + action.id + ' 的 ' + field + ' 最多 ' + limit + ' 个,已截断')
|
|
217
|
+
}
|
|
218
|
+
params[field] = field === 'referenceAudios' ? await Promise.all(picked.map(toLocalRef)) : picked
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (skipped.length > 0) {
|
|
222
|
+
console.warn(
|
|
223
|
+
'[web2api-audio] ' + action.id + ' 不收这些素材,已忽略:' + [...new Set(skipped)].join('、') +
|
|
224
|
+
'(当前平台只收:' + (Object.keys(map).join('、') || '无') + ')',
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
return params
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** 音频类工具收 text(不是 prompt):正文 = 用户输入 + 带名字的文本标签块 */
|
|
231
|
+
async function buildParams(action, input) {
|
|
232
|
+
const params = cleanValues(input.values || {})
|
|
233
|
+
if (action.model !== undefined && action.model !== '') params.model = action.model
|
|
234
|
+
params.text = [promptText(input), ...textBlocks(input)].filter((s) => String(s).trim() !== '').join('\n')
|
|
235
|
+
return attachRefs(action, input, params)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function collectUrls(result) {
|
|
239
|
+
const out = []
|
|
240
|
+
const push = (v) => {
|
|
241
|
+
if (typeof v === 'string') {
|
|
242
|
+
if (/^(https?:|data:|\/)/i.test(v)) out.push(v)
|
|
243
|
+
} else if (Array.isArray(v)) {
|
|
244
|
+
for (const item of v) push(item)
|
|
245
|
+
} else if (v && typeof v === 'object') {
|
|
246
|
+
push(v.url)
|
|
247
|
+
push(v.uri)
|
|
248
|
+
push(v.src)
|
|
249
|
+
push(v.urls)
|
|
250
|
+
push(v.downloadUrl)
|
|
251
|
+
push(v.resource)
|
|
252
|
+
push(v.audioUrl)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
push(result)
|
|
256
|
+
return [...new Set(out)]
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function absolutize(u) {
|
|
260
|
+
const s = String(u || '').trim()
|
|
261
|
+
if (!s) return ''
|
|
262
|
+
if (/^(https?:|data:|blob:)/i.test(s)) return s
|
|
263
|
+
return BASE + (s.startsWith('/') ? s : '/' + s)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function pollTask(taskId) {
|
|
267
|
+
const body = await api('/api/tasks/' + encodeURIComponent(taskId), {}, 120000, accountValues())
|
|
268
|
+
const t = body && body.data
|
|
269
|
+
if (!t || typeof t !== 'object') return { status: 'running', message: '任务查询返回空', taskId }
|
|
270
|
+
const status = String(t.status || '')
|
|
271
|
+
if (status === 'completed' || status === 'success' || status === 'done') {
|
|
272
|
+
const urls = collectUrls(t.result).map(absolutize).filter(Boolean)
|
|
273
|
+
if (urls.length === 0) return { status: 'error', error: '任务完成但没有产出资源', taskId }
|
|
274
|
+
return { status: 'done', urls, taskId }
|
|
275
|
+
}
|
|
276
|
+
if (status === 'failed') return { status: 'error', error: t.message || '任务执行失败', taskId }
|
|
277
|
+
if (status === 'cancelled') return { status: 'error', error: t.message || '任务已取消', taskId }
|
|
278
|
+
const waiting = status === 'paused' || status === 'retrying' || status === 'pending'
|
|
279
|
+
return {
|
|
280
|
+
status: 'running',
|
|
281
|
+
message: t.message || '合成中…',
|
|
282
|
+
...(typeof t.progress === 'number' ? { progress: t.progress } : {}),
|
|
283
|
+
taskId,
|
|
284
|
+
...(waiting ? { waiting: true } : {}),
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const format_volc = {
|
|
289
|
+
key: 'format', label: '格式', type: 'grid', default: 'wav',
|
|
290
|
+
options: [
|
|
291
|
+
{ label: 'WAV', value: 'wav' },
|
|
292
|
+
{ label: 'MP3', value: 'mp3' },
|
|
293
|
+
{ label: 'OGG Opus', value: 'ogg_opus' },
|
|
294
|
+
],
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** 豆包音色:与 web2api 的 voices 表必须一致,否则「照名字选、出来另一个人」 */
|
|
298
|
+
const speaker_doubao = {
|
|
299
|
+
key: 'speaker', label: '音色', type: 'select',
|
|
300
|
+
default: 'zh_female_xiaohe_conversation_wvae_bigtts',
|
|
301
|
+
options: [
|
|
302
|
+
{ label: '温柔桃子(升级版)', value: 'zh_female_wenroutaozi_v2_mars_bigtts' },
|
|
303
|
+
{ label: '磁性俊宇(升级版)', value: 'zh_male_nuanxinshizhe_mars_bigtts' },
|
|
304
|
+
{ label: '阳光甜妹(升级版)', value: 'zh_female_xiaohe_conversation_wvae_bigtts' },
|
|
305
|
+
{ label: '知性小棠', value: 'zh_female_wenroutaozi_mars_bigtts' },
|
|
306
|
+
{ label: '邻家女孩', value: 'zh_female_f261_conversation_wvae_bigtts' },
|
|
307
|
+
{ label: '魅力苏菲', value: 'zh_female_sophie_conversation_wvae_bigtts' },
|
|
308
|
+
{ label: '撒娇学妹', value: 'zh_female_yuanqinvyou_wvae_bigtts' },
|
|
309
|
+
{ label: '邻家男孩', value: 'zh_male_linjiananhai_moon_bigtts' },
|
|
310
|
+
{ label: '悠悠君子', value: 'zh_male_M100_conversation_wvae_bigtts' },
|
|
311
|
+
{ label: '温暖阿虎', value: 'zh_male_ahu_conversation_wvae_bigtts' },
|
|
312
|
+
{ label: '少年梓辛', value: 'zh_male_m286_conversation_wvae_bigtts' },
|
|
313
|
+
{ label: '阳光阿辰', value: 'zh_male_qingyiyuxuan_mars_bigtts' },
|
|
314
|
+
{ label: '腹黑霸总', value: 'ICL_c021bc19bf92' },
|
|
315
|
+
{ label: '冷酷霸总', value: 'ICL_e0b9b93ee322' },
|
|
316
|
+
{ label: '傲娇霸总', value: 'zh_male_aojiaobazong_wvae_bigtts' },
|
|
317
|
+
{ label: '霸道总裁', value: 'ICL_d4d40acd33dd' },
|
|
318
|
+
{ label: '温柔子言', value: 'zh_male_cheng_mars_bigtts' },
|
|
319
|
+
{ label: '率性阿哲', value: 'zh_male_litiebanzi_mars_bigtts' },
|
|
320
|
+
{ label: '温柔陆辰', value: 'ICL_df4fc4d1ce4b' },
|
|
321
|
+
{ label: '深夜播客', value: 'zh_male_shenyeboke_wvae_bigtts' },
|
|
322
|
+
{ label: '甜美小雪', value: 'ICL_6acf86286e24' },
|
|
323
|
+
{ label: '清冷阿梦', value: 'ICL_6d6550b0b6f3' },
|
|
324
|
+
{ label: '东方浩然', value: 'zh_male_dongfanghaoran_moon_bigtts' },
|
|
325
|
+
{ label: '病娇少爷', value: 'ICL_72afa6c5dc07' },
|
|
326
|
+
{ label: '清爽男大', value: 'zh_male_junlangxize_mars_bigtts' },
|
|
327
|
+
{ label: '清朗宇澄', value: 'ICL_9b3bc6941076' },
|
|
328
|
+
{ label: '奶音俊少', value: 'ICL_932b3f52bf3d' },
|
|
329
|
+
{ label: '沉稳皓轩', value: 'ICL_5a413fbc14fc' },
|
|
330
|
+
{ label: '温柔俊彦', value: 'ICL_0ce6ef379e73' },
|
|
331
|
+
{ label: '青涩沐阳', value: 'ICL_afedffe4586c' },
|
|
332
|
+
{ label: '睿语舟舟', value: 'ICL_4ce34d3f60f4' },
|
|
333
|
+
{ label: '湾区大叔', value: 'zh_male_gangpu_conversation_wvae_bigtts' },
|
|
334
|
+
{ label: '随性先生', value: 'ICL_b718c1050dd1' },
|
|
335
|
+
{ label: '渊博小叔', value: 'zh_male_m219_conversation_wvae_bigtts' },
|
|
336
|
+
{ label: '俊朗男友', value: 'ICL_1eed9233299f' },
|
|
337
|
+
{ label: '磁性阿铭', value: 'BV154_streaming' },
|
|
338
|
+
{ label: '奶酷小宇', value: 'ICL_b22cd40ccd3e' },
|
|
339
|
+
{ label: '暖阳阿晨', value: 'ICL_7a33516fe388' },
|
|
340
|
+
{ label: '低音小北', value: 'ICL_989e59f0082a' },
|
|
341
|
+
{ label: '男闺蜜俊熙', value: 'ICL_7ba54f5a883e' },
|
|
342
|
+
{ label: '深情霸总', value: 'ICL_6e69deb80ce5' },
|
|
343
|
+
{ label: '文静毛毛', value: 'zh_female_maomao_conversation_wvae_bigtts' },
|
|
344
|
+
{ label: '北京大妞', value: 'zh_female_beijingdaniu_mars_bigtts' },
|
|
345
|
+
{ label: '清甜瑶瑶', value: 'zh_female_F466_mars_bigtts' },
|
|
346
|
+
{ label: '活泼可昕', value: 'zh_female_F765_mars_bigtts' },
|
|
347
|
+
{ label: '水刃公子', value: 'ICL_da6a164900d4' },
|
|
348
|
+
{ label: '灵兔少女', value: 'ICL_eaf8dd4a3a0d' },
|
|
349
|
+
{ label: '蓝曜修士', value: 'ICL_4fba48c6d3cc' },
|
|
350
|
+
{ label: '咆哮小哥', value: 'ICL_21c82f5cbb7b' },
|
|
351
|
+
{ label: '解家花少', value: 'ICL_1289539b58cb' },
|
|
352
|
+
{ label: '闷油瓶小哥', value: 'ICL_ffed9fc2fee7' },
|
|
353
|
+
{ label: '墨镜黑哥', value: 'ICL_ba24ccf23bc7' },
|
|
354
|
+
{ label: '安全哥', value: 'ICL_4b1feb0ced67' },
|
|
355
|
+
{ label: '藕霸小童', value: 'zh_male_nezha' },
|
|
356
|
+
{ label: '雷霆女神', value: 'zh_female_leidian' },
|
|
357
|
+
{ label: '山哥播音', value: 'BV433_streaming' },
|
|
358
|
+
{ label: '顾姐', value: 'zh_female_guli_stream_gpu' },
|
|
359
|
+
{ label: '小品艺术家', value: 'BV223_streaming' },
|
|
360
|
+
{ label: '王小也', value: 'zh_male_wangye' },
|
|
361
|
+
{ label: '奶芙波波', value: 'BV428_streaming' },
|
|
362
|
+
{ label: '星鼠仔', value: 'zh_male_milaoshu' },
|
|
363
|
+
{ label: '麦小鸭', value: 'zh_male_tanglaoya' },
|
|
364
|
+
{ label: '黯刃秦主', value: 'ICL_cd62e63dcdab' },
|
|
365
|
+
{ label: '绯樱神巫', value: 'ICL_19abc3128fbb' },
|
|
366
|
+
{ label: '光头憨憨', value: 'ICL_8d858c1560ed' },
|
|
367
|
+
{ label: '智慧小羊', value: 'ICL_f35ff006eb05' },
|
|
368
|
+
{ label: '火舞魅娘', value: 'ICL_be2856499af4' },
|
|
369
|
+
{ label: '沪上傲女', value: 'ICL_7b76e4aafb6c' },
|
|
370
|
+
{ label: '冷酷哥哥', value: 'ICL_3bb18f934f4e' },
|
|
371
|
+
{ label: '高冷御姐', value: 'zh_female_leidian_conversation_wvae_bigtts' },
|
|
372
|
+
{ label: '快乐小东', value: 'zh_male_xudong_conversation_wvae_bigtts' },
|
|
373
|
+
{ label: '柔美女友', value: 'zh_female_sajiaonvyou_wvae_bigtts' },
|
|
374
|
+
{ label: '爽快思思', value: 'zh_female_sinong_conversation_wvae_bigtts' },
|
|
375
|
+
{ label: '妩媚御姐', value: 'ICL_da05661f8c64' },
|
|
376
|
+
{ label: '活泼女孩', value: 'ICL_11c6b3f0bd6d' },
|
|
377
|
+
{ label: '甜心小美', value: 'ICL_bad46416a2b7' },
|
|
378
|
+
{ label: '魅力女友', value: 'zh_female_meilinvyou_wvae_bigtts' },
|
|
379
|
+
{ label: '可爱女生', value: 'ICL_49240bb7f5ac' },
|
|
380
|
+
{ label: '川渝小伙', value: 'zh_male_sichuanskn' },
|
|
381
|
+
{ label: '南音阳仔', value: 'zh_male_nanchangygn' },
|
|
382
|
+
{ label: '湘都朗少', value: 'zh_male_changshakln' },
|
|
383
|
+
{ label: '桂乡甜妞', value: 'zh_female_guangxiwrn' },
|
|
384
|
+
{ label: '京腔侃爷', value: 'zh_male_M392_conversation_wvae_bigtts' },
|
|
385
|
+
{ label: '清新女声', value: 'zh_female_qingxin_clone2' },
|
|
386
|
+
{ label: '小甜妹', value: 'zh_female_taozi_conversation_v4_wvae_bigtts' },
|
|
387
|
+
{ label: '温柔姐姐', value: 'zh_female_xiaonan_lv_clone2' },
|
|
388
|
+
{ label: '桃花庵主', value: 'zh_male_renmao_mars_bigtts' },
|
|
389
|
+
{ label: '精灵向导', value: 'ICL_1beb294a9e3e' },
|
|
390
|
+
{ label: '清朗公子', value: 'ICL_d8c94c04d627' },
|
|
391
|
+
{ label: '内敛才俊', value: 'ICL_e991be511569' },
|
|
392
|
+
{ label: '清澈梓梓', value: 'zh_female_qingchezizi_moon_bigtts' },
|
|
393
|
+
{ label: '不羁雅痞', value: 'ICL_205cc3ca1152' },
|
|
394
|
+
{ label: '媚娇俏娘', value: 'ICL_4634ac0d9e82' },
|
|
395
|
+
{ label: '动漫小羊', value: 'zh_female_dongmanxiaoyang_moon_bigtts' },
|
|
396
|
+
{ label: '成熟姐姐', value: 'ICL_fd7fd93fb7b8' },
|
|
397
|
+
{ label: '恶魔女仆', value: 'ICL_bf4e1d132b48' },
|
|
398
|
+
{ label: '小丑', value: 'ICL_c1cee47f0150' },
|
|
399
|
+
{ label: '蛇发女妖', value: 'ICL_24dff5266b30' },
|
|
400
|
+
],
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* 语速 / 音调 / 音量:有范围的数值 → 基础控件画成滑块 + 数字框。
|
|
405
|
+
* 以前这里写 kind:'speed',那个 kind 现在没有了(滑块本来就是基础控件)。
|
|
406
|
+
*/
|
|
407
|
+
function speed(key, label, min, max, def) {
|
|
408
|
+
return { key, label, type: 'number', min, max, step: 5, default: def }
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export default {
|
|
412
|
+
id: 'web2api-audio',
|
|
413
|
+
// 平台展示信息(管理页显示;icon 也作为该平台模型的兜底图标)
|
|
414
|
+
title: 'Web2API · 音频',
|
|
415
|
+
description: '豆包语音合成 / 火山引擎音频',
|
|
416
|
+
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><defs><linearGradient id="wcAud" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fbbf24"/><stop offset="1" stop-color="#f59e0b"/></linearGradient></defs><rect width="32" height="32" rx="9" fill="url(#wcAud)"/><path d="M13 19.5a2.5 2.5 0 1 0 2.5 2.5v-6.6l6-1.4v3.5a2.5 2.5 0 1 0 2 2.45V10.5L15.5 12.4v7.1z" fill="#fff"/></svg>',
|
|
417
|
+
// 平台管理页据此渲染配置表单(与 web2api-image / video 同一套;多账号每套一份)
|
|
418
|
+
config: [
|
|
419
|
+
{ key: 'baseUrl', label: '服务地址', type: 'string', default: 'http://localhost:8033',
|
|
420
|
+
placeholder: 'http://localhost:8033', description: 'web2api 服务的根地址。留空 = 用默认地址。' },
|
|
421
|
+
{ key: 'apiKey', label: 'API Key', type: 'secret', description: 'web2api 开了 API_KEY 校验时才需要。留空 = 不带鉴权头。' },
|
|
422
|
+
],
|
|
423
|
+
actions: [
|
|
424
|
+
{
|
|
425
|
+
id: 'web2api:doubao-tts',
|
|
426
|
+
title: '豆包·语音合成',
|
|
427
|
+
description: '文本转语音(不开浏览器,不耗视频积分):选音色即可',
|
|
428
|
+
group: 'web2api · 音频',
|
|
429
|
+
nodeTypes: ['audio'],
|
|
430
|
+
needsPrompt: true,
|
|
431
|
+
order: 10,
|
|
432
|
+
platform: 'doubao', operation: 'tts',
|
|
433
|
+
promptMode: 'plain',
|
|
434
|
+
fields: [speaker_doubao],
|
|
435
|
+
// 豆包 TTS 没有参考音频字段(meta.ts 只有 text / speaker)
|
|
436
|
+
refFields: {},
|
|
437
|
+
pollIntervalMs: 2000, pollTimeoutMs: 600000,
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
id: 'web2api:volcengine-audio',
|
|
441
|
+
title: '火山引擎·音频生成',
|
|
442
|
+
description: 'seed-audio 音频生成:格式 / 语速 / 音量 / 音调可调',
|
|
443
|
+
group: 'web2api · 音频',
|
|
444
|
+
nodeTypes: ['audio'],
|
|
445
|
+
needsPrompt: true,
|
|
446
|
+
order: 11,
|
|
447
|
+
platform: 'volcengine', operation: 'generate-audio',
|
|
448
|
+
promptMode: 'plain',
|
|
449
|
+
fields: [format_volc, speed('speechRate', '语速', -50, 100, 0), speed('pitchRate', '音调', -12, 12, 0), speed('loudnessRate', '音量', -50, 100, 0)],
|
|
450
|
+
// 火山引擎收参考音频(最多 3 段):连进来的音频节点会走这里
|
|
451
|
+
refFields: { audio: 'referenceAudios' },
|
|
452
|
+
pollIntervalMs: 2000, pollTimeoutMs: 600000,
|
|
453
|
+
},
|
|
454
|
+
],
|
|
455
|
+
|
|
456
|
+
async submit(action, input) {
|
|
457
|
+
try {
|
|
458
|
+
const values = accountValues(input.values)
|
|
459
|
+
const body = await api('/api/tasks', {
|
|
460
|
+
method: 'POST',
|
|
461
|
+
body: JSON.stringify({ platform: action.platform, operation: action.operation, params: await buildParams(action, input) }),
|
|
462
|
+
}, 120000, values)
|
|
463
|
+
const task = body && body.data
|
|
464
|
+
if (!task) return { error: 'web2api 没有返回任务信息' }
|
|
465
|
+
|
|
466
|
+
// 同步完成:任务记录里已带产物,直接收工
|
|
467
|
+
const status = String(task.status || '')
|
|
468
|
+
if (status === 'completed' || status === 'success' || status === 'done') {
|
|
469
|
+
const urls = collectUrls(task.result).map(absolutize).filter(Boolean)
|
|
470
|
+
if (urls.length > 0) return { done: true, urls }
|
|
471
|
+
return { error: '合成完成但没有产出音频' }
|
|
472
|
+
}
|
|
473
|
+
if (status === 'failed') return { error: task.message || '合成失败' }
|
|
474
|
+
|
|
475
|
+
// 异步(服务端以后若改成任务化):按 taskId 轮询
|
|
476
|
+
if (typeof task.id === 'string' && task.id) return { taskId: task.id }
|
|
477
|
+
return { error: 'web2api 没有返回任务 id 或音频地址' }
|
|
478
|
+
} catch (err) {
|
|
479
|
+
return { error: err instanceof Error ? err.message : String(err) }
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
|
|
483
|
+
async poll(taskId) {
|
|
484
|
+
try {
|
|
485
|
+
return await pollTask(taskId)
|
|
486
|
+
} catch (err) {
|
|
487
|
+
return { status: 'running', message: err instanceof Error ? err.message : '任务查询失败', taskId }
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
async cancel(taskId) {
|
|
492
|
+
try {
|
|
493
|
+
await api('/api/tasks/' + encodeURIComponent(taskId) + '/cancel', { method: 'POST' }, 15000, accountValues())
|
|
494
|
+
} catch {
|
|
495
|
+
/* 已是终态 */
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
|