feat(video-from-script): 添加 TTS 音色管理和解析功能
- 在 config.json 中添加 `ttsVoices` 音色库,支持音色名称到 ID 的映射 - 实现 `resolveVoice` 函数,将音色名称解析为实际 ID - 更新账号系统和批量管道,支持通过音色名称配置 TTS 语音 - Excel 导入和 CLI 参数新增音色字段,支持按行指定不同音色
This commit is contained in:
@@ -37,6 +37,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.ttsVoices || {}
|
||||
return voices[voice] || voice
|
||||
}
|
||||
|
||||
function getAudioDuration(filePath) {
|
||||
try {
|
||||
const out = execFileSync('ffprobe', [
|
||||
@@ -64,7 +73,7 @@ function synthesize(text, options = {}) {
|
||||
if (!apiKey) { reject(new Error('ttsApiKey 未配置')); return }
|
||||
|
||||
const model = options.model || config.ttsModel || 'cosyvoice-v3-flash'
|
||||
const voice = options.voice || config.ttsVoice || 'longanyang'
|
||||
const voice = resolveVoice(options.voice || config.ttsVoice, config) || 'longanyang'
|
||||
const instruction = options.instruction || config.ttsInstruction || ''
|
||||
const outputDir = options.outputDir || './audio'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user