From f9462b4197a821d8237d232f30faa45d24f98073 Mon Sep 17 00:00:00 2001 From: bdim404 Date: Fri, 13 Mar 2026 15:35:50 +0800 Subject: [PATCH] feat: adjust emotion limits and guidance for character emotions in LLMService --- qwen3-tts-backend/core/llm_service.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/qwen3-tts-backend/core/llm_service.py b/qwen3-tts-backend/core/llm_service.py index 0b7246d..5d10cef 100644 --- a/qwen3-tts-backend/core/llm_service.py +++ b/qwen3-tts-backend/core/llm_service.py @@ -323,16 +323,16 @@ class LLMService: def _emotion_limits(violence_level: int, eroticism_level: int) -> tuple[str, str]: v = violence_level / 10 e = eroticism_level / 10 - female_happy = round(0.35 + 0.45 * e, 2) + female_happy = round(0.20 + 0.45 * e, 2) angry = round(0.15 + 0.65 * v, 2) sad = round(0.10 + 0.40 * v, 2) fear = round(0.10 + 0.60 * v, 2) hate = round(0.35 + 0.25 * max(v, e), 2) low = round(0.35 + 0.45 * e, 2) - surprise= round(0.10 + 0.40 * max(v, e), 2) + surprise= round(0.15 + 0.35 * max(v, e), 2) limits = ( f"愤怒={angry}、悲伤={sad}、恐惧={fear}、厌恶={hate}、低沉={low}、惊讶={surprise}、" - f"开心:男性角色上限=0.35,女性角色上限={female_happy}" + f"开心:男性角色上限=0.20,女性角色上限={female_happy}" ) guidance_parts = [] if violence_level >= 4: @@ -382,7 +382,8 @@ class LLMService: "- 混合情感:(情感1:比重+情感2:比重),如(开心:0.6+悲伤:0.2)、(愤怒:0.3+恐惧:0.4)\n" "- 混合情感时每个情感的比重独立设定,反映各自对情绪的贡献\n" f"- 各情感比重上限(严格不超过):{limits_str}\n" - "- 情感不明显时可省略整个括号\n" + "- 鼓励使用低值(0.05–0.10)表达微弱、内敛或一闪而过的情绪,无需非强即无\n" + "- 确实没有任何情绪色彩时可省略整个括号\n" + narrator_rule + emo_guidance_line + "\n其他规则:\n" @@ -459,13 +460,14 @@ class LLMService: "emo_text 格式规则:\n" " 单一情感:直接填情感词,用 emo_alpha 设置强度,如 emo_text=\"开心\", emo_alpha=0.3\n" " 混合情感:用 情感词:比重 格式拼接,emo_alpha 设为 1.0,如 emo_text=\"开心:0.6+悲伤:0.2\", emo_alpha=1.0\n" - "情绪不明显或旁白时,emo_text=\"\",emo_alpha=0。\n" - "各情感比重上限(严格不超过):开心=0.35、愤怒=0.15、悲伤=0.1、恐惧=0.1、厌恶=0.35、低沉=0.35、惊讶=0.1。\n" + "各情感比重上限(严格不超过):开心=0.20、愤怒=0.15、悲伤=0.1、恐惧=0.1、厌恶=0.35、低沉=0.35、惊讶=0.15。\n" + "鼓励用低值(0.05–0.10)表达微弱或内敛的情绪,不要非强即无;完全无情绪色彩时 emo_text 置空。\n" "同一角色的连续台词,情绪应尽量保持一致或仅有微弱变化,避免相邻片段间情绪跳跃。\n" "只输出JSON数组,不要有其他文字,格式如下:\n" '[{"character": "旁白", "text": "叙述文字", "emo_text": "", "emo_alpha": 0}, ' - '{"character": "角色名", "text": "对话内容", "emo_text": "开心", "emo_alpha": 0.3}, ' - '{"character": "角色名", "text": "含泪的笑", "emo_text": "开心:0.5+悲伤:0.2", "emo_alpha": 1.0}]' + '{"character": "角色名", "text": "淡淡的问候", "emo_text": "开心", "emo_alpha": 0.08}, ' + '{"character": "角色名", "text": "激动的欢呼", "emo_text": "开心", "emo_alpha": 0.18}, ' + '{"character": "角色名", "text": "含泪的笑", "emo_text": "开心:0.12+悲伤:0.08", "emo_alpha": 1.0}]' ) user_message = f"请解析以下章节文本:\n\n{chapter_text}" result = await self.stream_chat_json(system_prompt, user_message, on_token, max_tokens=16384, usage_callback=usage_callback)