将小说章节转换为MP3有声书,支持关键词触发,自动识别对话角色并分配不同音色,生成带背景音乐的完整有声书。
路径说明: 所有脚本路径相对于此 Skill 目录。 执行时:
cd {skill_dir} && python scripts/...
收到用户请求后,按以下步骤执行:
从用户输入中获取章节文本:
第一章.md、 第一章.txt)同时询问用户是否需要调整:
调用 DeepSeek 分析章节文本,识别旁白和对话:
bash
python scripts/chapter_analyzer.py --file "章节文件路径" > temp_analysis.json
输出为 JSON,包含 segments 数组,每段有:
type: title / narration / dialoguetext: 分段文本character: 角色名(对话时)mood: 段落情绪同时获得统计信息: 总字数、对话占比、角色列表。
注意: 将输出保存为临时 JSON 文件,供后续步骤使用。
根据章节情绪生成纯音乐背景:
bash
python scripts/music_generator.py \
--mood "章节情绪(如悬疑/温馨/平静)" \
--output "temp_bgm/bg_music.mp3"
情绪映射参考:
章节氛围音乐风格平静/日常轻钢琴悬疑/紧张暗黑氛围悲伤钢琴独奏欢快轻快节奏热血/战斗管弦乐激昂
如用户不需要背景音乐,跳过此步。
根据分段结果,调用 MiniMax TTS 为每段生成语音:
bash
python scripts/tts_generator.py \
--segments-file "temp_analysis.json" \
--output-dir "temp_audio/" > temp_tts_result.json
音色分配规则:
章节标题 → 主播音色( chapter_intro_voice)
旁白 → 统一旁白音色( narration_voice)
角色对话 → 根据角色名自动分配音色:
config.json 的 character_voices 中自定义拼接所有语音段 + 混入背景音乐:
bash
python scripts/audio_assembler.py \
--segments "temp_tts_result.json" \
--bg-music "temp_bgm/bg_music.mp3" \
--output "E:/qwenpaw/Novel/有声书输出/小说名_章节名.mp3"
如没有背景音乐,去掉 --bg-music 参数。
将最终 MP3 文件路径和信息展示给用户:
在 config.json 中配置以下信息:
配置项说明deepseek_api_keyDeepSeek API Key(分析章节文本)minimax_api_keyMiniMax API Key(TTS + 音乐生成)tts_modelTTS 模型(默认 speech-2.8-hd)music_model音乐模型(默认 music-2.6-free)narration_voice旁白音色default_male_voice男性角色默认音色default_female_voice女性角色默认音色output_path有声书输出目录bg_music_volume背景音乐音量 (0.0~1.0,默认 0.15)
示例 1: 用户提供文件路径
text
用户: 帮我把第一章转成有声书,文件在 E:\qwenpaw\Novel\当前作品\第一章.md
执行流程:
bash
python scripts/chapter_analyzer.py --file "E:/qwenpaw/Novel/当前作品/第一章.md" > temp_analysis.json
python scripts/music_generator.py --mood "平静" --output "temp_bgm/bg_music.mp3"
python scripts/tts_generator.py --segments-file temp_analysis.json --output-dir temp_audio/ > temp_tts_result.json
python scripts/audio_assembler.py --segments temp_tts_result.json --bg-music temp_bgm/bg_music.mp3 --output "E:/qwenpaw/Novel/有声书输出/当前作品_第一章.mp3"
示例 2: 用户直接粘贴章节文本
text
用户: 这段转有声书:(粘贴文本内容)
用 --text 参数直接传文本:
bash
python scripts/chapter_analyzer.py --text "粘贴的章节内容" > temp_analysis.json
character_voices 字段中自定义映射music-2.6-free 免费模型,如需更高品质可改为 music-2.6(需付费)temp_audio/ 和 temp_bgm/ 目录,可手动清理