@lingjingai/lj-awb-cli 0.5.7 → 0.5.14
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 +7 -3
- package/package.json +1 -1
- package/packages/awb-cli/package.json +2 -2
- package/packages/awb-core/package.json +1 -1
- package/packages/awb-core/src/api.js +8 -0
- package/packages/awb-core/src/commands.js +76 -1
- package/packages/awb-core/src/common.js +6 -0
- package/packages/awb-core/src/output.js +27 -8
- package/packages/awb-core/src/services.js +318 -17
- package/packages/awb-core/src/standalone.js +27 -8
- package/skills/lj-awb/SKILL.md +7 -5
- package/skills/lj-awb/VERSION +1 -1
- package/skills/lj-awb/compat.json +3 -3
- package/skills/lj-awb/modules/create.md +14 -2
- package/skills/lj-awb/modules/driver.md +7 -7
- package/skills/lj-awb/modules/model.md +6 -3
- package/skills/lj-awb/modules/task-manual.md +3 -0
- package/skills/lj-awb/references/volcengine-voice-types.md +455 -0
|
@@ -98,6 +98,7 @@ const ASSET_VIDEO_MIN_PIXELS = 640 * 640;
|
|
|
98
98
|
const ASSET_VIDEO_MAX_PIXELS = 834 * 1112;
|
|
99
99
|
const ASSET_AUDIO_MIN_SECONDS = 2;
|
|
100
100
|
const ASSET_AUDIO_MAX_SECONDS = 15;
|
|
101
|
+
const AUDIO_SPEAKER_ID_PATTERN = /^[A-Za-z0-9]+(?:_[A-Za-z0-9]+)+$/;
|
|
101
102
|
let ffprobeCommandCache = null;
|
|
102
103
|
let ffmpegCommandCache = null;
|
|
103
104
|
const PLATFORM_BACKEND_PATH_PREFIXES = [
|
|
@@ -118,8 +119,21 @@ const CREATE_STANDARD_KWARG_KEYS = new Set([
|
|
|
118
119
|
'generateNum',
|
|
119
120
|
'generate_num',
|
|
120
121
|
'duration',
|
|
122
|
+
'speaker',
|
|
121
123
|
'needAudio',
|
|
122
124
|
'need_audio',
|
|
125
|
+
'audioFormat',
|
|
126
|
+
'audio_format',
|
|
127
|
+
'sampleRate',
|
|
128
|
+
'sample_rate',
|
|
129
|
+
'speechRate',
|
|
130
|
+
'speech_rate',
|
|
131
|
+
'loudnessRate',
|
|
132
|
+
'loudness_rate',
|
|
133
|
+
'pitchRate',
|
|
134
|
+
'pitch_rate',
|
|
135
|
+
'enableSubtitle',
|
|
136
|
+
'enable_subtitle',
|
|
123
137
|
'resource',
|
|
124
138
|
'resources',
|
|
125
139
|
'resourcesJson',
|
|
@@ -1098,6 +1112,14 @@ export async function creditsUsageSummary(kwargs = {}) {
|
|
|
1098
1112
|
|
|
1099
1113
|
function modelListMetadata(kind, paramKeys = [], rulesByKey = new Map()) {
|
|
1100
1114
|
const keys = new Set(paramKeys);
|
|
1115
|
+
if (kind === 'audio') {
|
|
1116
|
+
return {
|
|
1117
|
+
inputModes: keys.has('resources') ? ['prompt_only', 'reference'] : ['prompt_only'],
|
|
1118
|
+
controls: ['duration', 'speaker', 'audio_format', 'sample_rate', 'speech_rate', 'loudness_rate', 'pitch_rate', 'enable_subtitle']
|
|
1119
|
+
.filter((key) => keys.has(key)),
|
|
1120
|
+
resourceParams: keys.has('resources') ? ['resources'] : [],
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1101
1123
|
const imageReferenceParams = ['cref', 'sref', 'iref', 'resources'].filter((key) => keys.has(key));
|
|
1102
1124
|
const videoResourceParams = ['frames', 'multi_param', 'multi_prompt'].filter((key) => keys.has(key));
|
|
1103
1125
|
const inputModes = createSpecSupportedIntents(createSpecInputModes(kind, keys, rulesByKey), kind)
|
|
@@ -1196,6 +1218,7 @@ function normalizeModelRows(payload, kind, options = {}) {
|
|
|
1196
1218
|
const MODEL_USAGE_FAMILY = {
|
|
1197
1219
|
image: { default: 'IMAGE_CREATE', allow: new Set(['IMAGE_CREATE']) },
|
|
1198
1220
|
video: { default: 'VIDEO_CREATE', allow: new Set(['VIDEO_CREATE']) },
|
|
1221
|
+
audio: { default: 'AUDIO_CREATE', allow: new Set(['AUDIO_CREATE']) },
|
|
1199
1222
|
};
|
|
1200
1223
|
|
|
1201
1224
|
export function resolveModelUsage(kind, kwargs = {}) {
|
|
@@ -1343,9 +1366,10 @@ export async function assetReviewModels(kwargs = {}) {
|
|
|
1343
1366
|
|
|
1344
1367
|
async function findModelGroup(modelGroupCode, options = {}) {
|
|
1345
1368
|
const includeRaw = Boolean(options.includeRaw);
|
|
1346
|
-
const [imageResult, videoResult] = await Promise.allSettled([
|
|
1369
|
+
const [imageResult, videoResult, audioResult] = await Promise.allSettled([
|
|
1347
1370
|
awbApi.fetchModelsByUsage('IMAGE_CREATE', {}),
|
|
1348
1371
|
awbApi.fetchModelsByUsage('VIDEO_CREATE', {}),
|
|
1372
|
+
awbApi.fetchModelsByUsage('AUDIO_CREATE', {}),
|
|
1349
1373
|
]);
|
|
1350
1374
|
const imageModels = imageResult.status === 'fulfilled'
|
|
1351
1375
|
? normalizeModelRows(imageResult.value, 'image', { includeRaw, includeInternal: true }).map((item) => ({ ...item, kind: 'image' }))
|
|
@@ -1353,13 +1377,16 @@ async function findModelGroup(modelGroupCode, options = {}) {
|
|
|
1353
1377
|
const videoModels = videoResult.status === 'fulfilled'
|
|
1354
1378
|
? normalizeModelRows(videoResult.value, 'video', { includeRaw, includeInternal: true }).map((item) => ({ ...item, kind: 'video' }))
|
|
1355
1379
|
: [];
|
|
1356
|
-
|
|
1380
|
+
const audioModels = audioResult.status === 'fulfilled'
|
|
1381
|
+
? normalizeModelRows(audioResult.value, 'audio', { includeRaw, includeInternal: true }).map((item) => ({ ...item, kind: 'audio' }))
|
|
1382
|
+
: [];
|
|
1383
|
+
return [...imageModels, ...videoModels, ...audioModels].find((item) => item.modelGroupCode === modelGroupCode) ?? null;
|
|
1357
1384
|
}
|
|
1358
1385
|
|
|
1359
1386
|
function resolveTaskModel(kind, kwargs = {}) {
|
|
1360
1387
|
const modelGroupCode = trimToNull(kwargs.modelGroupCode);
|
|
1361
1388
|
if (!modelGroupCode) {
|
|
1362
|
-
throw argumentError('缺少模型组编码', '传 --model-group-code <code
|
|
1389
|
+
throw argumentError('缺少模型组编码', '传 --model-group-code <code>;推荐先运行对应的 model image-models / video-models / audio-models。');
|
|
1363
1390
|
}
|
|
1364
1391
|
return {
|
|
1365
1392
|
kind,
|
|
@@ -1956,7 +1983,7 @@ function constraintConditionMatches(condition = {}, promptParams = {}) {
|
|
|
1956
1983
|
return String(actual ?? '') === String(condition.value ?? '');
|
|
1957
1984
|
}
|
|
1958
1985
|
|
|
1959
|
-
function assertParamsAgainstModel(promptParams = {}, params = [], constraints = []) {
|
|
1986
|
+
function assertParamsAgainstModel(promptParams = {}, params = [], constraints = [], taskKind = null) {
|
|
1960
1987
|
const paramByKey = new Map(params.map((item) => [item.key, item]));
|
|
1961
1988
|
for (const key of providedPromptParamKeys(promptParams)) {
|
|
1962
1989
|
const param = paramByKey.get(key);
|
|
@@ -1970,6 +1997,18 @@ function assertParamsAgainstModel(promptParams = {}, params = [], constraints =
|
|
|
1970
1997
|
if (param.maxLength != null && typeof value === 'string' && value.length > param.maxLength) {
|
|
1971
1998
|
throw argumentError(`参数 ${key} 超过模型长度限制:${value.length}/${param.maxLength}`);
|
|
1972
1999
|
}
|
|
2000
|
+
if (taskKind === 'audio' && (param.minValue != null || param.maxValue != null)) {
|
|
2001
|
+
const numericValue = Number(value);
|
|
2002
|
+
if (!Number.isFinite(numericValue)) {
|
|
2003
|
+
throw argumentError(`参数 ${key} 必须是数字:${value}`);
|
|
2004
|
+
}
|
|
2005
|
+
if (param.minValue != null && numericValue < param.minValue) {
|
|
2006
|
+
throw argumentError(`参数 ${key} 小于模型最小值:${numericValue}/${param.minValue}`);
|
|
2007
|
+
}
|
|
2008
|
+
if (param.maxValue != null && numericValue > param.maxValue) {
|
|
2009
|
+
throw argumentError(`参数 ${key} 超过模型最大值:${numericValue}/${param.maxValue}`);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
1973
2012
|
}
|
|
1974
2013
|
|
|
1975
2014
|
for (const constraint of constraints) {
|
|
@@ -1996,7 +2035,7 @@ async function validateCreateRequestAgainstModel(kind, modelGroupCode, promptPar
|
|
|
1996
2035
|
const params = modelOptionParams(context.options, context.taskKind);
|
|
1997
2036
|
const resources = modelOptionsResources(context.inputModes);
|
|
1998
2037
|
const effectiveResources = applyResourceLimitProfileConstraints(resources, context.constraints, resourceDetails);
|
|
1999
|
-
assertParamsAgainstModel(promptParams, params, context.constraints);
|
|
2038
|
+
assertParamsAgainstModel(promptParams, params, context.constraints, kind);
|
|
2000
2039
|
assertResourceShapeAgainstModel(resourceDetails, effectiveResources);
|
|
2001
2040
|
assertResourceCountsAgainstModel(resourceDetails, effectiveResources);
|
|
2002
2041
|
if (kind === 'video') {
|
|
@@ -2244,6 +2283,14 @@ function createParamForModelOption(option = {}, taskKind = 'image') {
|
|
|
2244
2283
|
meaning: '视频生成时长,单位秒。',
|
|
2245
2284
|
valueSource: '只能从 allowedValues 选择;CLI 会转成整数。',
|
|
2246
2285
|
},
|
|
2286
|
+
speaker: {
|
|
2287
|
+
key: 'speaker',
|
|
2288
|
+
cliArg: '--speaker',
|
|
2289
|
+
requestPath: 'promptParams.speaker',
|
|
2290
|
+
materialLegacyKey: 'speaker',
|
|
2291
|
+
meaning: '火山语音合成 2.0 或声音复刻产生的 voice_type 机器 ID。',
|
|
2292
|
+
valueSource: '只使用 https://docs.volcengine.com/docs/6561/1257544?lang=zh 同一行的 voice_type 或声音复刻返回的机器 ID;不得使用中文或英文音色名称,不得拼接或猜测 ID。',
|
|
2293
|
+
},
|
|
2247
2294
|
need_audio: {
|
|
2248
2295
|
key: 'needAudio',
|
|
2249
2296
|
cliArg: '--need-audio',
|
|
@@ -2355,11 +2402,54 @@ function inferTaskKind(found, optionKeys) {
|
|
|
2355
2402
|
if (found?.kind) return found.kind;
|
|
2356
2403
|
if (found?.usage === 'IMAGE_CREATE') return 'image';
|
|
2357
2404
|
if (found?.usage === 'VIDEO_CREATE') return 'video';
|
|
2405
|
+
if (found?.usage === 'AUDIO_CREATE') return 'audio';
|
|
2358
2406
|
return ['generated_time', 'frames', 'multi_param', 'multi_prompt', 'generated_mode', 'need_audio']
|
|
2359
2407
|
.some((key) => optionKeys.has(key)) ? 'video' : 'image';
|
|
2360
2408
|
}
|
|
2361
2409
|
|
|
2362
2410
|
function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
2411
|
+
if (taskKind === 'audio') {
|
|
2412
|
+
const hasPrompt = optionKeys.has('prompt');
|
|
2413
|
+
const hasResources = optionKeys.has('resources');
|
|
2414
|
+
const resourceRules = rulesByKey.get('resources') || {};
|
|
2415
|
+
const typedResourceRules = Array.isArray(resourceRules.resources) ? resourceRules.resources : [];
|
|
2416
|
+
const supportsResourceType = (mediaType) => !typedResourceRules.length
|
|
2417
|
+
|| typedResourceRules.some((item) => String(item?.mediaType || '').toUpperCase() === mediaType);
|
|
2418
|
+
const resourceLimits = (mediaType) => typedResourceRules.length
|
|
2419
|
+
? mediaRuleFromMultiParam(resourceRules, mediaType)
|
|
2420
|
+
: normalizeMediaRule(resourceRules);
|
|
2421
|
+
return [
|
|
2422
|
+
{
|
|
2423
|
+
mode: 'prompt_only',
|
|
2424
|
+
supported: hasPrompt,
|
|
2425
|
+
intent: '文本生成音频',
|
|
2426
|
+
requiredArgs: ['--model-group-code', '--prompt', '--duration'],
|
|
2427
|
+
userInput: '提供 prompt 和生成时长,不提供参考素材。',
|
|
2428
|
+
},
|
|
2429
|
+
{
|
|
2430
|
+
mode: 'reference_audio',
|
|
2431
|
+
supported: hasResources && supportsResourceType('AUDIO'),
|
|
2432
|
+
intent: '参考音频生成',
|
|
2433
|
+
requiredArgs: ['--model-group-code', '--prompt', '--duration', '--resource audio:reference=...'],
|
|
2434
|
+
userInput: '最多提供三段参考音频。',
|
|
2435
|
+
resourceSyntax: ['audio:reference=./reference.mp3'],
|
|
2436
|
+
requiredResources: ['audio:reference'],
|
|
2437
|
+
sourceKinds: ['local_file', 'http_url', 'backendPath'],
|
|
2438
|
+
resourceLimits: resourceLimits('AUDIO'),
|
|
2439
|
+
},
|
|
2440
|
+
{
|
|
2441
|
+
mode: 'reference_image',
|
|
2442
|
+
supported: hasResources && supportsResourceType('IMAGE'),
|
|
2443
|
+
intent: '参考图片生成音频',
|
|
2444
|
+
requiredArgs: ['--model-group-code', '--prompt', '--duration', '--resource image:reference=...'],
|
|
2445
|
+
userInput: '提供一张参考图片,不能与参考音频混用。',
|
|
2446
|
+
resourceSyntax: ['image:reference=./reference.png'],
|
|
2447
|
+
requiredResources: ['image:reference'],
|
|
2448
|
+
sourceKinds: ['local_file', 'http_url', 'backendPath'],
|
|
2449
|
+
resourceLimits: resourceLimits('IMAGE'),
|
|
2450
|
+
},
|
|
2451
|
+
];
|
|
2452
|
+
}
|
|
2363
2453
|
const hasPrompt = optionKeys.has('prompt');
|
|
2364
2454
|
const hasImageReference = ['iref', 'cref', 'sref', 'resources'].some((key) => optionKeys.has(key));
|
|
2365
2455
|
const hasFrames = optionKeys.has('frames');
|
|
@@ -2570,6 +2660,17 @@ function createSpecSupportedIntents(inputModes, taskKind = null) {
|
|
|
2570
2660
|
promptBinding: 'none',
|
|
2571
2661
|
promptPlaceholder: '图片任务不使用 reference_key 或 <<<key>>>;在 prompt 中用自然语言指代参考图。',
|
|
2572
2662
|
}));
|
|
2663
|
+
} else if (taskKind === 'audio') {
|
|
2664
|
+
intents.push(compactRecord({
|
|
2665
|
+
mode: 'reference',
|
|
2666
|
+
intent: '参考素材生成音频',
|
|
2667
|
+
userInput: `用户提供${referenceLabels.join('、')}作为参考素材;参考音频与参考图片不能混用。`,
|
|
2668
|
+
requiredArgs: ['--model-group-code', '--prompt', '--duration', '--resource <audio|image>:reference=...'],
|
|
2669
|
+
resourceUsages: ['reference'],
|
|
2670
|
+
resourceSyntax: uniqueNonEmpty(referenceModes.flatMap((item) => item.resourceSyntax || [])),
|
|
2671
|
+
promptBinding: 'none',
|
|
2672
|
+
promptPlaceholder: '音频任务不使用 reference_key 或 <<<key>>>。',
|
|
2673
|
+
}));
|
|
2573
2674
|
} else {
|
|
2574
2675
|
intents.push(compactRecord({
|
|
2575
2676
|
mode: 'reference',
|
|
@@ -2746,16 +2847,20 @@ function createSpecParameterControls(createParams, inputModes = []) {
|
|
|
2746
2847
|
function createSpecAgentGuidance(taskKind, inputRequirement) {
|
|
2747
2848
|
const keyParamGuidance = taskKind === 'video'
|
|
2748
2849
|
? 'fee 或 create --dry-run 前,必须先确认用户未提供的价格 / 效果关键参数:quality、duration、约束后仍可选的 ratio;needAudio 普通模型只在用户明确要输出音效时确认。可灵 3o / Kling 3.0 支持 needAudio 时 CLI 默认开声音,用户明确不要声音时传 --need-audio false。不要静默使用 defaultValue 先估价。'
|
|
2749
|
-
:
|
|
2850
|
+
: (taskKind === 'audio'
|
|
2851
|
+
? 'fee 或 create --dry-run 前,必须确认 duration;audioFormat 未提供时默认 mp3,其余音频参数以 model options 为准。'
|
|
2852
|
+
: 'fee 或 create --dry-run 前,必须先确认用户未提供的价格 / 效果关键参数:quality、ratio、generateNum。不要静默使用 defaultValue 先估价。');
|
|
2750
2853
|
const guidance = [
|
|
2751
2854
|
'先用 model options 获取枚举值、文件类型、数量、大小、时长和条件约束;create-spec 只负责创建方式。',
|
|
2752
2855
|
'用 inputRequirement 和 supportedIntents 在 prompt_only、reference、frames、storyboard 中选择一种输入模式;不要按媒体类型拆成多个任务。',
|
|
2753
2856
|
];
|
|
2754
2857
|
if (taskKind === 'image') {
|
|
2755
2858
|
guidance.push('图片任务不使用 reference_key 或 <<<key>>>。参考图只用 --resource image:reference=... 传入,prompt 用“图一 / 图二 / 参考图 / 白发女 / 背景图”等自然语言指代。');
|
|
2756
|
-
} else {
|
|
2859
|
+
} else if (taskKind === 'video') {
|
|
2757
2860
|
guidance.push('reference_key 是视频参考资源的可选绑定;prompt 可以不写占位符。如果 prompt 写了 <<<key>>>,必须能匹配同名 reference 资源。');
|
|
2758
2861
|
guidance.push('只有 model options.resources[] 存在 media=AUDIO usage=reference 时,音频文件 / URL / asset 才能走 --resource audio:reference=...;是否需要输出音效才使用 --need-audio true/false。');
|
|
2862
|
+
} else {
|
|
2863
|
+
guidance.push('音频任务只接受 reference 用途的音频或图片;最多 3 个参考音频或 1 张参考图片,两类不能混用,也不使用 reference_key。');
|
|
2759
2864
|
}
|
|
2760
2865
|
guidance.push(
|
|
2761
2866
|
keyParamGuidance,
|
|
@@ -2781,16 +2886,21 @@ function createSpecValidationRules(taskKind) {
|
|
|
2781
2886
|
if (taskKind === 'video') {
|
|
2782
2887
|
rules.splice(4, 0, 'reference_key 仅用于视频 reference 资源的可选 prompt 占位符绑定;prompt 中出现 <<<key>>> 时,必须有同名 reference 资源。');
|
|
2783
2888
|
rules.push('subject reference 必须使用 asset:<externalId>,externalId 应来自 create subject + create subject-wait。');
|
|
2784
|
-
} else {
|
|
2889
|
+
} else if (taskKind === 'image') {
|
|
2785
2890
|
rules.push('图片任务 resources 只接受 image reference,且不接受 reference_key 或 <<<key>>>;请用自然 prompt 描述图一、图二、参考图、主体等映射。');
|
|
2891
|
+
} else {
|
|
2892
|
+
rules.push('音频任务 resources 只接受 audio/image reference;最多 3 个参考音频或 1 张参考图片,不能混用,也不接受 reference_key。');
|
|
2786
2893
|
}
|
|
2787
2894
|
return rules;
|
|
2788
2895
|
}
|
|
2789
2896
|
|
|
2790
2897
|
function createSpecPreflight(taskKind) {
|
|
2791
|
-
const
|
|
2792
|
-
|
|
2793
|
-
|
|
2898
|
+
const commands = {
|
|
2899
|
+
image: ['model image-models', 'create image-fee', 'create image'],
|
|
2900
|
+
video: ['model video-models', 'create video-fee', 'create video'],
|
|
2901
|
+
audio: ['model audio-models', 'create audio-fee', 'create audio'],
|
|
2902
|
+
};
|
|
2903
|
+
const [modelListCommand, feeCommand, createCommand] = commands[taskKind] || commands.image;
|
|
2794
2904
|
return [
|
|
2795
2905
|
'doctor --verify',
|
|
2796
2906
|
`${modelListCommand} --model <keyword>`,
|
|
@@ -2811,7 +2921,7 @@ function createSpecExamples(taskKind, supportedIntents) {
|
|
|
2811
2921
|
if (taskKind === 'image') {
|
|
2812
2922
|
if (hasIntent('prompt_only')) examples.push('lj-awb create image --model-group-code <code> --prompt "品牌吉祥物表情包四宫格" --ratio 1:1 --quality 1K --dry-run');
|
|
2813
2923
|
if (hasIntent('reference')) examples.push('lj-awb create image --model-group-code <code> --prompt "保持参考图主体,生成海报" --resource image:reference=./ref.png --dry-run');
|
|
2814
|
-
} else {
|
|
2924
|
+
} else if (taskKind === 'video') {
|
|
2815
2925
|
if (hasIntent('prompt_only')) examples.push('lj-awb create video --model-group-code <code> --prompt "机器人站在白色展台中央,缓慢转身" --duration 6 --dry-run');
|
|
2816
2926
|
if (hasIntent('reference')) {
|
|
2817
2927
|
const referenceIntent = supportedIntents.find((item) => item.mode === 'reference');
|
|
@@ -2829,6 +2939,9 @@ function createSpecExamples(taskKind, supportedIntents) {
|
|
|
2829
2939
|
}
|
|
2830
2940
|
}
|
|
2831
2941
|
if (hasIntent('storyboard')) examples.push('lj-awb create video --model-group-code <code> --resources-json ./storyboard.json --duration 5 --dry-run');
|
|
2942
|
+
} else {
|
|
2943
|
+
if (hasIntent('prompt_only')) examples.push('lj-awb create audio --model-group-code <code> --prompt "轻快明亮的电子音乐" --duration 6 --dry-run');
|
|
2944
|
+
if (hasIntent('reference')) examples.push('lj-awb create audio --model-group-code <code> --prompt "保持参考音色,生成舒缓配乐" --duration 6 --resource audio:reference=./reference.mp3 --dry-run');
|
|
2832
2945
|
}
|
|
2833
2946
|
return examples;
|
|
2834
2947
|
}
|
|
@@ -2854,6 +2967,12 @@ function modelOptionParams(options = [], taskKind = 'image') {
|
|
|
2854
2967
|
const maxLength = option.paramType === 'Prompt'
|
|
2855
2968
|
? ruleNumber(rules.maxValue ?? rules.maxLength ?? rules.maxPromptLength)
|
|
2856
2969
|
: undefined;
|
|
2970
|
+
const minValue = taskKind !== 'audio' || option.paramType === 'Prompt'
|
|
2971
|
+
? undefined
|
|
2972
|
+
: ruleNumber(rules.minValue ?? rules.min);
|
|
2973
|
+
const maxValue = taskKind !== 'audio' || option.paramType === 'Prompt'
|
|
2974
|
+
? undefined
|
|
2975
|
+
: ruleNumber(rules.maxValue ?? rules.max);
|
|
2857
2976
|
return compactRecord({
|
|
2858
2977
|
key: createParam.key,
|
|
2859
2978
|
label: option.paramName,
|
|
@@ -2862,6 +2981,8 @@ function modelOptionParams(options = [], taskKind = 'image') {
|
|
|
2862
2981
|
defaultValue,
|
|
2863
2982
|
defaultName: modelParamDefaultName(option),
|
|
2864
2983
|
maxLength,
|
|
2984
|
+
minValue,
|
|
2985
|
+
maxValue,
|
|
2865
2986
|
required,
|
|
2866
2987
|
cliArg: createParam.cliArg,
|
|
2867
2988
|
genericModelParam: createParam.genericModelParam || undefined,
|
|
@@ -3020,13 +3141,19 @@ export async function modelCreateSpec(kwargs = {}) {
|
|
|
3020
3141
|
const context = await loadModelOptionContext(modelGroupCode, { includeRaw });
|
|
3021
3142
|
const supportedIntents = createSpecSupportedIntents(context.inputModes, context.taskKind);
|
|
3022
3143
|
const inputRequirement = createSpecInputRequirement(context.taskKind, context.inputModes, supportedIntents);
|
|
3144
|
+
const commandByTaskKind = {
|
|
3145
|
+
image: { create: 'create image', fee: 'create image-fee', taskType: 'IMAGE_CREATE' },
|
|
3146
|
+
video: { create: 'create video', fee: 'create video-fee', taskType: 'VIDEO_GROUP' },
|
|
3147
|
+
audio: { create: 'create audio', fee: 'create audio-fee', taskType: 'AUDIO_CREATE' },
|
|
3148
|
+
};
|
|
3149
|
+
const commands = commandByTaskKind[context.taskKind] || commandByTaskKind.image;
|
|
3023
3150
|
return compactRecord({
|
|
3024
3151
|
schemaVersion: 1,
|
|
3025
3152
|
modelGroupCode,
|
|
3026
3153
|
taskKind: context.taskKind,
|
|
3027
|
-
createCommand:
|
|
3028
|
-
feeCommand:
|
|
3029
|
-
statusCommandTaskType:
|
|
3154
|
+
createCommand: commands.create,
|
|
3155
|
+
feeCommand: commands.fee,
|
|
3156
|
+
statusCommandTaskType: commands.taskType,
|
|
3030
3157
|
optionsCommand: `model options --model-group-code ${modelGroupCode}`,
|
|
3031
3158
|
model: context.model,
|
|
3032
3159
|
inputRequirement,
|
|
@@ -3064,6 +3191,7 @@ const AUDIO_VIDEO_EXTENSIONS = new Set([
|
|
|
3064
3191
|
'.oga',
|
|
3065
3192
|
'.ogg',
|
|
3066
3193
|
'.ogv',
|
|
3194
|
+
'.pcm',
|
|
3067
3195
|
'.wav',
|
|
3068
3196
|
'.webm',
|
|
3069
3197
|
]);
|
|
@@ -4219,7 +4347,7 @@ const RESOURCE_SOURCE_KEYS = new Set(['kind', 'value']);
|
|
|
4219
4347
|
const RESOURCE_TYPES = new Set(['image', 'video', 'audio', 'subject']);
|
|
4220
4348
|
const RESOURCE_USAGES = new Set(['reference', 'first_frame', 'last_frame', 'keyframe']);
|
|
4221
4349
|
|
|
4222
|
-
function parseIntegerParam(value, name, minValue) {
|
|
4350
|
+
function parseIntegerParam(value, name, minValue, maxValue = null) {
|
|
4223
4351
|
if (value == null || value === '') return null;
|
|
4224
4352
|
const text = String(value).trim();
|
|
4225
4353
|
if (!/^[+-]?\d+$/.test(text)) {
|
|
@@ -4232,9 +4360,24 @@ function parseIntegerParam(value, name, minValue) {
|
|
|
4232
4360
|
if (parsed < minValue) {
|
|
4233
4361
|
throw argumentError(`${name} 必须是${minValue === 0 ? '非负整数' : '正整数'}`);
|
|
4234
4362
|
}
|
|
4363
|
+
if (maxValue != null && parsed > maxValue) {
|
|
4364
|
+
throw argumentError(`${name} 不能超过 ${maxValue}`);
|
|
4365
|
+
}
|
|
4235
4366
|
return parsed;
|
|
4236
4367
|
}
|
|
4237
4368
|
|
|
4369
|
+
export function normalizeAudioSpeakerId(value) {
|
|
4370
|
+
const speaker = trimToNull(value);
|
|
4371
|
+
if (!speaker) return null;
|
|
4372
|
+
if (!AUDIO_SPEAKER_ID_PATTERN.test(speaker)) {
|
|
4373
|
+
throw argumentError(
|
|
4374
|
+
'--speaker 必须传火山音色表中的 voice_type,不能传音色名称',
|
|
4375
|
+
'请从 https://docs.volcengine.com/docs/6561/1257544?lang=zh 原样复制音色名称同一行的完整 voice_type;不得拼接或猜测 ID。',
|
|
4376
|
+
);
|
|
4377
|
+
}
|
|
4378
|
+
return speaker;
|
|
4379
|
+
}
|
|
4380
|
+
|
|
4238
4381
|
function normalizeUnifiedPromptParams(promptParams) {
|
|
4239
4382
|
if (promptParams.duration != null && promptParams.duration !== '') {
|
|
4240
4383
|
promptParams.duration = parseIntegerParam(promptParams.duration, 'promptParams.duration', 0);
|
|
@@ -4472,6 +4615,21 @@ async function collectResourceSpecs(kwargs = {}, options = {}) {
|
|
|
4472
4615
|
});
|
|
4473
4616
|
if (Array.isArray(resourcesJson)) items.push(...resourcesJson);
|
|
4474
4617
|
return items.map((item, index) => normalizeResourceObject(item, index)).filter((item) => {
|
|
4618
|
+
if (options.kind === 'audio') {
|
|
4619
|
+
if (!['audio', 'image'].includes(item.type)) {
|
|
4620
|
+
throw argumentError('音频任务 resource 只支持 type=audio 或 type=image');
|
|
4621
|
+
}
|
|
4622
|
+
if (item.usage !== 'reference') {
|
|
4623
|
+
throw argumentError('音频任务 resource 只支持 usage=reference');
|
|
4624
|
+
}
|
|
4625
|
+
if (item.reference_key) {
|
|
4626
|
+
throw argumentError('音频任务 reference 不支持 reference_key');
|
|
4627
|
+
}
|
|
4628
|
+
if (item._source.kind !== 'url') {
|
|
4629
|
+
throw argumentError('音频任务 resource 暂只支持 url,本地文件会自动上传为 url');
|
|
4630
|
+
}
|
|
4631
|
+
return true;
|
|
4632
|
+
}
|
|
4475
4633
|
if (options.kind !== 'image') return true;
|
|
4476
4634
|
if (item.type !== 'image') {
|
|
4477
4635
|
throw argumentError('图片任务 resource 只支持 type=image');
|
|
@@ -4935,7 +5093,7 @@ async function buildVideoRequest(kwargs = {}, options = {}) {
|
|
|
4935
5093
|
if (shouldDefaultNeedAudioForVideoModel(validation.context.model, validation.params, promptParams)) {
|
|
4936
5094
|
defaultParams.need_audio = true;
|
|
4937
5095
|
promptParams = normalizeUnifiedPromptParams(defaultParams);
|
|
4938
|
-
assertParamsAgainstModel(promptParams, validation.params, validation.context.constraints);
|
|
5096
|
+
assertParamsAgainstModel(promptParams, validation.params, validation.context.constraints, validation.context.taskKind);
|
|
4939
5097
|
}
|
|
4940
5098
|
const resolvedResources = await resolveResources(kwargs, {
|
|
4941
5099
|
dryRun,
|
|
@@ -5027,6 +5185,149 @@ export async function videoCreate(kwargs = {}) {
|
|
|
5027
5185
|
};
|
|
5028
5186
|
}
|
|
5029
5187
|
|
|
5188
|
+
async function buildAudioRequest(kwargs = {}, options = {}) {
|
|
5189
|
+
const dryRun = Boolean(options.dryRun);
|
|
5190
|
+
const model = resolveTaskModel('audio', kwargs);
|
|
5191
|
+
const prompt = trimToNull(kwargs.prompt);
|
|
5192
|
+
if (!prompt) throw argumentError('缺少音频生成提示词', '传 --prompt <text>。');
|
|
5193
|
+
|
|
5194
|
+
const duration = parseIntegerParam(kwargs.duration, '--duration', 1, 120);
|
|
5195
|
+
if (duration == null) throw argumentError('缺少音频生成时长', '传 --duration <seconds>,支持 1-120 秒。');
|
|
5196
|
+
|
|
5197
|
+
const validationResources = await resolveResources(kwargs, {
|
|
5198
|
+
dryRun: true,
|
|
5199
|
+
kind: 'audio',
|
|
5200
|
+
sceneType: TASK_UPLOAD_SCENE.AUDIO_CREATE,
|
|
5201
|
+
});
|
|
5202
|
+
const audioReferenceCount = validationResources.resources.filter((item) => item.type === 'audio').length;
|
|
5203
|
+
const imageReferenceCount = validationResources.resources.filter((item) => item.type === 'image').length;
|
|
5204
|
+
if (audioReferenceCount > 3) throw argumentError('参考音频最多支持 3 个');
|
|
5205
|
+
if (imageReferenceCount > 1) throw argumentError('参考图片最多支持 1 张');
|
|
5206
|
+
if (audioReferenceCount && imageReferenceCount) {
|
|
5207
|
+
throw argumentError('参考音频和参考图片不能混用');
|
|
5208
|
+
}
|
|
5209
|
+
const genericModelParams = await collectGenericModelParams(kwargs);
|
|
5210
|
+
const defaultParams = {
|
|
5211
|
+
...genericModelParams,
|
|
5212
|
+
prompt,
|
|
5213
|
+
duration,
|
|
5214
|
+
audio_format: trimToNull(kwargs.audioFormat ?? kwargs.audio_format) ?? 'mp3',
|
|
5215
|
+
resources: validationResources.resources,
|
|
5216
|
+
};
|
|
5217
|
+
const speaker = normalizeAudioSpeakerId(kwargs.speaker ?? defaultParams.speaker);
|
|
5218
|
+
if (speaker) defaultParams.speaker = speaker;
|
|
5219
|
+
else delete defaultParams.speaker;
|
|
5220
|
+
const integerOptions = [
|
|
5221
|
+
['sample_rate', kwargs.sampleRate ?? kwargs.sample_rate, 1],
|
|
5222
|
+
['speech_rate', kwargs.speechRate ?? kwargs.speech_rate, -50],
|
|
5223
|
+
['loudness_rate', kwargs.loudnessRate ?? kwargs.loudness_rate, -50],
|
|
5224
|
+
['pitch_rate', kwargs.pitchRate ?? kwargs.pitch_rate, -12],
|
|
5225
|
+
];
|
|
5226
|
+
for (const [key, value, min] of integerOptions) {
|
|
5227
|
+
if (value != null && value !== '') defaultParams[key] = parseIntegerParam(value, `--${key.replaceAll('_', '-')}`, min);
|
|
5228
|
+
}
|
|
5229
|
+
const enableSubtitle = kwargs.enableSubtitle ?? kwargs.enable_subtitle;
|
|
5230
|
+
if (enableSubtitle != null && enableSubtitle !== '') defaultParams.enable_subtitle = toBool(enableSubtitle);
|
|
5231
|
+
|
|
5232
|
+
const promptParams = normalizeUnifiedPromptParams(defaultParams);
|
|
5233
|
+
const validation = await validateCreateRequestAgainstModel(
|
|
5234
|
+
'audio', model.modelGroupCode, promptParams, validationResources.resourceDetails,
|
|
5235
|
+
);
|
|
5236
|
+
const resolvedResources = await resolveResources(kwargs, {
|
|
5237
|
+
dryRun,
|
|
5238
|
+
kind: 'audio',
|
|
5239
|
+
sceneType: TASK_UPLOAD_SCENE.AUDIO_CREATE,
|
|
5240
|
+
resourceRules: validation.resourceRules,
|
|
5241
|
+
});
|
|
5242
|
+
const requestPromptParams = normalizeUnifiedPromptParams({
|
|
5243
|
+
...defaultParams,
|
|
5244
|
+
resources: resolvedResources.resources,
|
|
5245
|
+
});
|
|
5246
|
+
const projectGroupNo = await resolveProjectGroupNo(kwargs.projectGroupNo, {
|
|
5247
|
+
allowNull: dryRun,
|
|
5248
|
+
noNetwork: dryRun,
|
|
5249
|
+
noSave: dryRun,
|
|
5250
|
+
});
|
|
5251
|
+
return {
|
|
5252
|
+
model,
|
|
5253
|
+
projectGroupNo,
|
|
5254
|
+
uploads: resolvedResources.uploads,
|
|
5255
|
+
localFiles: resolvedResources.localFiles,
|
|
5256
|
+
resourceConversions: resolvedResources.resourceConversions,
|
|
5257
|
+
request: {
|
|
5258
|
+
requestSource: REQUEST_SOURCE_CLI,
|
|
5259
|
+
modelGroupCode: model.modelGroupCode,
|
|
5260
|
+
promptParams: requestPromptParams,
|
|
5261
|
+
...(projectGroupNo ? { projectGroupNo } : {}),
|
|
5262
|
+
},
|
|
5263
|
+
};
|
|
5264
|
+
}
|
|
5265
|
+
|
|
5266
|
+
export async function audioFee(kwargs = {}) {
|
|
5267
|
+
if (toBool(kwargs.dryRun)) {
|
|
5268
|
+
const built = await buildAudioRequest(kwargs, { dryRun: true });
|
|
5269
|
+
return compactRecord({
|
|
5270
|
+
dryRun: true,
|
|
5271
|
+
action: 'create audio-fee',
|
|
5272
|
+
request: built.request,
|
|
5273
|
+
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
5274
|
+
});
|
|
5275
|
+
}
|
|
5276
|
+
const built = await buildAudioRequest(kwargs);
|
|
5277
|
+
const payload = await awbApi.fetchAudioFee(built.request);
|
|
5278
|
+
return {
|
|
5279
|
+
data: payload,
|
|
5280
|
+
...(await pointEstimate(payload, built.projectGroupNo)),
|
|
5281
|
+
};
|
|
5282
|
+
}
|
|
5283
|
+
|
|
5284
|
+
export async function audioCreate(kwargs = {}) {
|
|
5285
|
+
if (toBool(kwargs.dryRun)) {
|
|
5286
|
+
const built = await buildAudioRequest(kwargs, { dryRun: true });
|
|
5287
|
+
return compactRecord({
|
|
5288
|
+
dryRun: true,
|
|
5289
|
+
action: 'create audio',
|
|
5290
|
+
request: built.request,
|
|
5291
|
+
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
5292
|
+
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
5293
|
+
});
|
|
5294
|
+
}
|
|
5295
|
+
ensureConfirmed(kwargs, '正式生成音频会消耗积分,需要确认', { action: 'create audio' });
|
|
5296
|
+
const built = await buildAudioRequest(kwargs);
|
|
5297
|
+
const feePayload = await awbApi.fetchAudioFee(built.request).catch(() => null);
|
|
5298
|
+
const estimate = await pointEstimate(feePayload, built.projectGroupNo).catch(() => ({}));
|
|
5299
|
+
const payload = await awbApi.createAudioTask(built.request);
|
|
5300
|
+
const result = normalizeCreatedTask(payload, {
|
|
5301
|
+
...estimate,
|
|
5302
|
+
projectGroupNo: built.projectGroupNo,
|
|
5303
|
+
modelGroupCode: built.request.modelGroupCode,
|
|
5304
|
+
...(built.uploads.length ? { uploads: normalizeCreateUploads(built.uploads) } : {}),
|
|
5305
|
+
});
|
|
5306
|
+
await appendTaskRecord(kwargs, {
|
|
5307
|
+
taskId: result.taskId,
|
|
5308
|
+
taskType: 'AUDIO_CREATE',
|
|
5309
|
+
projectGroupNo: built.projectGroupNo,
|
|
5310
|
+
modelGroupCode: built.request.modelGroupCode,
|
|
5311
|
+
promptSummary: taskPromptSummary({ prompt: built.request.promptParams?.prompt }),
|
|
5312
|
+
});
|
|
5313
|
+
if (toInt(kwargs.waitSeconds, 0) > 0 && result.taskId) {
|
|
5314
|
+
return {
|
|
5315
|
+
...result,
|
|
5316
|
+
waited: await waitTask({
|
|
5317
|
+
taskId: result.taskId,
|
|
5318
|
+
taskType: 'AUDIO_CREATE',
|
|
5319
|
+
projectGroupNo: built.projectGroupNo,
|
|
5320
|
+
waitSeconds: kwargs.waitSeconds,
|
|
5321
|
+
pollIntervalMs: kwargs.pollIntervalMs,
|
|
5322
|
+
}),
|
|
5323
|
+
};
|
|
5324
|
+
}
|
|
5325
|
+
return {
|
|
5326
|
+
...result,
|
|
5327
|
+
nextCommand: result.taskId ? `lj-awb task wait --task-id ${result.taskId} -f json` : null,
|
|
5328
|
+
};
|
|
5329
|
+
}
|
|
5330
|
+
|
|
5030
5331
|
export async function loadBatchItems(inputFile, mode = 'generic') {
|
|
5031
5332
|
const filePath = trimToNull(inputFile);
|
|
5032
5333
|
if (!filePath) throw argumentError('缺少批量输入文件', '传 --input-file <json|jsonl|txt>。');
|