feat: Add emotion handling to audiobook segments with emo_text and emo_alpha attributes

This commit is contained in:
2026-03-12 14:34:20 +08:00
parent 1757f39322
commit bbcfc0e8d3
8 changed files with 37 additions and 5 deletions

View File

@@ -201,9 +201,14 @@ class LLMService:
system_prompt = (
"你是一个专业的有声书制作助手。请将给定的章节文本解析为对话片段列表。"
f"已知角色列表(必须从中选择):{names_str}"
"所有非对话的叙述文字归属于narrator角色。"
"所有非对话的叙述文字归属于narrator角色。\n"
"同时根据语境为每个片段判断情绪,可选情绪及对应强度如下(必须严格使用以下值):\n"
"开心(emo_alpha=0.6)、愤怒(emo_alpha=0.15)、悲伤(emo_alpha=0.4)、恐惧(emo_alpha=0.4)、"
"厌恶(emo_alpha=0.6)、低沉(emo_alpha=0.6)、惊讶(emo_alpha=0.3)、中性(emo_alpha=0.5)。\n"
"narrator旁白及情绪不明显的片段emo_text设为\"\"emo_alpha设为0.5。\n"
"只输出JSON数组不要有其他文字格式如下\n"
'[{"character": "narrator", "text": "叙述文字"}, {"character": "角色名", "text": "对话内容"}, ...]'
'[{"character": "narrator", "text": "叙述文字", "emo_text": "", "emo_alpha": 0.5}, '
'{"character": "角色名", "text": "对话内容", "emo_text": "开心", "emo_alpha": 0.6}, ...]'
)
user_message = f"请解析以下章节文本:\n\n{chapter_text}"
result = await self.stream_chat_json(system_prompt, user_message, on_token, max_tokens=16384)