- 重写 `phase-images`:改为并发 3 张并行生成,每个 item 完成立即写入 manifest,支持 MJ task ID 恢复 - 重写 `phase-videos`:先恢复已有 task ID 再提交新任务(并发 3),支持中断恢复 - 迁移 TTS 引擎:从 Qwen-TTS HTTP 接口切换为 CosyVoice WebSocket 接口,支持音色/语气参数透传 - 精简账号系统:移除 `styles/` 目录、`taskId` 过滤和 `--id` 正则校验,`references` 改为顶层字段 - 调整 `slugify`:限制中文字符 5 个、其他 10 个,避免文件名过长 - 更新文档:`manifest-schema.md` 中 `narration` 改为完整原文案,`account-creation.md` 新增 TTS 配置项 - 配置更新:默认 TTS 模型切换为 `cosyvoice-v3.5-plus`,新增 `localAudio` 参数
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
/**
|
||
* Phase: tts — 语音合成
|
||
*
|
||
* 使用通义千问 TTS 生成旁白音频
|
||
*/
|
||
|
||
const path = require('path')
|
||
const { saveManifest, ensureDir, log, getManifestDir } = require('./pipeline-utils')
|
||
|
||
async function phaseTts(manifest, manifestPath, options = {}) {
|
||
const dir = getManifestDir(manifestPath)
|
||
const audioDir = path.join(dir, 'audio')
|
||
ensureDir(audioDir)
|
||
|
||
const { synthesize } = require('../qwen-tts')
|
||
|
||
const items = manifest.items.filter(it =>
|
||
it.status === 'done' && (it.narration || it.text) && !it.audio
|
||
)
|
||
if (items.length === 0) { log('tts', '无待处理 item,跳过'); return }
|
||
|
||
log('tts', `共 ${items.length} 段`)
|
||
|
||
for (let i = 0; i < items.length; i++) {
|
||
const item = items[i]
|
||
const idx = i + 1
|
||
try {
|
||
const { filePath, duration } = await synthesize(item.narration || item.text, {
|
||
outputDir: audioDir,
|
||
id: item.id || idx,
|
||
voice: manifest.ttsVoice || undefined,
|
||
instruction: manifest.ttsInstruction || undefined,
|
||
})
|
||
item.audio = path.relative(dir, filePath).replace(/\\/g, '/')
|
||
item.audioDuration = Math.round(duration * 1000) / 1000
|
||
log('tts', `[${idx}/${items.length}] ${duration.toFixed(1)}s: ${(item.narration || item.text).substring(0, 30)}...`)
|
||
} catch (err) {
|
||
item.status = 'failed'
|
||
item.error = `TTS失败: ${err.message}`
|
||
log('tts', `[${idx}/${items.length}] 失败: ${err.message}`)
|
||
}
|
||
saveManifest(manifestPath, manifest)
|
||
}
|
||
}
|
||
|
||
module.exports = { phaseTts }
|