@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
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plume-canvas/cloud-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"plume-canvas": "./dist/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"providers",
|
|
14
|
+
"builtin-manifest.json"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/web.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/web.js"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"start": "pnpm build:assets && pnpm build && pnpm serve",
|
|
23
|
+
"dev": "tsx src/cli.ts serve -d ../../.plume --trusted-origin http://localhost:5288",
|
|
24
|
+
"build": "pnpm typecheck && pnpm bundle",
|
|
25
|
+
"bundle": "node scripts/bundle.mjs && tsc -p tsconfig.build.json && node scripts/bundle-dts.mjs",
|
|
26
|
+
"gen:manifest": "node scripts/gen-builtin-manifest.mjs",
|
|
27
|
+
"build:assets": "node scripts/build-assets-parallel.mjs",
|
|
28
|
+
"prepack": "pnpm run build && pnpm gen:manifest",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"serve": "node ./dist/cli.js serve",
|
|
32
|
+
"e2e": "tsx e2e/cloud-e2e.ts",
|
|
33
|
+
"e2e:mcp": "tsx e2e/mcp-e2e.ts",
|
|
34
|
+
"e2e:realtime": "tsx e2e/realtime-e2e.ts"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@hono/node-server": "^2.1.1",
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
39
|
+
"@prismshadow/penguin-core": "0.2.13",
|
|
40
|
+
"hono": "^4.6.0",
|
|
41
|
+
"yaml": "^2.9.1",
|
|
42
|
+
"zod": "^3.23.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@microsoft/api-extractor": "7.58.9",
|
|
46
|
+
"@plume-canvas/kernel": "workspace:*",
|
|
47
|
+
"@types/node": "^24.12.3",
|
|
48
|
+
"esbuild": "^0.28.2",
|
|
49
|
+
"tsx": "^4.22.4",
|
|
50
|
+
"typescript": "~6.0.2",
|
|
51
|
+
"vitest": "^3.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 火山引擎(豆包语音)· seed-audio-1.0 音频生成 —— 直连官方接口。
|
|
3
|
+
*
|
|
4
|
+
* 接口:POST https://openspeech.bytedance.com/api/v3/tts/create
|
|
5
|
+
* 鉴权(两种控制台都支持):
|
|
6
|
+
* - 新版控制台:X-Api-Key 单头;
|
|
7
|
+
* - 旧版控制台:X-Api-App-Id + X-Api-Access-Key 双头。
|
|
8
|
+
* 可选 X-Api-Request-Id 做追踪(响应头里会带 X-Tt-Logid,用于找客服定位)。
|
|
9
|
+
* 同步返回:{ audio(base64), url(2 小时有效), duration, original_duration, subtitle? }
|
|
10
|
+
*
|
|
11
|
+
* 两种生成方式,可以混用:
|
|
12
|
+
* - 参考音频:连进来的音频按顺序放进 references,提示词里写 @音频1 / @音频2 引用;
|
|
13
|
+
* - 自然语言:直接在提示词里描述音色、情绪、语速、场景(也能纯描述生成音效)。
|
|
14
|
+
* references 的顺序必须与 @音频N 的编号一致,所以编号和数组出自同一次遍历。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const DEFAULT_BASE = 'https://openspeech.bytedance.com'
|
|
18
|
+
const MAX_PROMPT = 3000
|
|
19
|
+
const MAX_REFS = 3
|
|
20
|
+
const MAX_REF_BYTES = 10 * 1024 * 1024
|
|
21
|
+
|
|
22
|
+
function injected() {
|
|
23
|
+
return typeof __mcProviderConfig === 'undefined' ? { accounts: [], values: {}, byId: {} } : __mcProviderConfig
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function accountValues(values) {
|
|
27
|
+
const inj = injected()
|
|
28
|
+
const preferred = values && typeof values.__accountId === 'string' ? values.__accountId : ''
|
|
29
|
+
if (preferred && inj.byId && inj.byId[preferred]) return inj.byId[preferred]
|
|
30
|
+
const fallback = inj.defaultId && inj.byId && inj.byId[inj.defaultId]
|
|
31
|
+
if (fallback) return fallback
|
|
32
|
+
const accounts = inj.accounts || []
|
|
33
|
+
if (accounts.length > 0) return accounts[0].values || {}
|
|
34
|
+
return inj.values || {}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function baseOf(values) {
|
|
38
|
+
const b = values && typeof values.baseUrl === 'string' && values.baseUrl.trim()
|
|
39
|
+
? values.baseUrl.trim()
|
|
40
|
+
: process.env.VOLC_AUDIO_BASE || DEFAULT_BASE
|
|
41
|
+
return String(b).replace(/\/+$/, '')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 新版控制台的 API Key(X-Api-Key) */
|
|
45
|
+
function keyOf(values) {
|
|
46
|
+
if (values && typeof values.apiKey === 'string' && values.apiKey.trim()) return values.apiKey.trim()
|
|
47
|
+
return process.env.VOLC_API_KEY || ''
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 旧版控制台的 App ID / Access Key(双头鉴权,两个都要) */
|
|
51
|
+
function legacyOf(values) {
|
|
52
|
+
const appId = (values && typeof values.appId === 'string' && values.appId.trim()) || process.env.VOLC_APP_ID || ''
|
|
53
|
+
const accessKey =
|
|
54
|
+
(values && typeof values.accessKey === 'string' && values.accessKey.trim()) || process.env.VOLC_ACCESS_KEY || ''
|
|
55
|
+
return appId && accessKey ? { appId, accessKey } : null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 有没有可用的鉴权(任一一种即可) */
|
|
59
|
+
function hasAuth(values) {
|
|
60
|
+
return Boolean(keyOf(values) || legacyOf(values))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 火山要求带一个请求追踪号;没有内置 uuid 模块就直接拼一个够用的 */
|
|
64
|
+
function traceId() {
|
|
65
|
+
const hex = () => Math.floor(Math.random() * 16).toString(16)
|
|
66
|
+
let s = ''
|
|
67
|
+
for (let i = 0; i < 32; i++) s += hex()
|
|
68
|
+
return s.slice(0, 8) + '-' + s.slice(8, 12) + '-' + s.slice(12, 16) + '-' + s.slice(16, 20) + '-' + s.slice(20)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function callJson(url, init, timeoutMs, values) {
|
|
72
|
+
const ac = new AbortController()
|
|
73
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs)
|
|
74
|
+
try {
|
|
75
|
+
const key = keyOf(values)
|
|
76
|
+
const legacy = legacyOf(values)
|
|
77
|
+
const headers = {
|
|
78
|
+
'Content-Type': 'application/json',
|
|
79
|
+
...(key ? { 'X-Api-Key': key } : {}),
|
|
80
|
+
// 旧版控制台:App ID + Access Key 双头(与单头同时给也没关系,服务端认哪个都行)
|
|
81
|
+
...(legacy ? { 'X-Api-App-Id': legacy.appId, 'X-Api-Access-Key': legacy.accessKey } : {}),
|
|
82
|
+
'X-Api-Request-Id': traceId(),
|
|
83
|
+
...(init.headers || {}),
|
|
84
|
+
}
|
|
85
|
+
const res = await fetch(url, { ...init, headers, signal: ac.signal })
|
|
86
|
+
const text = await res.text()
|
|
87
|
+
let body = null
|
|
88
|
+
try {
|
|
89
|
+
body = text ? JSON.parse(text) : null
|
|
90
|
+
} catch {
|
|
91
|
+
throw new Error('火山引擎返回的不是 JSON(HTTP ' + res.status + ')')
|
|
92
|
+
}
|
|
93
|
+
// 火山在业务失败时也可能回 200,错误码在 body.code 里
|
|
94
|
+
const code = body && typeof body.code === 'number' ? body.code : 0
|
|
95
|
+
const logId = res.headers.get('x-tt-logid') || ''
|
|
96
|
+
if (!res.ok || code !== 0) {
|
|
97
|
+
const msg = (body && body.message) || 'HTTP ' + res.status
|
|
98
|
+
throw new Error(translateError(msg, code || res.status) + (logId ? '(logid ' + logId + ')' : ''))
|
|
99
|
+
}
|
|
100
|
+
return body || {}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
if (err instanceof Error && err.name === 'AbortError') {
|
|
103
|
+
throw new Error('火山引擎请求超时(' + Math.round(timeoutMs / 1000) + ' 秒),长文本可能要更久')
|
|
104
|
+
}
|
|
105
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
106
|
+
if (/fetch failed|ECONNREFUSED|Failed to fetch|NetworkError|ENOTFOUND|ETIMEDOUT/i.test(msg)) {
|
|
107
|
+
throw new Error('连不上火山引擎(' + baseOf(values) + '),请检查网络或代理设置')
|
|
108
|
+
}
|
|
109
|
+
throw new Error(msg || '火山引擎调用失败')
|
|
110
|
+
} finally {
|
|
111
|
+
clearTimeout(timer)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 把火山的错误码 / 英文原话翻成能照做的中文 */
|
|
116
|
+
function translateError(msg, code) {
|
|
117
|
+
const m = String(msg)
|
|
118
|
+
if (code === 401 || /unauthor|invalid.*key|api key/i.test(m)) {
|
|
119
|
+
return 'API Key 无效或没有开通这个服务:请到火山控制台确认 Key 与「音频生成」服务已开通'
|
|
120
|
+
}
|
|
121
|
+
if (code === 403 || /forbidden|permission/i.test(m)) return '这个 API Key 没有权限调用音频生成(可能是服务未开通或 IP 白名单)'
|
|
122
|
+
if (code === 429 || /rate|qps|too many/i.test(m)) return '请求太频繁了,等一会儿再试'
|
|
123
|
+
if (/quota|balance|insufficient|arrear/i.test(m)) return '火山账户余额或配额不足:' + m
|
|
124
|
+
if (/text_prompt/i.test(m)) return '提示词不合规或被拒绝:' + m
|
|
125
|
+
if (/reference|audio_data|audio_url/i.test(m)) {
|
|
126
|
+
return '参考音频有问题:最多 3 段、每段 ≤ 30 秒 / 10 MB,格式限 wav / mp3 / pcm / ogg_opus(' + m + ')'
|
|
127
|
+
}
|
|
128
|
+
if (/speaker/i.test(m)) return '音色 ID 不存在或不支持:' + m
|
|
129
|
+
return m
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function dataUrlInfo(url) {
|
|
133
|
+
const m = /^data:([^;,]*)(;base64)?,([\s\S]*)$/i.exec(String(url || ''))
|
|
134
|
+
if (!m) return null
|
|
135
|
+
const bytes = m[2] ? Math.floor((m[3].length * 3) / 4) : decodeURIComponent(m[3]).length
|
|
136
|
+
return { mime: m[1] || '', bytes }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** data URL → 纯 base64(火山 references[].audio_data 只收裸 base64) */
|
|
140
|
+
function base64Of(url) {
|
|
141
|
+
const s = String(url || '')
|
|
142
|
+
const m = /^data:[^;,]*;base64,([\s\S]*)$/i.exec(s)
|
|
143
|
+
if (m) return m[1]
|
|
144
|
+
const plain = /^data:[^;,]*,[\s\S]*$/i.exec(s)
|
|
145
|
+
if (plain) return ''
|
|
146
|
+
return ''
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 连进来的音频 → references,并按数组顺序编号(@音频1 = references[0])。
|
|
151
|
+
* 编号与数组必须出自同一次遍历,分成两遍很容易错位(错一位就换成别人在说话)。
|
|
152
|
+
*/
|
|
153
|
+
function collectAudios(input) {
|
|
154
|
+
const refs = []
|
|
155
|
+
const indexById = new Map()
|
|
156
|
+
const skipped = []
|
|
157
|
+
for (const r of input.resources || []) {
|
|
158
|
+
if (!r) continue
|
|
159
|
+
if (r.kind !== 'audio') {
|
|
160
|
+
if (r.kind) skipped.push(r.kind)
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
const url = typeof r.url === 'string' ? r.url.trim() : ''
|
|
164
|
+
if (!url) {
|
|
165
|
+
skipped.push('空音频')
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
const n = refs.length + 1
|
|
169
|
+
if (n > MAX_REFS) break
|
|
170
|
+
const info = dataUrlInfo(url)
|
|
171
|
+
if (info && info.bytes > MAX_REF_BYTES) {
|
|
172
|
+
throw new Error('参考音频「' + (r.name || '未命名') + '」超过 10 MB,请换短一点的片段')
|
|
173
|
+
}
|
|
174
|
+
const b64 = base64Of(url)
|
|
175
|
+
// 宿主一般已经把资源解析成 data URL;万一给了可访问的 http 地址就走 audio_url
|
|
176
|
+
refs.push(b64 ? { audio_data: b64 } : { audio_url: url })
|
|
177
|
+
if (typeof r.id === 'string' && r.id) indexById.set(r.id, n)
|
|
178
|
+
}
|
|
179
|
+
if (skipped.length > 0) {
|
|
180
|
+
console.warn('[seed-audio-volc] 这个模型只收参考音频,已忽略:' + [...new Set(skipped)].join('、'))
|
|
181
|
+
}
|
|
182
|
+
return { refs, indexById }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 提示词分段 → text_prompt(tag 换成 @音频N,普通文字原样) */
|
|
186
|
+
function buildPrompt(input, indexById) {
|
|
187
|
+
let out = ''
|
|
188
|
+
for (const seg of input.prompts || []) {
|
|
189
|
+
if (!seg || typeof seg.value !== 'string') continue
|
|
190
|
+
if (seg.type === 'tag') {
|
|
191
|
+
const n = indexById.get(seg.value)
|
|
192
|
+
if (n) out += '@音频' + n
|
|
193
|
+
else console.warn('[seed-audio-volc] 提示词里的素材 ' + seg.value + ' 不是参考音频,已省略')
|
|
194
|
+
} else {
|
|
195
|
+
out += seg.value
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return out
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** 采样率按格式兜底:ogg_opus 只支持 48000,wav/pcm 默认 40000,mp3 默认 44100 */
|
|
202
|
+
function sampleRateFor(format, value) {
|
|
203
|
+
const n = typeof value === 'number' ? value : Number(value)
|
|
204
|
+
if (format === 'ogg_opus') return 48000
|
|
205
|
+
if (Number.isFinite(n) && n > 0) return n
|
|
206
|
+
if (format === 'mp3') return 44100
|
|
207
|
+
return 40000
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function mimeFor(format) {
|
|
211
|
+
switch (format) {
|
|
212
|
+
case 'wav':
|
|
213
|
+
return 'audio/wav'
|
|
214
|
+
case 'mp3':
|
|
215
|
+
return 'audio/mpeg'
|
|
216
|
+
case 'ogg_opus':
|
|
217
|
+
return 'audio/ogg'
|
|
218
|
+
case 'pcm':
|
|
219
|
+
return 'audio/L16'
|
|
220
|
+
default:
|
|
221
|
+
return 'audio/mpeg'
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const action = {
|
|
226
|
+
id: 'seed-audio-volc:generate',
|
|
227
|
+
// 标题里不带「官方」后缀(用户 2026-11-17):平台那一栏已经写了「火山引擎」,
|
|
228
|
+
// 再挂括号只会把名字占长,模型列表里还会和 51KIK 那条挤成两行。
|
|
229
|
+
title: 'Seed Audio 1.0',
|
|
230
|
+
description: '火山引擎直连。写 @音频1 用这段声音,描述里写情绪、语速、场景;纯描述也能生成音效',
|
|
231
|
+
group: '火山引擎 · 音频',
|
|
232
|
+
nodeTypes: ['audio'],
|
|
233
|
+
needsPrompt: true,
|
|
234
|
+
order: 20,
|
|
235
|
+
model: 'seed-audio-1.0',
|
|
236
|
+
pollIntervalMs: 3000,
|
|
237
|
+
pollTimeoutMs: 600000,
|
|
238
|
+
fields: [
|
|
239
|
+
{
|
|
240
|
+
key: 'format', label: '格式', type: 'grid', default: 'mp3',
|
|
241
|
+
options: [
|
|
242
|
+
{ label: 'MP3', value: 'mp3' },
|
|
243
|
+
{ label: 'WAV', value: 'wav' },
|
|
244
|
+
{ label: 'PCM', value: 'pcm' },
|
|
245
|
+
{ label: 'OGG', value: 'ogg_opus' },
|
|
246
|
+
],
|
|
247
|
+
description: 'MP3 体积小;WAV 音质原始但文件大;OGG 只支持 48k 采样率。',
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
key: 'sampleRate', label: '采样率', type: 'select', default: 24000,
|
|
251
|
+
options: [
|
|
252
|
+
{ label: '16 kHz', value: 16000 },
|
|
253
|
+
{ label: '24 kHz', value: 24000 },
|
|
254
|
+
{ label: '32 kHz', value: 32000 },
|
|
255
|
+
{ label: '44.1 kHz', value: 44100 },
|
|
256
|
+
{ label: '48 kHz', value: 48000 },
|
|
257
|
+
],
|
|
258
|
+
description: '越高越清晰、文件越大。人声 24 kHz 够用;选 OGG 会强制 48 kHz。',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
key: 'speechRate', label: '语速', type: 'number', min: -50, max: 100, step: 5, default: 0,
|
|
262
|
+
description: '0 是原速;-50 是 0.5 倍慢,100 是 2 倍快。',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
key: 'pitchRate', label: '音调', type: 'number', min: -12, max: 12, step: 1, default: 0,
|
|
266
|
+
description: '往下调声音更低沉,往上调更尖。',
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
key: 'loudnessRate', label: '音量', type: 'number', min: -50, max: 100, step: 5, default: 0,
|
|
270
|
+
description: '0 是原始音量;-50 减半,100 加倍。',
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
templates: [
|
|
274
|
+
{
|
|
275
|
+
id: 'seed-audio-volc:tpl-ref',
|
|
276
|
+
name: '参考音色读台词',
|
|
277
|
+
description: '选一段音频,用它本来的声音说话',
|
|
278
|
+
prompt: '@音频1 用这个声音说:今天的雨下得好大啊,你带伞了吗?',
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
id: 'seed-audio-volc:tpl-dialog',
|
|
282
|
+
name: '两人对话',
|
|
283
|
+
description: '参考音色 + 描述出来的男声,一来一回',
|
|
284
|
+
prompt:
|
|
285
|
+
'@音频1 用这个甜美轻快的少女声说:你终于回来啦,我等了你好久。\n' +
|
|
286
|
+
'然后一个四十多岁的低沉沙哑中年男人,语速很慢、带着一点疲惫,接着说:路上堵车,我也没办法啊。',
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
id: 'seed-audio-volc:tpl-scene',
|
|
290
|
+
name: '纯描述音效',
|
|
291
|
+
description: '不连参考音频也能用:雨夜、街道、远处车流',
|
|
292
|
+
prompt: '雨夜的街道,雨点密密地打在铁皮雨棚上,远处有汽车驶过溅起水花,偶尔一声闷雷。',
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 'seed-audio-volc:tpl-narrator',
|
|
296
|
+
name: '旁白男声',
|
|
297
|
+
description: '纯描述的音色,适合纪录片旁白',
|
|
298
|
+
prompt: '一个三十多岁的男中音做纪录片旁白,语速平稳、声音厚实、略带克制,说:这里是长江的源头,海拔六千米,风从冰川上吹过。',
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export default {
|
|
304
|
+
id: 'seed-audio-volc',
|
|
305
|
+
title: '火山引擎 · 音频生成',
|
|
306
|
+
description: '豆包 seed-audio-1.0 官方接口:参考音色 + 自然语言描述,生成对白、旁白和音效',
|
|
307
|
+
// 豆包官方品牌图标(与 Agent 图标表里的 doubao 同一个 SVG)。
|
|
308
|
+
// 这里必须写成完整 <svg>,不能只写名字:平台管理列表只认 SVG / 图片地址,
|
|
309
|
+
// 写名字会退回成「火」字兜底(用户 2026-11-17 截图)。
|
|
310
|
+
icon:
|
|
311
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">' +
|
|
312
|
+
'<path fill="#1E37FC" d="M5.31 15.756c.172-3.75 1.883-5.999 2.549-6.739-3.26 2.058-5.425 5.658-6.358 8.308v1.12C1.501 21.513 4.226 24 7.59 24a6.59 6.59 0 0 0 2.2-.375c.353-.12.7-.248 1.039-.378.913-.899 1.65-1.91 2.243-2.992-4.877 2.431-7.974.072-7.763-4.5l.002.001z"/>' +
|
|
313
|
+
'<path fill="#37E1BE" d="M22.57 10.283c-1.212-.901-4.109-2.404-7.397-2.8.295 3.792.093 8.766-2.1 12.773a12.782 12.782 0 0 1-2.244 2.992c3.764-1.448 6.746-3.457 8.596-5.219 2.82-2.683 3.353-5.178 3.361-6.66a2.737 2.737 0 0 0-.216-1.084v-.002z"/>' +
|
|
314
|
+
'<path fill="#A569FF" d="M14.303 1.867C12.955.7 11.248 0 9.39 0 7.532 0 5.883.677 4.545 1.807 2.791 3.29 1.627 5.557 1.5 8.125v9.201c.932-2.65 3.097-6.25 6.357-8.307.5-.318 1.025-.595 1.569-.829 1.883-.801 3.878-.932 5.746-.706-.222-2.83-.718-5.002-.87-5.617h.001z"/>' +
|
|
315
|
+
'<path fill="#1E37FC" d="M17.305 4.961a199.47 199.47 0 0 1-1.08-1.094c-.202-.213-.398-.419-.586-.622l-1.333-1.378c.151.615.648 2.786.869 5.617 3.288.395 6.185 1.898 7.396 2.8-1.306-1.275-3.475-3.487-5.266-5.323z"/>' +
|
|
316
|
+
'</svg>',
|
|
317
|
+
config: [
|
|
318
|
+
{
|
|
319
|
+
key: 'baseUrl', label: '服务地址', type: 'string', default: DEFAULT_BASE,
|
|
320
|
+
placeholder: DEFAULT_BASE, description: '默认就是官方地址,一般不用改。',
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
key: 'apiKey', label: 'API Key', type: 'secret',
|
|
324
|
+
description: '新版控制台 → API Key 管理里创建的那串(X-Api-Key)。用旧版控制台就填下面两项。',
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
key: 'appId', label: 'App ID(旧版)', type: 'secret',
|
|
328
|
+
description: '旧版控制台 → 应用管理的 App ID。与下面的 Access Key 一起用,和 API Key 二选一。',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
key: 'accessKey', label: 'Access Key(旧版)', type: 'secret',
|
|
332
|
+
description: '旧版控制台应用里的 Access Key / Access Token。',
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
actions: [action],
|
|
336
|
+
|
|
337
|
+
async submit(actionDef, input) {
|
|
338
|
+
try {
|
|
339
|
+
const values = accountValues(input.values)
|
|
340
|
+
const v = input.values || {}
|
|
341
|
+
if (!hasAuth(values)) {
|
|
342
|
+
return {
|
|
343
|
+
error:
|
|
344
|
+
'还没填火山的鉴权:新版控制台填 API Key;旧版控制台填 App ID + Access Key(到「设置 → 平台」里填)',
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const { refs, indexById } = collectAudios(input)
|
|
349
|
+
let prompt = buildPrompt(input, indexById)
|
|
350
|
+
// 连了参考音频却没写 @音频N:补一句,否则模型不知道要学哪段声音
|
|
351
|
+
if (refs.length > 0 && !/@音频\d/.test(prompt)) {
|
|
352
|
+
prompt = '参考 @音频1 的音色、语气和说话方式。\n' + prompt
|
|
353
|
+
}
|
|
354
|
+
prompt = prompt.trim()
|
|
355
|
+
if (!prompt) {
|
|
356
|
+
return { error: '请写一句台词或描述,例如:@音频1 用这个声音说:你好呀。' }
|
|
357
|
+
}
|
|
358
|
+
if ([...prompt].length > MAX_PROMPT) {
|
|
359
|
+
return { error: '提示词太长了(' + [...prompt].length + ' 字),最多 ' + MAX_PROMPT + ' 字' }
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const format = typeof v.format === 'string' && v.format ? v.format : 'mp3'
|
|
363
|
+
const body = {
|
|
364
|
+
model: actionDef.model || 'seed-audio-1.0',
|
|
365
|
+
text_prompt: prompt,
|
|
366
|
+
audio_config: {
|
|
367
|
+
format,
|
|
368
|
+
sample_rate: sampleRateFor(format, v.sampleRate),
|
|
369
|
+
speech_rate: num(v.speechRate, 0),
|
|
370
|
+
pitch_rate: num(v.pitchRate, 0),
|
|
371
|
+
loudness_rate: num(v.loudnessRate, 0),
|
|
372
|
+
},
|
|
373
|
+
watermark: {},
|
|
374
|
+
}
|
|
375
|
+
if (refs.length > 0) body.references = refs
|
|
376
|
+
|
|
377
|
+
const res = await callJson(baseOf(values) + '/api/v3/tts/create', {
|
|
378
|
+
method: 'POST',
|
|
379
|
+
body: JSON.stringify(body),
|
|
380
|
+
}, 300000, values)
|
|
381
|
+
|
|
382
|
+
const urls = []
|
|
383
|
+
if (typeof res.url === 'string' && res.url) urls.push(res.url)
|
|
384
|
+
// 没有外链但给了 base64:转成 data URL,后台会收进画布资源目录
|
|
385
|
+
if (urls.length === 0 && typeof res.audio === 'string' && res.audio) {
|
|
386
|
+
urls.push('data:' + mimeFor(format) + ';base64,' + res.audio)
|
|
387
|
+
}
|
|
388
|
+
if (urls.length === 0) return { error: '生成完成但没有拿到音频地址' }
|
|
389
|
+
|
|
390
|
+
const dur = typeof res.original_duration === 'number' ? res.original_duration : res.duration
|
|
391
|
+
console.log('[seed-audio-volc] 生成完成 ' + (dur ?? '?') + ' 秒,参考音频 ' + refs.length + ' 段')
|
|
392
|
+
return { done: true, urls }
|
|
393
|
+
} catch (err) {
|
|
394
|
+
return { error: err instanceof Error ? err.message : String(err) }
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function num(v, fallback) {
|
|
400
|
+
const n = typeof v === 'number' ? v : Number(v)
|
|
401
|
+
return Number.isFinite(n) ? n : fallback
|
|
402
|
+
}
|