feat: add continue script functionality for AI-generated audiobook projects

This commit is contained in:
2026-03-13 11:59:37 +08:00
parent 7129047c3f
commit 7644584c39
11 changed files with 355 additions and 7 deletions

View File

@@ -323,6 +323,42 @@ class LLMService:
system_prompt, user_message, on_token=on_token, max_tokens=4096, usage_callback=usage_callback
)
async def generate_additional_chapter_outline(
self,
genre: str,
subgenre: str,
premise: str,
style: str,
existing_chapters: list[Dict],
additional_chapters: int,
characters: list[Dict],
usage_callback: Optional[Callable[[int, int], None]] = None,
) -> list[Dict]:
system_prompt = (
"你是一个专业的故事创作助手。请根据已有章节大纲,续写新的章节大纲。\n"
"每章包含章节索引(从给定起始索引开始)、标题和简介。\n"
"新章节必须与已有章节剧情连贯,情节有所推进。\n"
"只输出JSON格式如下不要有其他文字\n"
'{"chapters": [{"index": N, "title": "标题", "summary": "章节内容简介2-3句话"}, ...]}'
)
genre_label = f"{genre}{'/' + subgenre if subgenre else ''}"
char_names = [c.get("name", "") for c in characters if c.get("name") not in ("narrator", "旁白")]
start_index = len(existing_chapters)
existing_summary = "\n".join(
f"{ch.get('index', i) + 1}章「{ch.get('title', '')}」:{ch.get('summary', '')}"
for i, ch in enumerate(existing_chapters)
)
user_message = (
f"故事类型:{genre_label}\n"
+ (f"风格:{style}\n" if style else "")
+ f"故事简介:{premise}\n"
f"主要角色:{', '.join(char_names)}\n\n"
f"已有章节大纲(共{len(existing_chapters)}章):\n{existing_summary}\n\n"
f"请从第{start_index}章(索引{start_index})开始,续写{additional_chapters}章大纲,剧情要承接上文。"
)
result = await self.stream_chat_json(system_prompt, user_message, max_tokens=4096, usage_callback=usage_callback)
return result.get("chapters", [])
async def parse_chapter_segments(self, chapter_text: str, character_names: list[str], on_token=None, usage_callback: Optional[Callable[[int, int], None]] = None) -> list[Dict]:
names_str = "".join(character_names)
system_prompt = (