fix(speech): 智能体的音色不生效(用户报的)—— 界面朗读时没传 agentId(v2.0.54)

内核一直是对的:speech.voice_for() 有'智能体 > 全局'的覆盖,
/api/tts 和 /api/tts/stream 都收 agentId。

漏的是界面:client.speak(text) 只传正文,内核拿不到人就永远用全局音色 ——
用户在智能体编辑页选的音色配了等于没配。

  · SpeechController 加 agentId: () -> String(lambda,切换智能体要跟着变)
  · KernelClient.speak / streamTts 加 agentId 参数
  · ChatScreen 的 remember 里传 vm.state.settings.activeAgentId
  · 流式那条(自动朗读/长句)漏的是同一处,一起补

探针新增 16 节 4 项:界面侧没法测(Kotlin),所以钉**契约** ——
只要 agentId 传进来音色就必须跟着换、没配的回落全局。
This commit is contained in:
l
2026-10-16 16:21:39 +08:00
parent 182c0005a4
commit 08eecb9e0a
4 changed files with 47 additions and 7 deletions

View File

@@ -449,6 +449,30 @@ def main():
check("置顶数超过窗口时,置顶的全部保留(6 条)", kept == 6, f"实际 {kept} 条:{seg4[-200:]}")
store.write_settings({"memoryWindow": 50})
# ---------------------------------------------------------------- 16
section("16. 语音:智能体自己的音色要真的生效(用户报的「语音没生效」)")
#
# 内核这边一直是对的(`voice_for` 做"智能体 > 全局"),
# 真正漏的是**界面朗读时不传 agentId** —— 于是内核拿不到人,
# 永远用全局那个嗓子,智能体编辑页里选的音色白配。
# 界面那一侧没法在这里测,所以这里把**契约**钉死:
# 只要 agentId 传进来,音色必须跟着换。
import speech
a_voice = store.create_agent({"name": "嗓音测试"})
store.update_agent(a_voice["id"], {"ttsVoice": "my-voice-123", "ttsEngine": "volc"})
st = store.read_settings()
merged = speech.voice_for(st, store.get_agent(a_voice["id"]))
check("智能体的音色覆盖了全局", merged.get("ttsVoice") == "my-voice-123", str(merged.get("ttsVoice")))
check("引擎也跟着覆盖", merged.get("ttsEngine") == "volc", str(merged.get("ttsEngine")))
plain = speech.voice_for(st, {})
check("没配的智能体回落全局", plain.get("ttsVoice") == speech.voice_for(st, {}).get("ttsVoice"))
# 半配:只设了音色、没设引擎 → 引擎回落,音色用它的
half = store.create_agent({"name": "半配"})
store.update_agent(half["id"], {"ttsVoice": "only-voice"})
m2 = speech.voice_for(st, store.get_agent(half["id"]))
check("只设音色时引擎回落全局", m2.get("ttsVoice") == "only-voice", str(m2.get("ttsVoice")))
# ---------------------------------------------------------------- 汇总
print()
if fails: