cerevox 4.0.0-alpha.1 → 4.0.0-alpha.3
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/dist/mcp/servers/prompts/outlines-backup.md +37 -12
- package/dist/mcp/servers/prompts/skills//344/270/200/351/224/256/346/210/220/347/211/207.md +2 -1
- package/dist/mcp/servers/zerocut.d.ts.map +1 -1
- package/dist/mcp/servers/zerocut.js +27 -909
- package/dist/mcp/servers/zerocut.js.map +1 -1
- package/package.json +1 -1
- /package/dist/mcp/servers/prompts/{zerocut-core copy.md → zerocut-core-web.md} +0 -0
|
@@ -261,7 +261,7 @@ async function filterMaterialsForUpload(materials, projectLocalDir) {
|
|
|
261
261
|
regularFiles.push(material);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
//
|
|
264
|
+
// 处理分镜文件(scXX_ 前缀)
|
|
265
265
|
if (sceneFiles.length > 0 && mediaLogs.length > 0) {
|
|
266
266
|
// 按前缀和扩展名分组
|
|
267
267
|
const groupedFiles = new Map();
|
|
@@ -309,7 +309,7 @@ async function filterMaterialsForUpload(materials, projectLocalDir) {
|
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
else {
|
|
312
|
-
// 如果没有 media_logs.json
|
|
312
|
+
// 如果没有 media_logs.json 或没有分镜文件,全部上传
|
|
313
313
|
filesToUpload.push(...sceneFiles);
|
|
314
314
|
}
|
|
315
315
|
// 处理普通文件(全量上传)
|
|
@@ -341,7 +341,7 @@ server.registerPrompt('zerocut-guideline', {
|
|
|
341
341
|
description: '专业的短视频创作 Agent 指导规范,包含完整的工作流程、工具说明和质量建议',
|
|
342
342
|
}, async () => {
|
|
343
343
|
try {
|
|
344
|
-
const promptPath = (0, node_path_1.resolve)(__dirname, './prompts/zerocut-core.md');
|
|
344
|
+
const promptPath = (0, node_path_1.resolve)(__dirname, './prompts/zerocut-core-web.md');
|
|
345
345
|
const promptContent = await (0, promises_1.readFile)(promptPath, 'utf-8');
|
|
346
346
|
return {
|
|
347
347
|
messages: [
|
|
@@ -356,8 +356,8 @@ server.registerPrompt('zerocut-guideline', {
|
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
358
|
catch (error) {
|
|
359
|
-
console.error('Failed to load zerocut-guideline prompt:', error);
|
|
360
|
-
throw new Error(`Failed to load zerocut-guideline prompt: ${error}`);
|
|
359
|
+
console.error('Failed to load zerocut-guideline-web prompt:', error);
|
|
360
|
+
throw new Error(`Failed to load zerocut-guideline-web prompt: ${error}`);
|
|
361
361
|
}
|
|
362
362
|
});
|
|
363
363
|
server.registerTool('project-open', {
|
|
@@ -586,56 +586,6 @@ server.registerTool('retrieve-rules-context', {
|
|
|
586
586
|
const ai = currentSession.ai;
|
|
587
587
|
const { data: rules } = await ai.listContextRules();
|
|
588
588
|
if (!promptContent) {
|
|
589
|
-
const rulesList = rules
|
|
590
|
-
.filter((rule) => !rule.name.startsWith('skill-'))
|
|
591
|
-
.map((rule) => ({
|
|
592
|
-
name: rule.name,
|
|
593
|
-
trigger: rule.trigger,
|
|
594
|
-
}));
|
|
595
|
-
const chooseRulePrompt = `当前ZeroCut版本:${constants_1.VERSION}
|
|
596
|
-
|
|
597
|
-
请分析用户具体指令,匹配可用规则中的trigger,选择最合适的规则。
|
|
598
|
-
|
|
599
|
-
## 可用规则:
|
|
600
|
-
${JSON.stringify(rulesList, null, 2)}
|
|
601
|
-
|
|
602
|
-
请返回一个 JSON 字符串,包含用户意图对应的规则名称。格式为:{"rule_name": "规则名称"}
|
|
603
|
-
`;
|
|
604
|
-
const schema = {
|
|
605
|
-
name: 'choose_rule',
|
|
606
|
-
schema: {
|
|
607
|
-
type: 'object',
|
|
608
|
-
properties: {
|
|
609
|
-
rule_name: {
|
|
610
|
-
type: 'string',
|
|
611
|
-
description: '用户意图对应的规则名称',
|
|
612
|
-
},
|
|
613
|
-
},
|
|
614
|
-
required: ['rule_name'],
|
|
615
|
-
},
|
|
616
|
-
};
|
|
617
|
-
const completion = await ai.getCompletions({
|
|
618
|
-
model: 'Doubao-Seed-1.6-flash',
|
|
619
|
-
messages: [
|
|
620
|
-
{
|
|
621
|
-
role: 'system',
|
|
622
|
-
content: chooseRulePrompt,
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
role: 'user',
|
|
626
|
-
content: request,
|
|
627
|
-
},
|
|
628
|
-
],
|
|
629
|
-
response_format: {
|
|
630
|
-
type: 'json_schema',
|
|
631
|
-
json_schema: schema,
|
|
632
|
-
},
|
|
633
|
-
});
|
|
634
|
-
const ruleName = JSON.parse(completion.choices[0].message.content).rule_name;
|
|
635
|
-
// let rule = rules.find((rule: any) => rule.name === ruleName);
|
|
636
|
-
// if (!rule) {
|
|
637
|
-
// rule = rules.find((rule: any) => rule.name === '通用视频助手');
|
|
638
|
-
// }
|
|
639
589
|
const rule = rules.find((rule) => rule.name === 'core-rules');
|
|
640
590
|
promptContent = rule.prompt;
|
|
641
591
|
// 确保目录存在
|
|
@@ -1070,12 +1020,12 @@ server.registerTool('generate-image', {
|
|
|
1070
1020
|
.default('seedream-pro'),
|
|
1071
1021
|
prompt: zod_1.z
|
|
1072
1022
|
.string()
|
|
1073
|
-
.describe('The prompt to generate. 一般要严格对应 storyboard
|
|
1023
|
+
.describe('The prompt to generate. 一般要严格对应 storyboard 中当前分镜的 start_frame 或 end_frame 中的字段描述,如果是生成线稿,则 type 使用 line-sketch,如果是生成故事板印样或人物镜头宫格,则 type 使用 shot-grid'),
|
|
1074
1024
|
sceneIndex: zod_1.z
|
|
1075
1025
|
.number()
|
|
1076
1026
|
.min(1)
|
|
1077
1027
|
.optional()
|
|
1078
|
-
.describe('
|
|
1028
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
1079
1029
|
storyBoardFile: zod_1.z
|
|
1080
1030
|
.string()
|
|
1081
1031
|
.optional()
|
|
@@ -1181,14 +1131,7 @@ server.registerTool('generate-image', {
|
|
|
1181
1131
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
1182
1132
|
const outlineSheetImagePath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'materials', 'outline_sheet.png');
|
|
1183
1133
|
const hasOutlineSheet = (0, node_fs_1.existsSync)(outlineSheetImagePath);
|
|
1184
|
-
//
|
|
1185
|
-
if (!hasOutlineSheet &&
|
|
1186
|
-
!checkStoryboardFlag &&
|
|
1187
|
-
(0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
1188
|
-
checkStoryboardFlag = true;
|
|
1189
|
-
return createErrorResponse('必须先审查生成的 storyboard.json 内容,确保每个场景中的stage_atmosphere内容按照规则被正确融合到start_frame和video_prompt中,不得遗漏,检查完成后先汇报,如果有问题,应当先修改 storyboard.json 内容,然后再调用 generate-image 生成图片。注意修改 storyboard 内容时,仅修改相应字段的字符串值,不要破坏JSON格式!', 'generate-image');
|
|
1190
|
-
}
|
|
1191
|
-
// 校验 prompt 与 storyboard.json 中场景设定的一致性
|
|
1134
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性
|
|
1192
1135
|
if (sceneIndex && !skipConsistencyCheck) {
|
|
1193
1136
|
try {
|
|
1194
1137
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
@@ -1276,73 +1219,6 @@ server.registerTool('generate-image', {
|
|
|
1276
1219
|
// 检查并替换英文单引号包裹的中文内容为中文双引号
|
|
1277
1220
|
// 这样才能让 seedream 生成更好的中文文字
|
|
1278
1221
|
let processedPrompt = prompt.replace(/'([^']*[\u4e00-\u9fff][^']*)'/g, '“$1”');
|
|
1279
|
-
try {
|
|
1280
|
-
const ai = currentSession.ai;
|
|
1281
|
-
const promptOptimizer = await (0, promises_1.readFile)((0, node_path_1.resolve)(__dirname, './prompts/image-prompt-optimizer.md'), 'utf8');
|
|
1282
|
-
if (!hasOutlineSheet) {
|
|
1283
|
-
const schema = {
|
|
1284
|
-
name: 'optimize_image_prompt',
|
|
1285
|
-
schema: {
|
|
1286
|
-
type: 'object',
|
|
1287
|
-
properties: {
|
|
1288
|
-
prompt_optimized: {
|
|
1289
|
-
type: 'string',
|
|
1290
|
-
description: '优化后的提示词',
|
|
1291
|
-
},
|
|
1292
|
-
metaphor_modifiers: {
|
|
1293
|
-
type: 'array',
|
|
1294
|
-
description: '从 prompt_optimized 中抽取的所有比喻修饰词(字符串数组)',
|
|
1295
|
-
items: {
|
|
1296
|
-
type: 'string',
|
|
1297
|
-
description: '比喻性修饰词,例如 “如羽毛般轻盈”、“像晨雾一样柔和”',
|
|
1298
|
-
},
|
|
1299
|
-
},
|
|
1300
|
-
},
|
|
1301
|
-
required: ['prompt_optimized', 'metaphor_modifiers'],
|
|
1302
|
-
},
|
|
1303
|
-
};
|
|
1304
|
-
const completion = await ai.getCompletions({
|
|
1305
|
-
model: 'Doubao-Seed-1.6',
|
|
1306
|
-
messages: [
|
|
1307
|
-
{
|
|
1308
|
-
role: 'system',
|
|
1309
|
-
content: promptOptimizer,
|
|
1310
|
-
},
|
|
1311
|
-
{
|
|
1312
|
-
role: 'user',
|
|
1313
|
-
content: `## 用户指令
|
|
1314
|
-
|
|
1315
|
-
${processedPrompt.trim()}
|
|
1316
|
-
|
|
1317
|
-
## 参考图
|
|
1318
|
-
|
|
1319
|
-
${referenceImages?.map((ref, index) => `图${index + 1}:${ref.image}`).join('\n') || '无'}`,
|
|
1320
|
-
},
|
|
1321
|
-
],
|
|
1322
|
-
response_format: {
|
|
1323
|
-
type: 'json_schema',
|
|
1324
|
-
json_schema: schema,
|
|
1325
|
-
},
|
|
1326
|
-
});
|
|
1327
|
-
const optimizedPrompt = completion.choices[0]?.message?.content.trim();
|
|
1328
|
-
if (optimizedPrompt) {
|
|
1329
|
-
try {
|
|
1330
|
-
const { prompt_optimized, metaphor_modifiers } = JSON.parse(optimizedPrompt);
|
|
1331
|
-
processedPrompt = `${prompt_optimized}`;
|
|
1332
|
-
if (metaphor_modifiers?.length) {
|
|
1333
|
-
processedPrompt += `\n\n注意:下面这些是形象比喻,并不是输出内容。\n${metaphor_modifiers}`;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
catch (ex) {
|
|
1337
|
-
console.error('Failed to parse optimized prompt:', ex);
|
|
1338
|
-
processedPrompt = optimizedPrompt;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
catch (error) {
|
|
1344
|
-
console.error('Failed to optimize prompt:', error);
|
|
1345
|
-
}
|
|
1346
1222
|
if (imageCount > 1) {
|
|
1347
1223
|
processedPrompt = `请生成${imageCount}张${size}大小的关联图片,每张图分别生成,不要拼接为大图 ${processedPrompt}`;
|
|
1348
1224
|
}
|
|
@@ -1415,7 +1291,7 @@ server.registerTool('generate-image', {
|
|
|
1415
1291
|
if (objectPrefix.length > 0) {
|
|
1416
1292
|
processedPrompt = `${objectPrefix.join('\n')}
|
|
1417
1293
|
|
|
1418
|
-
${turnaroundMessage}
|
|
1294
|
+
${turnaroundMessage}参考以上图片,执行以下绘图指令:
|
|
1419
1295
|
${processedPrompt}`.trim();
|
|
1420
1296
|
}
|
|
1421
1297
|
}
|
|
@@ -1452,7 +1328,7 @@ ${processedPrompt}`.trim();
|
|
|
1452
1328
|
];
|
|
1453
1329
|
}
|
|
1454
1330
|
else {
|
|
1455
|
-
//
|
|
1331
|
+
// 多图
|
|
1456
1332
|
uris = await Promise.all(res.urls.map((url, i) => {
|
|
1457
1333
|
if (!url)
|
|
1458
1334
|
return '';
|
|
@@ -2076,695 +1952,6 @@ server.registerTool('text-to-speech', {
|
|
|
2076
1952
|
return createErrorResponse(error, 'text-to-speech');
|
|
2077
1953
|
}
|
|
2078
1954
|
});
|
|
2079
|
-
// server.registerTool(
|
|
2080
|
-
// 'generate-scene-tts',
|
|
2081
|
-
// {
|
|
2082
|
-
// title: 'Generate Scene TTS',
|
|
2083
|
-
// description: `生成场景配音`,
|
|
2084
|
-
// inputSchema: {
|
|
2085
|
-
// text: z.string().describe('The text to generate.'),
|
|
2086
|
-
// sceneIndex: z
|
|
2087
|
-
// .number()
|
|
2088
|
-
// .min(1)
|
|
2089
|
-
// .optional()
|
|
2090
|
-
// .describe(
|
|
2091
|
-
// '场景索引,从1开始的下标,如果非场景对应素材,则可不传,场景素材必传'
|
|
2092
|
-
// ),
|
|
2093
|
-
// storyBoardFile: z
|
|
2094
|
-
// .string()
|
|
2095
|
-
// .optional()
|
|
2096
|
-
// .default('storyboard.json')
|
|
2097
|
-
// .describe('故事板文件路径'),
|
|
2098
|
-
// skipConsistencyCheck: z
|
|
2099
|
-
// .boolean()
|
|
2100
|
-
// .optional()
|
|
2101
|
-
// .default(false)
|
|
2102
|
-
// .describe('是否跳过一致性检查,默认为false(即默认进行一致性检查)'),
|
|
2103
|
-
// skipCheckWithSceneReason: z
|
|
2104
|
-
// .string()
|
|
2105
|
-
// .optional()
|
|
2106
|
-
// .describe(
|
|
2107
|
-
// '跳过校验的理由,如果skipConsistencyCheck设为true,必须要传这个参数'
|
|
2108
|
-
// ),
|
|
2109
|
-
// saveToFileName: z
|
|
2110
|
-
// .string()
|
|
2111
|
-
// .describe('The filename to save. 应该是mp3文件'),
|
|
2112
|
-
// speed: z
|
|
2113
|
-
// .number()
|
|
2114
|
-
// .min(0.5)
|
|
2115
|
-
// .max(2)
|
|
2116
|
-
// .optional()
|
|
2117
|
-
// .default(1)
|
|
2118
|
-
// .describe('The speed of the tts.'),
|
|
2119
|
-
// pitch: z
|
|
2120
|
-
// .number()
|
|
2121
|
-
// .min(-12)
|
|
2122
|
-
// .max(12)
|
|
2123
|
-
// .optional()
|
|
2124
|
-
// .default(0)
|
|
2125
|
-
// .describe('The pitch of the tts.'),
|
|
2126
|
-
// volume: z
|
|
2127
|
-
// .number()
|
|
2128
|
-
// .min(0)
|
|
2129
|
-
// .max(10)
|
|
2130
|
-
// .optional()
|
|
2131
|
-
// .default(1.0)
|
|
2132
|
-
// .describe('The volume of the tts.'),
|
|
2133
|
-
// voiceID: z
|
|
2134
|
-
// .string()
|
|
2135
|
-
// .describe(
|
|
2136
|
-
// `适合作为视频配音的音色ID,除非用户指定,否则你必须确保已通过 pick-voice 工具挑选出真实存在的音色。`
|
|
2137
|
-
// ),
|
|
2138
|
-
// context_texts: z
|
|
2139
|
-
// .array(z.string())
|
|
2140
|
-
// .default([])
|
|
2141
|
-
// .describe(
|
|
2142
|
-
// `语音合成的辅助信息,用于模型对话式合成,能更好的体现语音情感
|
|
2143
|
-
// 可以探索,比如常见示例有以下几种:
|
|
2144
|
-
// 1. 语速调整
|
|
2145
|
-
// - context_texts: ["你可以说慢一点吗?"]
|
|
2146
|
-
// 2. 情绪/语气调整
|
|
2147
|
-
// - context_texts=["你可以用特别特别痛心的语气说话吗?"]
|
|
2148
|
-
// - context_texts=["嗯,你的语气再欢乐一点"]
|
|
2149
|
-
// 3. 音量调整
|
|
2150
|
-
// - context_texts=["你嗓门再小点。"]
|
|
2151
|
-
// 4. 音感调整
|
|
2152
|
-
// - context_texts=["你能用骄傲的语气来说话吗?"]
|
|
2153
|
-
// `
|
|
2154
|
-
// ),
|
|
2155
|
-
// explicit_language: z.enum(['zh', 'en', 'ja']).optional().default('zh'),
|
|
2156
|
-
// },
|
|
2157
|
-
// },
|
|
2158
|
-
// async ({
|
|
2159
|
-
// text,
|
|
2160
|
-
// sceneIndex,
|
|
2161
|
-
// storyBoardFile,
|
|
2162
|
-
// skipConsistencyCheck,
|
|
2163
|
-
// voiceID,
|
|
2164
|
-
// saveToFileName,
|
|
2165
|
-
// speed,
|
|
2166
|
-
// pitch,
|
|
2167
|
-
// volume,
|
|
2168
|
-
// context_texts,
|
|
2169
|
-
// explicit_language,
|
|
2170
|
-
// }) => {
|
|
2171
|
-
// try {
|
|
2172
|
-
// // 验证session状态
|
|
2173
|
-
// const currentSession = await validateSession('generate-scene-tts');
|
|
2174
|
-
// const validatedFileName = validateFileName(saveToFileName);
|
|
2175
|
-
// const finalSpeed = speed ?? 1;
|
|
2176
|
-
// volume = volume ?? 1;
|
|
2177
|
-
// const ai = currentSession.ai;
|
|
2178
|
-
// let scene = null;
|
|
2179
|
-
// // 校验 text 与 storyboard.json 中场景设定的一致性
|
|
2180
|
-
// if (sceneIndex && !skipConsistencyCheck) {
|
|
2181
|
-
// try {
|
|
2182
|
-
// const voice = (await ai.listVoices()).find(v => v.id === voiceID);
|
|
2183
|
-
// if (!voice) {
|
|
2184
|
-
// return createErrorResponse(
|
|
2185
|
-
// `Voice ${voiceID} not found in voice-list. Use pick-voice tool to pick an available voice. 若用户坚持要使用该音色,需跳过一致性检查。`,
|
|
2186
|
-
// 'generate-scene-tts'
|
|
2187
|
-
// );
|
|
2188
|
-
// }
|
|
2189
|
-
// const storyBoardPath = resolve(
|
|
2190
|
-
// process.env.ZEROCUT_PROJECT_CWD || process.cwd(),
|
|
2191
|
-
// projectLocalDir,
|
|
2192
|
-
// storyBoardFile
|
|
2193
|
-
// );
|
|
2194
|
-
// if (existsSync(storyBoardPath)) {
|
|
2195
|
-
// const storyBoardContent = await readFile(storyBoardPath, 'utf8');
|
|
2196
|
-
// // 检查 storyBoard JSON 语法合法性
|
|
2197
|
-
// let storyBoard;
|
|
2198
|
-
// try {
|
|
2199
|
-
// storyBoard = JSON.parse(storyBoardContent);
|
|
2200
|
-
// } catch (jsonError) {
|
|
2201
|
-
// return createErrorResponse(
|
|
2202
|
-
// `storyBoard 文件 ${storyBoardFile} 存在 JSON 语法错误,请修复后重试。错误详情: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
|
2203
|
-
// 'generate-scene-tts'
|
|
2204
|
-
// );
|
|
2205
|
-
// }
|
|
2206
|
-
// if (storyBoard.scenes && Array.isArray(storyBoard.scenes)) {
|
|
2207
|
-
// scene = storyBoard.scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2208
|
-
// if (scene) {
|
|
2209
|
-
// const script = scene.script;
|
|
2210
|
-
// let isValidText = false;
|
|
2211
|
-
// // 检查 text 是否严格等于 script
|
|
2212
|
-
// if (script && text === script) {
|
|
2213
|
-
// isValidText = true;
|
|
2214
|
-
// }
|
|
2215
|
-
// // 检查 text 是否严格等于 dialog 数组中某个元素的 script
|
|
2216
|
-
// if (
|
|
2217
|
-
// !isValidText &&
|
|
2218
|
-
// scene.dialog &&
|
|
2219
|
-
// Array.isArray(scene.dialog)
|
|
2220
|
-
// ) {
|
|
2221
|
-
// for (const dialogItem of scene.dialog) {
|
|
2222
|
-
// if (dialogItem.script && text === dialogItem.script) {
|
|
2223
|
-
// isValidText = true;
|
|
2224
|
-
// break;
|
|
2225
|
-
// }
|
|
2226
|
-
// }
|
|
2227
|
-
// }
|
|
2228
|
-
// if (!isValidText) {
|
|
2229
|
-
// return createErrorResponse(
|
|
2230
|
-
// '配音文本必须严格遵照storyboard的设定,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用',
|
|
2231
|
-
// 'generate-scene-tts'
|
|
2232
|
-
// );
|
|
2233
|
-
// }
|
|
2234
|
-
// } else {
|
|
2235
|
-
// console.warn(
|
|
2236
|
-
// `Scene index ${sceneIndex} not found in storyboard.json`
|
|
2237
|
-
// );
|
|
2238
|
-
// }
|
|
2239
|
-
// }
|
|
2240
|
-
// } else {
|
|
2241
|
-
// console.warn(`Story board file not found: ${storyBoardPath}`);
|
|
2242
|
-
// }
|
|
2243
|
-
// } catch (error) {
|
|
2244
|
-
// console.error('Failed to validate text with story board:', error);
|
|
2245
|
-
// // 如果读取或解析 storyboard.json 失败,继续执行但记录警告
|
|
2246
|
-
// }
|
|
2247
|
-
// }
|
|
2248
|
-
// console.log(
|
|
2249
|
-
// `Generating TTS with voice: ${voiceID}, speed: ${finalSpeed}, text: ${text.substring(0, 100)}...`
|
|
2250
|
-
// );
|
|
2251
|
-
// if (voiceID.startsWith('BV0')) {
|
|
2252
|
-
// throw new Error(
|
|
2253
|
-
// `BV0* 系列音色已弃用,你必须通过 pick-voice 工具挑选一个真实存在的音色。`
|
|
2254
|
-
// );
|
|
2255
|
-
// }
|
|
2256
|
-
// const type =
|
|
2257
|
-
// voiceID.startsWith('zh_') ||
|
|
2258
|
-
// voiceID.startsWith('en_') ||
|
|
2259
|
-
// voiceID.startsWith('multi_') ||
|
|
2260
|
-
// voiceID.startsWith('saturn_') ||
|
|
2261
|
-
// voiceID.startsWith('ICL_')
|
|
2262
|
-
// ? 'volcano'
|
|
2263
|
-
// : 'minimax';
|
|
2264
|
-
// let res;
|
|
2265
|
-
// let emotion = 'auto';
|
|
2266
|
-
// if (type === 'volcano') {
|
|
2267
|
-
// volume = Math.max(Math.min(volume, 2.0), 0.5);
|
|
2268
|
-
// res = await ai.textToSpeechVolc({
|
|
2269
|
-
// text: text.trim(),
|
|
2270
|
-
// speaker: voiceID,
|
|
2271
|
-
// speed: Math.floor(100 * (finalSpeed - 1)),
|
|
2272
|
-
// volume: Math.floor(100 * (volume - 1)),
|
|
2273
|
-
// context_texts,
|
|
2274
|
-
// explicit_language,
|
|
2275
|
-
// voice_to_caption:
|
|
2276
|
-
// explicit_language === 'zh' || explicit_language === 'en',
|
|
2277
|
-
// });
|
|
2278
|
-
// } else {
|
|
2279
|
-
// emotion = 'neutral';
|
|
2280
|
-
// if (context_texts.length > 0) {
|
|
2281
|
-
// const prompt = `根据用户输入语音内容和上下文内容,从文字判断语音合理的情感,然后选择以下情感**之一**返回结果:
|
|
2282
|
-
// "happy", "sad", "angry", "fearful", "disgusted", "surprised", "calm", "fluent", "whisper", "neutral"
|
|
2283
|
-
// ## 要求
|
|
2284
|
-
// 输出 JSON 格式,包含一个 emotion 字段,值为以上情感之一。
|
|
2285
|
-
// `;
|
|
2286
|
-
// const schema = {
|
|
2287
|
-
// name: 'emotion_schema',
|
|
2288
|
-
// schema: {
|
|
2289
|
-
// type: 'object',
|
|
2290
|
-
// properties: {
|
|
2291
|
-
// emotion: {
|
|
2292
|
-
// type: 'string',
|
|
2293
|
-
// enum: [
|
|
2294
|
-
// 'neutral',
|
|
2295
|
-
// 'happy',
|
|
2296
|
-
// 'sad',
|
|
2297
|
-
// 'angry',
|
|
2298
|
-
// 'fearful',
|
|
2299
|
-
// 'disgusted',
|
|
2300
|
-
// 'surprised',
|
|
2301
|
-
// 'calm',
|
|
2302
|
-
// 'fluent',
|
|
2303
|
-
// 'whisper',
|
|
2304
|
-
// ],
|
|
2305
|
-
// description: '用户输入语音的情感',
|
|
2306
|
-
// },
|
|
2307
|
-
// },
|
|
2308
|
-
// required: ['emotion'],
|
|
2309
|
-
// },
|
|
2310
|
-
// };
|
|
2311
|
-
// const payload: any = {
|
|
2312
|
-
// model: 'Doubao-Seed-1.6',
|
|
2313
|
-
// messages: [
|
|
2314
|
-
// {
|
|
2315
|
-
// role: 'system',
|
|
2316
|
-
// content: prompt,
|
|
2317
|
-
// },
|
|
2318
|
-
// {
|
|
2319
|
-
// role: 'user',
|
|
2320
|
-
// content: `## 语音内容:
|
|
2321
|
-
// ${text.trim()}
|
|
2322
|
-
// ## 语音上下文
|
|
2323
|
-
// ${context_texts.join('\n')}
|
|
2324
|
-
// `,
|
|
2325
|
-
// },
|
|
2326
|
-
// ],
|
|
2327
|
-
// response_format: {
|
|
2328
|
-
// type: 'json_schema',
|
|
2329
|
-
// json_schema: schema,
|
|
2330
|
-
// },
|
|
2331
|
-
// };
|
|
2332
|
-
// const completion = await ai.getCompletions(payload);
|
|
2333
|
-
// const emotionObj = JSON.parse(
|
|
2334
|
-
// completion.choices[0]?.message?.content ?? '{}'
|
|
2335
|
-
// );
|
|
2336
|
-
// emotion = emotionObj.emotion ?? 'neutral';
|
|
2337
|
-
// }
|
|
2338
|
-
// res = await ai.textToSpeech({
|
|
2339
|
-
// text: text.trim(),
|
|
2340
|
-
// voiceName: voiceID,
|
|
2341
|
-
// speed: finalSpeed,
|
|
2342
|
-
// pitch,
|
|
2343
|
-
// volume,
|
|
2344
|
-
// emotion,
|
|
2345
|
-
// voice_to_caption:
|
|
2346
|
-
// explicit_language === 'zh' || explicit_language === 'en',
|
|
2347
|
-
// });
|
|
2348
|
-
// }
|
|
2349
|
-
// if (!res) {
|
|
2350
|
-
// throw new Error('Failed to generate TTS: no response from AI service');
|
|
2351
|
-
// }
|
|
2352
|
-
// if (res.url) {
|
|
2353
|
-
// console.log('TTS generated successfully, saving to materials...');
|
|
2354
|
-
// const { url, duration, ...opts } = res;
|
|
2355
|
-
// if (!skipConsistencyCheck && duration > 16) {
|
|
2356
|
-
// return createErrorResponse(
|
|
2357
|
-
// 'TTS duration exceeds 16 seconds, 建议调整文本长度、提升语速或拆分场景...,⚠️如简化文本内容或拆分文本,需要立即更新 storyboard 以保持内容同步!如仍要生成,可设置 skipConsistencyCheck 为 true,跳过一致性检查。',
|
|
2358
|
-
// 'generate-scene-tts'
|
|
2359
|
-
// );
|
|
2360
|
-
// }
|
|
2361
|
-
// if (!duration) {
|
|
2362
|
-
// return createErrorResponse(
|
|
2363
|
-
// 'TTS duration not returned from AI service',
|
|
2364
|
-
// 'generate-scene-tts'
|
|
2365
|
-
// );
|
|
2366
|
-
// }
|
|
2367
|
-
// const uri = await saveMaterial(currentSession, url, validatedFileName);
|
|
2368
|
-
// let warn = '';
|
|
2369
|
-
// if (scene) {
|
|
2370
|
-
// const minDur = Math.ceil(duration);
|
|
2371
|
-
// if (scene.audio_mode === 'vo_sync' && scene.duration !== minDur) {
|
|
2372
|
-
// warn = `场景${sceneIndex}设定的时长${scene.duration}秒与实际生成的语音时长${minDur}秒不一致,音画同步将有问题,建议修改场景时长为${minDur}秒`;
|
|
2373
|
-
// } else if (scene.duration < minDur) {
|
|
2374
|
-
// warn = `场景${sceneIndex}设定的时长${scene.duration}秒小于实际生成的语音时长${duration}秒,可能会导致场景结束时音频未播放完成,建议修改场景时长为${minDur}秒`;
|
|
2375
|
-
// }
|
|
2376
|
-
// }
|
|
2377
|
-
// const result = {
|
|
2378
|
-
// success: true,
|
|
2379
|
-
// warn,
|
|
2380
|
-
// source: url, // 方便调试
|
|
2381
|
-
// uri,
|
|
2382
|
-
// durationMs: Math.floor((duration || 0) * 1000),
|
|
2383
|
-
// text,
|
|
2384
|
-
// emotion,
|
|
2385
|
-
// context_texts,
|
|
2386
|
-
// voiceName: voiceID,
|
|
2387
|
-
// speed: finalSpeed,
|
|
2388
|
-
// timestamp: new Date().toISOString(),
|
|
2389
|
-
// ...opts,
|
|
2390
|
-
// };
|
|
2391
|
-
// // Update media_logs.json
|
|
2392
|
-
// try {
|
|
2393
|
-
// await updateMediaLogs(
|
|
2394
|
-
// currentSession,
|
|
2395
|
-
// validatedFileName,
|
|
2396
|
-
// result,
|
|
2397
|
-
// 'audio'
|
|
2398
|
-
// );
|
|
2399
|
-
// } catch (error) {
|
|
2400
|
-
// console.warn(
|
|
2401
|
-
// `Failed to update media_logs.json for ${validatedFileName}:`,
|
|
2402
|
-
// error
|
|
2403
|
-
// );
|
|
2404
|
-
// }
|
|
2405
|
-
// return {
|
|
2406
|
-
// content: [
|
|
2407
|
-
// {
|
|
2408
|
-
// type: 'text' as const,
|
|
2409
|
-
// text: JSON.stringify(result),
|
|
2410
|
-
// },
|
|
2411
|
-
// ],
|
|
2412
|
-
// };
|
|
2413
|
-
// } else {
|
|
2414
|
-
// console.warn('TTS generation completed but no URL returned');
|
|
2415
|
-
// return {
|
|
2416
|
-
// content: [
|
|
2417
|
-
// {
|
|
2418
|
-
// type: 'text' as const,
|
|
2419
|
-
// text: JSON.stringify({
|
|
2420
|
-
// success: false,
|
|
2421
|
-
// error:
|
|
2422
|
-
// 'No TTS URL returned from AI service. You should use pick-voice tool to pick an available voice.',
|
|
2423
|
-
// response: res,
|
|
2424
|
-
// timestamp: new Date().toISOString(),
|
|
2425
|
-
// }),
|
|
2426
|
-
// },
|
|
2427
|
-
// ],
|
|
2428
|
-
// };
|
|
2429
|
-
// }
|
|
2430
|
-
// } catch (error) {
|
|
2431
|
-
// return createErrorResponse(error, 'generate-scene-tts');
|
|
2432
|
-
// }
|
|
2433
|
-
// }
|
|
2434
|
-
// );
|
|
2435
|
-
// server.registerTool(
|
|
2436
|
-
// 'compile-and-run',
|
|
2437
|
-
// {
|
|
2438
|
-
// title: 'Compile And Run',
|
|
2439
|
-
// description: 'Compile project to ffmpeg command and run it.',
|
|
2440
|
-
// inputSchema: {
|
|
2441
|
-
// projectFileName: z
|
|
2442
|
-
// .string()
|
|
2443
|
-
// .describe('The VideoProject configuration object.'),
|
|
2444
|
-
// outputFileName: z
|
|
2445
|
-
// .string()
|
|
2446
|
-
// .optional()
|
|
2447
|
-
// .describe('Output video filename (optional, defaults to output.mp4).'),
|
|
2448
|
-
// },
|
|
2449
|
-
// },
|
|
2450
|
-
// async ({ projectFileName, outputFileName }) => {
|
|
2451
|
-
// try {
|
|
2452
|
-
// // 验证session状态
|
|
2453
|
-
// const currentSession = await validateSession('compile-and-run');
|
|
2454
|
-
// // 检查字幕内容匹配标记
|
|
2455
|
-
// if (!checkStoryboardSubtitlesFlag) {
|
|
2456
|
-
// checkStoryboardSubtitlesFlag = true;
|
|
2457
|
-
// return createErrorResponse(
|
|
2458
|
-
// `请先对 draft_content 进行以下一致性检查:
|
|
2459
|
-
// 1. 检查字幕文字内容是否与 storyboard 中各个场景的 script 或 dialog 内容完全一致(⚠️ 允许字幕分段展示,只要最终文本保持一致就行)
|
|
2460
|
-
// 2. 检查视频 resolution 设定是否与 storyboard 的 orientation 设置一致,默认 720p 情况下视频尺寸应为横屏 1280x720,竖屏 720x1280,若视频为 1080p 则尺寸应分别为横屏 1920x1080 和竖屏 1080x1920,切勿设反
|
|
2461
|
-
// 3. 除非用户明确表示不要背景音乐,否则应检查是否有生成并配置了 BGM,若无,则生成 BGM 并将其加入素材和轨道配置
|
|
2462
|
-
// 以上检查任何一项有问题,先修复 draft_content 使其符合要求后再进行合成`,
|
|
2463
|
-
// 'compile-and-run'
|
|
2464
|
-
// );
|
|
2465
|
-
// }
|
|
2466
|
-
// console.log('Starting video compilation and rendering...');
|
|
2467
|
-
// // 验证terminal可用性
|
|
2468
|
-
// const terminal = currentSession.terminal;
|
|
2469
|
-
// if (!terminal) {
|
|
2470
|
-
// throw new Error('Terminal not available in current session');
|
|
2471
|
-
// }
|
|
2472
|
-
// const localProjectFile = resolve(
|
|
2473
|
-
// projectLocalDir,
|
|
2474
|
-
// basename(projectFileName)
|
|
2475
|
-
// );
|
|
2476
|
-
// const project = JSON.parse(await readFile(localProjectFile, 'utf-8'));
|
|
2477
|
-
// // 验证输出文件名安全性
|
|
2478
|
-
// const outFile = outputFileName || project.export.outFile || 'output.mp4';
|
|
2479
|
-
// const validatedFileName = validateFileName(outFile);
|
|
2480
|
-
// console.log(`Output file: ${validatedFileName}`);
|
|
2481
|
-
// // 构建工作目录路径
|
|
2482
|
-
// const workDir = `/home/user/cerevox-zerocut/projects/${terminal.id}`;
|
|
2483
|
-
// const outputDir = `${workDir}/output`;
|
|
2484
|
-
// const outputPath = `${outputDir}/${validatedFileName}`;
|
|
2485
|
-
// // Project已经通过zVideoProject schema验证
|
|
2486
|
-
// const validated = { ...project };
|
|
2487
|
-
// // 更新导出配置
|
|
2488
|
-
// validated.export = {
|
|
2489
|
-
// ...validated.export,
|
|
2490
|
-
// outFile: outputPath,
|
|
2491
|
-
// };
|
|
2492
|
-
// console.log('Compiling VideoProject to FFmpeg command...');
|
|
2493
|
-
// // 编译为FFmpeg命令
|
|
2494
|
-
// let compiled: CompileResult;
|
|
2495
|
-
// try {
|
|
2496
|
-
// compiled = await compileToFfmpeg(validated, {
|
|
2497
|
-
// workingDir: outputDir,
|
|
2498
|
-
// subtitleStrategy: 'ass',
|
|
2499
|
-
// subtitlesFileName: `${outFile.replace(/\.mp4$/, '')}.subtitles.ass`,
|
|
2500
|
-
// });
|
|
2501
|
-
// } catch (compileError) {
|
|
2502
|
-
// console.error('Failed to compile VideoProject:', compileError);
|
|
2503
|
-
// throw new Error(`Failed to compile VideoProject: ${compileError}`);
|
|
2504
|
-
// }
|
|
2505
|
-
// console.log(`FFmpeg command generated (${compiled.cmd.length} chars)`);
|
|
2506
|
-
// console.log('FFmpeg Command:', compiled.cmd.substring(0, 200) + '...');
|
|
2507
|
-
// // 执行FFmpeg命令
|
|
2508
|
-
// console.log('Executing FFmpeg command...');
|
|
2509
|
-
// const result = await runFfmpeg(currentSession, compiled);
|
|
2510
|
-
// if (result.exitCode === 0) {
|
|
2511
|
-
// console.log('Video compilation completed successfully');
|
|
2512
|
-
// // 自动下载输出文件
|
|
2513
|
-
// console.log('Starting automatic download of output files...');
|
|
2514
|
-
// let downloadResult = null;
|
|
2515
|
-
// try {
|
|
2516
|
-
// const workDir = `/home/user/cerevox-zerocut/projects/${terminal.id}/output`;
|
|
2517
|
-
// let outputs: string[] = [];
|
|
2518
|
-
// try {
|
|
2519
|
-
// outputs = (await currentSession.files.listFiles(workDir)) || [];
|
|
2520
|
-
// } catch (listError) {
|
|
2521
|
-
// console.warn('Failed to list output files:', listError);
|
|
2522
|
-
// outputs = [];
|
|
2523
|
-
// }
|
|
2524
|
-
// if (outputs.length > 0) {
|
|
2525
|
-
// const outputDir = resolve(
|
|
2526
|
-
// process.env.ZEROCUT_PROJECT_CWD || process.cwd(),
|
|
2527
|
-
// projectLocalDir,
|
|
2528
|
-
// 'output'
|
|
2529
|
-
// );
|
|
2530
|
-
// await mkdir(outputDir, { recursive: true });
|
|
2531
|
-
// const downloadErrors: string[] = [];
|
|
2532
|
-
// const successfulDownloads: string[] = [];
|
|
2533
|
-
// const promises = outputs.map(async output => {
|
|
2534
|
-
// try {
|
|
2535
|
-
// await currentSession.files.download(
|
|
2536
|
-
// `${workDir}/${output}`,
|
|
2537
|
-
// `${outputDir}/${output}`
|
|
2538
|
-
// );
|
|
2539
|
-
// successfulDownloads.push(output);
|
|
2540
|
-
// return output;
|
|
2541
|
-
// } catch (downloadError) {
|
|
2542
|
-
// const errorMsg = `Failed to download ${output}: ${downloadError}`;
|
|
2543
|
-
// console.error(errorMsg);
|
|
2544
|
-
// downloadErrors.push(errorMsg);
|
|
2545
|
-
// return null;
|
|
2546
|
-
// }
|
|
2547
|
-
// });
|
|
2548
|
-
// const results = await Promise.all(promises);
|
|
2549
|
-
// const sources = results.filter(
|
|
2550
|
-
// output => output !== null
|
|
2551
|
-
// ) as string[];
|
|
2552
|
-
// downloadResult = {
|
|
2553
|
-
// totalFiles: outputs.length,
|
|
2554
|
-
// successfulDownloads: sources.length,
|
|
2555
|
-
// failedDownloads: downloadErrors.length,
|
|
2556
|
-
// downloadErrors:
|
|
2557
|
-
// downloadErrors.length > 0 ? downloadErrors : undefined,
|
|
2558
|
-
// downloadPath: outputDir,
|
|
2559
|
-
// sources,
|
|
2560
|
-
// };
|
|
2561
|
-
// console.log(
|
|
2562
|
-
// `Download completed: ${sources.length}/${outputs.length} files successful`
|
|
2563
|
-
// );
|
|
2564
|
-
// } else {
|
|
2565
|
-
// console.log('No output files found to download');
|
|
2566
|
-
// downloadResult = {
|
|
2567
|
-
// totalFiles: 0,
|
|
2568
|
-
// successfulDownloads: 0,
|
|
2569
|
-
// failedDownloads: 0,
|
|
2570
|
-
// message: 'No output files found to download',
|
|
2571
|
-
// };
|
|
2572
|
-
// }
|
|
2573
|
-
// } catch (downloadError) {
|
|
2574
|
-
// console.error('Download process failed:', downloadError);
|
|
2575
|
-
// downloadResult = {
|
|
2576
|
-
// error: `Download failed: ${downloadError}`,
|
|
2577
|
-
// totalFiles: 0,
|
|
2578
|
-
// successfulDownloads: 0,
|
|
2579
|
-
// failedDownloads: 1,
|
|
2580
|
-
// };
|
|
2581
|
-
// }
|
|
2582
|
-
// const successResult = {
|
|
2583
|
-
// success: true,
|
|
2584
|
-
// outputPath,
|
|
2585
|
-
// outputFileName: validatedFileName,
|
|
2586
|
-
// command: compiled.cmd,
|
|
2587
|
-
// message: 'Video compilation and download completed successfully',
|
|
2588
|
-
// download: downloadResult,
|
|
2589
|
-
// timestamp: new Date().toISOString(),
|
|
2590
|
-
// };
|
|
2591
|
-
// return {
|
|
2592
|
-
// content: [
|
|
2593
|
-
// {
|
|
2594
|
-
// type: 'text' as const,
|
|
2595
|
-
// text: JSON.stringify(successResult),
|
|
2596
|
-
// },
|
|
2597
|
-
// ],
|
|
2598
|
-
// };
|
|
2599
|
-
// } else {
|
|
2600
|
-
// console.error(`FFmpeg failed with exit code: ${result.exitCode}`);
|
|
2601
|
-
// const failureResult = {
|
|
2602
|
-
// success: false,
|
|
2603
|
-
// exitCode: result.exitCode,
|
|
2604
|
-
// outputPath,
|
|
2605
|
-
// // command: compiled.cmd,
|
|
2606
|
-
// stderr: result.stderr,
|
|
2607
|
-
// message: `FFmpeg exited with code ${result.exitCode}`,
|
|
2608
|
-
// timestamp: new Date().toISOString(),
|
|
2609
|
-
// };
|
|
2610
|
-
// if (result.exitCode === 254) {
|
|
2611
|
-
// failureResult.message =
|
|
2612
|
-
// 'FFmpeg failed with code 254. Close current session immediately (inMinutes = 0) and re-open a new session to try again.';
|
|
2613
|
-
// }
|
|
2614
|
-
// return {
|
|
2615
|
-
// content: [
|
|
2616
|
-
// {
|
|
2617
|
-
// type: 'text' as const,
|
|
2618
|
-
// text: JSON.stringify(failureResult),
|
|
2619
|
-
// },
|
|
2620
|
-
// ],
|
|
2621
|
-
// };
|
|
2622
|
-
// }
|
|
2623
|
-
// } catch (error) {
|
|
2624
|
-
// return createErrorResponse(error, 'compile-and-run');
|
|
2625
|
-
// }
|
|
2626
|
-
// }
|
|
2627
|
-
// );
|
|
2628
|
-
// server.registerTool(
|
|
2629
|
-
// 'get-schema',
|
|
2630
|
-
// {
|
|
2631
|
-
// title: 'Get Storyboard Schema or Draft Content Schema',
|
|
2632
|
-
// description:
|
|
2633
|
-
// 'Get the complete Storyboard or Draft Content JSON Schema definition. Use this schema to validate storyboard.json or draft_content.json files.',
|
|
2634
|
-
// inputSchema: {
|
|
2635
|
-
// type: z
|
|
2636
|
-
// .enum(['storyboard', 'draft_content'])
|
|
2637
|
-
// .describe(
|
|
2638
|
-
// 'The type of schema to retrieve. Must be either "storyboard" or "draft_content". 用 type: storyboard 的 schema 生成 storyboard.json;用 type: draft_content 的 schema 生成 draft_content.json'
|
|
2639
|
-
// ),
|
|
2640
|
-
// },
|
|
2641
|
-
// },
|
|
2642
|
-
// async ({ type }) => {
|
|
2643
|
-
// try {
|
|
2644
|
-
// const schemaPath = resolve(__dirname, `./prompts/${type}-schema.json`);
|
|
2645
|
-
// const schemaContent = await readFile(schemaPath, 'utf-8');
|
|
2646
|
-
// const schema = JSON.parse(schemaContent);
|
|
2647
|
-
// let important_guidelines = '';
|
|
2648
|
-
// if (type === 'draft_content') {
|
|
2649
|
-
// important_guidelines = `⚠️ 生成文件时请严格遵守输出规范,字幕文本内容必须与 storyboard.json 中的 script(或dialog) 字段的文本内容完全一致。
|
|
2650
|
-
// ** 字幕优化 **
|
|
2651
|
-
// * 在保证字幕文本内容与 storyboard.json 中的 script(或dialog) 字段的文本内容完全一致的前提下,可根据 tts 返回的 \`captions.utterances\` 字段对字幕的显示进行优化,将过长的字幕分段显示,在 draft_content.json 中使用分段字幕,captions 的内容在 media_logs.json 中可查询到。
|
|
2652
|
-
// * 如用户未特殊指定,字幕样式(字体及大小)务必遵守输出规范
|
|
2653
|
-
// `;
|
|
2654
|
-
// }
|
|
2655
|
-
// return {
|
|
2656
|
-
// content: [
|
|
2657
|
-
// {
|
|
2658
|
-
// type: 'text' as const,
|
|
2659
|
-
// text: JSON.stringify({
|
|
2660
|
-
// success: true,
|
|
2661
|
-
// schema,
|
|
2662
|
-
// important_guidelines,
|
|
2663
|
-
// timestamp: new Date().toISOString(),
|
|
2664
|
-
// }),
|
|
2665
|
-
// },
|
|
2666
|
-
// ],
|
|
2667
|
-
// };
|
|
2668
|
-
// } catch (error) {
|
|
2669
|
-
// return createErrorResponse(error, 'get-schema');
|
|
2670
|
-
// }
|
|
2671
|
-
// }
|
|
2672
|
-
// );
|
|
2673
|
-
// server.registerTool(
|
|
2674
|
-
// 'pick-voice',
|
|
2675
|
-
// {
|
|
2676
|
-
// title: 'Pick Voice',
|
|
2677
|
-
// description:
|
|
2678
|
-
// '根据用户需求,选择尽可能符合要求的语音,在合适的情况下,优先采用 volcano_tts_2 类型的语音',
|
|
2679
|
-
// inputSchema: {
|
|
2680
|
-
// prompt: z
|
|
2681
|
-
// .string()
|
|
2682
|
-
// .describe('用户需求描述,例如:一个有亲和力的,适合给孩子讲故事的语音'),
|
|
2683
|
-
// custom_design: z
|
|
2684
|
-
// .boolean()
|
|
2685
|
-
// .optional()
|
|
2686
|
-
// .describe(
|
|
2687
|
-
// '是否自定义语音,由于要消耗较多积分,因此**只有用户明确要求自己设计语音**,才将该参数设为true'
|
|
2688
|
-
// ),
|
|
2689
|
-
// custom_design_preview: z
|
|
2690
|
-
// .string()
|
|
2691
|
-
// .optional()
|
|
2692
|
-
// .describe(
|
|
2693
|
-
// '用户自定义语音的预览文本,用于展示自定义语音的效果,只有 custom_design 为 true 时才需要'
|
|
2694
|
-
// ),
|
|
2695
|
-
// custom_design_save_to: z
|
|
2696
|
-
// .string()
|
|
2697
|
-
// .optional()
|
|
2698
|
-
// .describe(
|
|
2699
|
-
// '自定义语音的保存路径,例如:custom_voice.mp3 custom_voice_{id}.mp3'
|
|
2700
|
-
// ),
|
|
2701
|
-
// },
|
|
2702
|
-
// },
|
|
2703
|
-
// async ({
|
|
2704
|
-
// prompt,
|
|
2705
|
-
// custom_design,
|
|
2706
|
-
// custom_design_preview,
|
|
2707
|
-
// custom_design_save_to,
|
|
2708
|
-
// }) => {
|
|
2709
|
-
// try {
|
|
2710
|
-
// // 验证session状态
|
|
2711
|
-
// const currentSession = await validateSession('pick-voice');
|
|
2712
|
-
// const ai = currentSession.ai;
|
|
2713
|
-
// if (custom_design) {
|
|
2714
|
-
// if (!custom_design_preview) {
|
|
2715
|
-
// throw new Error(
|
|
2716
|
-
// 'custom_design_preview is required when custom_design is true'
|
|
2717
|
-
// );
|
|
2718
|
-
// }
|
|
2719
|
-
// const data = await currentSession.ai.voiceDesign({
|
|
2720
|
-
// prompt,
|
|
2721
|
-
// previewText: custom_design_preview,
|
|
2722
|
-
// });
|
|
2723
|
-
// if (data.voice_id) {
|
|
2724
|
-
// const trial_audio = data.trial_audio;
|
|
2725
|
-
// let uri = '';
|
|
2726
|
-
// if (trial_audio) {
|
|
2727
|
-
// uri = await saveMaterial(
|
|
2728
|
-
// currentSession,
|
|
2729
|
-
// trial_audio,
|
|
2730
|
-
// custom_design_save_to || `custom_voice_${data.voice_id}.mp3`
|
|
2731
|
-
// );
|
|
2732
|
-
// }
|
|
2733
|
-
// return {
|
|
2734
|
-
// content: [
|
|
2735
|
-
// {
|
|
2736
|
-
// type: 'text' as const,
|
|
2737
|
-
// text: JSON.stringify({
|
|
2738
|
-
// success: true,
|
|
2739
|
-
// ...data,
|
|
2740
|
-
// uri,
|
|
2741
|
-
// timestamp: new Date().toISOString(),
|
|
2742
|
-
// }),
|
|
2743
|
-
// },
|
|
2744
|
-
// ],
|
|
2745
|
-
// };
|
|
2746
|
-
// } else {
|
|
2747
|
-
// throw new Error(`Voice design failed, ${JSON.stringify(data)}`);
|
|
2748
|
-
// }
|
|
2749
|
-
// }
|
|
2750
|
-
// const data = await ai.pickVoice({ prompt });
|
|
2751
|
-
// return {
|
|
2752
|
-
// content: [
|
|
2753
|
-
// {
|
|
2754
|
-
// type: 'text' as const,
|
|
2755
|
-
// text: JSON.stringify({
|
|
2756
|
-
// success: true,
|
|
2757
|
-
// ...data,
|
|
2758
|
-
// timestamp: new Date().toISOString(),
|
|
2759
|
-
// }),
|
|
2760
|
-
// },
|
|
2761
|
-
// ],
|
|
2762
|
-
// };
|
|
2763
|
-
// } catch (error) {
|
|
2764
|
-
// return createErrorResponse(error, 'pick-voice');
|
|
2765
|
-
// }
|
|
2766
|
-
// }
|
|
2767
|
-
// );
|
|
2768
1955
|
let lastEffect = '';
|
|
2769
1956
|
server.registerTool('generate-video', {
|
|
2770
1957
|
title: 'Generate Video',
|
|
@@ -2772,12 +1959,12 @@ server.registerTool('generate-video', {
|
|
|
2772
1959
|
inputSchema: {
|
|
2773
1960
|
prompt: zod_1.z
|
|
2774
1961
|
.string()
|
|
2775
|
-
.describe('The prompt to generate. 一般要严格对应 storyboard
|
|
1962
|
+
.describe('The prompt to generate. 一般要严格对应 storyboard 中当前分镜的 video_prompt 字段描述;传这个参数时,若跳过了一致性检查,记得保留镜头切换语言,如“切镜至第二镜头”这样的指令不应当省略。'),
|
|
2776
1963
|
sceneIndex: zod_1.z
|
|
2777
1964
|
.number()
|
|
2778
1965
|
.min(1)
|
|
2779
1966
|
.optional()
|
|
2780
|
-
.describe('
|
|
1967
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
2781
1968
|
storyBoardFile: zod_1.z
|
|
2782
1969
|
.string()
|
|
2783
1970
|
.optional()
|
|
@@ -2873,7 +2060,7 @@ server.registerTool('generate-video', {
|
|
|
2873
2060
|
console.warn(`zero 模型的视频仅支持 1080p 分辨率,用户指定的分辨率为 %s,已自动将 ${resolution} 转换为 1080p`, resolution);
|
|
2874
2061
|
resolution = '1080p';
|
|
2875
2062
|
}
|
|
2876
|
-
// 校验 prompt 与 storyboard.json
|
|
2063
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性
|
|
2877
2064
|
if (sceneIndex && !skipConsistencyCheck) {
|
|
2878
2065
|
try {
|
|
2879
2066
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
@@ -2895,7 +2082,7 @@ server.registerTool('generate-video', {
|
|
|
2895
2082
|
return createErrorResponse('视频提示词必须严格遵照storyboard的设定,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用', 'generate-video');
|
|
2896
2083
|
}
|
|
2897
2084
|
if (scene.is_continuous && !end_frame) {
|
|
2898
|
-
return createErrorResponse('
|
|
2085
|
+
return createErrorResponse('连续分镜必须指定end_frame参数,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用', 'generate-video');
|
|
2899
2086
|
}
|
|
2900
2087
|
if (scene.video_duration != null &&
|
|
2901
2088
|
duration !== scene.video_duration) {
|
|
@@ -2904,14 +2091,14 @@ server.registerTool('generate-video', {
|
|
|
2904
2091
|
if (storyBoard.voice_type &&
|
|
2905
2092
|
storyBoard.voice_type !== 'slient') {
|
|
2906
2093
|
if (mute) {
|
|
2907
|
-
return createErrorResponse('
|
|
2094
|
+
return createErrorResponse('有对话和旁白的分镜不能静音,请将mute设为false再重新使用工具。如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用', 'generate-video');
|
|
2908
2095
|
}
|
|
2909
2096
|
}
|
|
2910
2097
|
// 检查 use_video_model 与 type 参数的一致性
|
|
2911
2098
|
if (scene.use_video_model &&
|
|
2912
2099
|
type &&
|
|
2913
2100
|
scene.use_video_model !== type) {
|
|
2914
|
-
return createErrorResponse(
|
|
2101
|
+
return createErrorResponse(`分镜建议的视频模型(${scene.use_video_model})与传入的type参数(${type})不一致。请确保use_video_model与type参数值相同,或将skipConsistencyCheck设置为true后再次调用`, 'generate-video');
|
|
2915
2102
|
}
|
|
2916
2103
|
}
|
|
2917
2104
|
else {
|
|
@@ -2927,60 +2114,6 @@ server.registerTool('generate-video', {
|
|
|
2927
2114
|
console.error('Failed to validate prompt with story board:', error);
|
|
2928
2115
|
// 如果读取或解析 storyboard.json 失败,继续执行但记录警告
|
|
2929
2116
|
}
|
|
2930
|
-
// 校验视频时长与 timeline_analysis.json 中 proposed_video_scenes 的匹配
|
|
2931
|
-
try {
|
|
2932
|
-
const timelineAnalysisPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'timeline_analysis.json');
|
|
2933
|
-
if ((0, node_fs_1.existsSync)(timelineAnalysisPath)) {
|
|
2934
|
-
const timelineAnalysisContent = await (0, promises_1.readFile)(timelineAnalysisPath, 'utf8');
|
|
2935
|
-
const timelineAnalysis = JSON.parse(timelineAnalysisContent);
|
|
2936
|
-
if (timelineAnalysis.proposed_video_scenes &&
|
|
2937
|
-
Array.isArray(timelineAnalysis.proposed_video_scenes)) {
|
|
2938
|
-
const videoScene = timelineAnalysis.proposed_video_scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2939
|
-
if (videoScene && videoScene.video_duration_s) {
|
|
2940
|
-
const expectedDuration = videoScene.video_duration_s;
|
|
2941
|
-
if (duration !== expectedDuration) {
|
|
2942
|
-
return createErrorResponse(`视频时长必须与timeline_analysis中的设定匹配。当前场景${videoScene.scene_id}要求时长为${expectedDuration}秒,但传入的duration为${duration}秒。请调整duration参数为${expectedDuration}秒后重试。如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用。`, 'generate-video');
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
else {
|
|
2946
|
-
console.warn(`Scene ${sceneIndex} (scene_${sceneIndex.toString().padStart(2, '0')}) not found in timeline_analysis.json proposed_video_scenes`);
|
|
2947
|
-
}
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
else {
|
|
2951
|
-
// 检查音频时长标志
|
|
2952
|
-
try {
|
|
2953
|
-
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
2954
|
-
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
2955
|
-
const storyBoardContent = await (0, promises_1.readFile)(storyBoardPath, 'utf8');
|
|
2956
|
-
const storyBoard = JSON.parse(storyBoardContent);
|
|
2957
|
-
if (storyBoard.scenes && Array.isArray(storyBoard.scenes)) {
|
|
2958
|
-
const scene = storyBoard.scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2959
|
-
if (scene &&
|
|
2960
|
-
((scene.script && scene.script.trim() !== '') ||
|
|
2961
|
-
scene.dialog)) {
|
|
2962
|
-
if (!checkAudioVideoDurationFlag) {
|
|
2963
|
-
checkAudioVideoDurationFlag = true;
|
|
2964
|
-
if (scene.audio_mode === 'vo_sync') {
|
|
2965
|
-
return createErrorResponse('请先自我检查 media_logs 中的音频时长,确保 storyboard 中视频时长为音频时长向上取整 即 ceil(音频时长),然后再按照正确的视频时长创建视频', 'generate-video');
|
|
2966
|
-
}
|
|
2967
|
-
else if (scene.audio_mode === 'dialogue') {
|
|
2968
|
-
return createErrorResponse('请先自我检查 media_logs 中的音频时长,确保 storyboard 中视频时长**不小于**音频时长向上取整 即 ceil(音频时长),然后再按照正确的视频时长创建视频', 'generate-video');
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
catch (error) {
|
|
2976
|
-
console.error('Failed to check audio duration flag:', error);
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
catch (error) {
|
|
2981
|
-
console.error('Failed to validate duration with timeline analysis:', error);
|
|
2982
|
-
// 如果读取或解析 timeline_analysis.json 失败,继续执行但记录警告
|
|
2983
|
-
}
|
|
2984
2117
|
}
|
|
2985
2118
|
const validatedFileName = validateFileName(saveToFileName);
|
|
2986
2119
|
console.log(`Generating video with prompt: ${prompt.substring(0, 100)}...`);
|
|
@@ -3702,7 +2835,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3702
2835
|
inputSchema: {
|
|
3703
2836
|
prompt: zod_1.z
|
|
3704
2837
|
.string()
|
|
3705
|
-
.describe('The prompt to generate video with or without reference images. 一般要严格对应 storyboard
|
|
2838
|
+
.describe('The prompt to generate video with or without reference images. 一般要严格对应 storyboard 中当前分镜的 video_prompt 字段描述;传这个参数时,若跳过了一致性检查,记得保留镜头切换语言,如“切镜至第二镜头”这样的指令不应当省略。'),
|
|
3706
2839
|
rewritePrompt: zod_1.z
|
|
3707
2840
|
.boolean()
|
|
3708
2841
|
.optional()
|
|
@@ -3763,7 +2896,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3763
2896
|
.number()
|
|
3764
2897
|
.min(1)
|
|
3765
2898
|
.optional()
|
|
3766
|
-
.describe('
|
|
2899
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
3767
2900
|
storyBoardFile: zod_1.z
|
|
3768
2901
|
.string()
|
|
3769
2902
|
.optional()
|
|
@@ -3795,24 +2928,9 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3795
2928
|
const outlineSheetImagePath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'materials', 'outline_sheet.png');
|
|
3796
2929
|
const hasOutlineSheet = (0, node_fs_1.existsSync)(outlineSheetImagePath);
|
|
3797
2930
|
if (hasOutlineSheet && !skipConsistencyCheck) {
|
|
3798
|
-
return createErrorResponse('
|
|
3799
|
-
}
|
|
3800
|
-
// 检查 storyboard 标志
|
|
3801
|
-
if (!hasOutlineSheet &&
|
|
3802
|
-
!checkStoryboardFlag &&
|
|
3803
|
-
(0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
3804
|
-
checkStoryboardFlag = true;
|
|
3805
|
-
return createErrorResponse(`必须先审查生成的 storyboard.json 内容,按照如下步骤:
|
|
3806
|
-
|
|
3807
|
-
1. 确保每个场景中的stage_atmosphere内容按照规则被正确融合到video_prompt中,不得遗漏
|
|
3808
|
-
2. 如有main_characters设定且包含了reference_image,或有reference_objects,需确保video_prompt描述已包含该场景相关main_characters和所有reference_objects中的物品或背景,并确保参考图具体内容已经在video_prompt中有明确描述,如果没有,可忽略。
|
|
3809
|
-
3. 如有配音,先自我检查 media_logs 中的查音频时长,确保以匹配音频时长来生成视频
|
|
3810
|
-
|
|
3811
|
-
检查完上述问题后先汇报,如果有需要,应当先修改 storyboard.json 内容,然后再调用 generate-video-by-ref 生成视频。注意修改 storyboard 内容时,仅修改相应字段的字符串值,不要破坏JSON格式!
|
|
3812
|
-
|
|
3813
|
-
再次调用 generate-video-by-ref 时,如需要参考图,要确保referenceImages使用正确(main_characters中的reference_image作为参考人物,reference_objects中的image作为参考物品或参考背景)`, 'generate-image');
|
|
2931
|
+
return createErrorResponse('监测到素材中存在outline_sheet.png这张图(由outline工具生成的),应采用 generate-video 图生视频。若用户明确要用参考生视频,则跳过一致性检查。', 'generate-video');
|
|
3814
2932
|
}
|
|
3815
|
-
// 校验 prompt 与 storyboard.json
|
|
2933
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性(如果提供了 sceneIndex)
|
|
3816
2934
|
if (!skipConsistencyCheck && sceneIndex) {
|
|
3817
2935
|
try {
|
|
3818
2936
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
@@ -3834,16 +2952,16 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3834
2952
|
}
|
|
3835
2953
|
// 检查 scene.is_continuous 是否为 true
|
|
3836
2954
|
if (scene.is_continuous === true) {
|
|
3837
|
-
return createErrorResponse('
|
|
2955
|
+
return createErrorResponse('连续镜头应使用首尾帧,请修改连续镜头设置,或将本分镜改为首尾帧方式实现', 'generate-video-by-ref');
|
|
3838
2956
|
}
|
|
3839
2957
|
if (scene.video_type !== 'references') {
|
|
3840
|
-
return createErrorResponse(
|
|
2958
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中的 video_type (${scene.video_type}) 未设置为 'references',不应当使用参考生视频,请使用图生视频 generate-video 方式生成`, 'generate-video-by-ref');
|
|
3841
2959
|
}
|
|
3842
2960
|
// 检查 use_video_model 与 type 参数的一致性
|
|
3843
2961
|
if (scene.use_video_model &&
|
|
3844
2962
|
type &&
|
|
3845
2963
|
scene.use_video_model !== type) {
|
|
3846
|
-
return createErrorResponse(
|
|
2964
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中的 use_video_model (${scene.use_video_model}) 必须与 type 参数 (${type}) 保持一致`, 'generate-video-by-ref');
|
|
3847
2965
|
}
|
|
3848
2966
|
// 检查 scene.references 的一致性
|
|
3849
2967
|
if (scene.references &&
|
|
@@ -3859,7 +2977,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3859
2977
|
const character = mainCharacters.find((char) => char.name === referenceName);
|
|
3860
2978
|
if (character) {
|
|
3861
2979
|
if (!character.reference_image) {
|
|
3862
|
-
return createErrorResponse(
|
|
2980
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的角色 "${referenceName}" 在 main_characters 中没有 reference_image 属性`, 'generate-video-by-ref');
|
|
3863
2981
|
}
|
|
3864
2982
|
requiredImage = character.reference_image;
|
|
3865
2983
|
found = true;
|
|
@@ -3869,7 +2987,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3869
2987
|
const refObject = referenceObjects.find((obj) => obj.name === referenceName);
|
|
3870
2988
|
if (refObject) {
|
|
3871
2989
|
if (!refObject.image) {
|
|
3872
|
-
return createErrorResponse(
|
|
2990
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的物品/背景 "${referenceName}" 在 reference_objects 中没有 image 属性`, 'generate-video-by-ref');
|
|
3873
2991
|
}
|
|
3874
2992
|
requiredImage = refObject.image;
|
|
3875
2993
|
found = true;
|
|
@@ -3877,11 +2995,11 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3877
2995
|
}
|
|
3878
2996
|
// 如果既不在 main_characters 也不在 reference_objects 中
|
|
3879
2997
|
if (!found) {
|
|
3880
|
-
return createErrorResponse(
|
|
2998
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的 "${referenceName}" 在 main_characters 或 reference_objects 中都找不到对应的定义`, 'generate-video-by-ref');
|
|
3881
2999
|
}
|
|
3882
3000
|
// 检查对应的图片是否在 referenceImages 参数中
|
|
3883
3001
|
if (!referenceImages.some(ref => ref.fileName === requiredImage)) {
|
|
3884
|
-
return createErrorResponse(
|
|
3002
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的 "${referenceName}" 对应的图片 "${requiredImage}" 不在 referenceImages 参数中,请确保传入正确的参考图片`, 'generate-video-by-ref');
|
|
3885
3003
|
}
|
|
3886
3004
|
}
|
|
3887
3005
|
}
|