feat(video-from-script): 添加 TTS 音色管理和解析功能
- 在 config.json 中添加 `ttsVoices` 音色库,支持音色名称到 ID 的映射 - 实现 `resolveVoice` 函数,将音色名称解析为实际 ID - 更新账号系统和批量管道,支持通过音色名称配置 TTS 语音 - Excel 导入和 CLI 参数新增音色字段,支持按行指定不同音色
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { loadAccountConfig, saveManifest, ensureDir, slugify, ACCOUNTS_DIR, SKILLS_DIR } = require('./pipeline-utils')
|
||||
const { loadAccountConfig, loadConfig, resolveVoice, saveManifest, ensureDir, slugify, ACCOUNTS_DIR, SKILLS_DIR } = require('./pipeline-utils')
|
||||
|
||||
function initManifest(options) {
|
||||
const { account: accountId, mode, items: itemsJson, itemsFile } = options
|
||||
@@ -17,6 +17,7 @@ function initManifest(options) {
|
||||
}
|
||||
|
||||
const accountConfig = loadAccountConfig(accountId)
|
||||
const globalConfig = loadConfig()
|
||||
|
||||
// 解析 items
|
||||
let rawItems
|
||||
@@ -123,7 +124,8 @@ function initManifest(options) {
|
||||
format: options.format || accountConfig.defaultFormat || '9:16',
|
||||
mode: resolvedMode,
|
||||
references,
|
||||
...(accountConfig.ttsVoice ? { ttsVoice: accountConfig.ttsVoice } : {}),
|
||||
...(accountConfig.ttsVoice ? { ttsVoice: resolveVoice(accountConfig.ttsVoice, globalConfig) } : {}),
|
||||
...(options.ttsVoice ? { ttsVoice: resolveVoice(options.ttsVoice, globalConfig) } : {}),
|
||||
...(accountConfig.ttsInstruction ? { ttsInstruction: accountConfig.ttsInstruction } : {}),
|
||||
// 铁律:ttsRate 写死 1.15x,不允许配置覆盖(除非显式传入)
|
||||
ttsRate: options.ttsRate || 1.15,
|
||||
|
||||
@@ -8,11 +8,12 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// 路径常量(基于 lib/ 的父目录 scripts/)
|
||||
const SCRIPTS_DIR = path.join(__dirname, '..')
|
||||
const SKILLS_DIR = path.join(SCRIPTS_DIR, '..')
|
||||
const PROJECT_ROOT = path.join(SKILLS_DIR, '..', '..')
|
||||
const CONFIG_PATH = path.join(SKILLS_DIR, 'config.json')
|
||||
const ACCOUNTS_DIR = path.join(PROJECT_ROOT, '..', 'accounts')
|
||||
const SCRIPTS_DIR = path.join(__dirname, '..') // scripts/
|
||||
const SKILLS_DIR = path.join(SCRIPTS_DIR, '..') // video-from-script/
|
||||
const SKILL_PARENT_DIR = path.join(SKILLS_DIR, '..') // skills/
|
||||
const PROJECT_ROOT = path.join(SKILLS_DIR, '..', '..') // .claude/
|
||||
const CONFIG_PATH = path.join(SKILL_PARENT_DIR, 'config.json') // skills/config.json
|
||||
const ACCOUNTS_DIR = path.join(PROJECT_ROOT, '..', 'accounts') // 美图/accounts
|
||||
|
||||
// ============================================================================
|
||||
// 配置 & Manifest
|
||||
@@ -22,6 +23,15 @@ function loadConfig() {
|
||||
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'))
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析音色:名称 → ID。如果是音色库中的名称则查 ttsVoices 映射表,否则原样返回。
|
||||
*/
|
||||
function resolveVoice(voice, config) {
|
||||
if (!voice) return voice
|
||||
const voices = (config || loadConfig()).ttsVoices || {}
|
||||
return voices[voice] || voice
|
||||
}
|
||||
|
||||
function loadManifest(manifestPath) {
|
||||
return JSON.parse(fs.readFileSync(manifestPath, 'utf-8'))
|
||||
}
|
||||
@@ -221,6 +231,7 @@ module.exports = {
|
||||
CONFIG_PATH,
|
||||
ACCOUNTS_DIR,
|
||||
loadConfig,
|
||||
resolveVoice,
|
||||
loadManifest,
|
||||
saveManifest,
|
||||
loadAccountConfig,
|
||||
|
||||
Reference in New Issue
Block a user