From 06c76bd828c97dbf67e4b6fae6bf94e726faefe3 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 26 May 2025 15:41:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=83=A8=E5=88=86=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E4=B8=8D=E9=9C=80=E8=A6=81=E6=92=AD=E6=94=BE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent_service/AgentService.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index f73d7c0b9..20b97a7e1 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt @@ -662,7 +662,7 @@ object AgentService : CoroutineScope { val responseBuilder = StringBuilder() var aiMetadata:String = "" var userMetadata = JSONObject() - + var nobroadcast = false // 如果有图片,添加图片信息到元数据 if (hasImage) { userMetadata.put("hasImage", true) @@ -717,7 +717,7 @@ object AgentService : CoroutineScope { callback = object : OpenAIService.StreamCallback { override fun onToken(token: String) { responseBuilder.append(token) - if (speakResponse) { + if (speakResponse && !nobroadcast) { ttsService?.speakStream(token) } // 发送流式回复token @@ -748,8 +748,6 @@ object AgentService : CoroutineScope { // 保存聊天记录 saveChatMessage(displayText, response,aiMetadata,userMetadata.toString()) - - } // 标记AI流式输出已完成 @@ -792,7 +790,9 @@ object AgentService : CoroutineScope { "result" to functionCallResult.toString(), )) Log.d(TAG, "mcp调用结果: $functionCallResult") - aiMetadata = autoHandleFcunCallResult(functionCallResult); + val (metestr, broadcast)= autoHandleFcunCallResult(functionCallResult); + aiMetadata = metestr; + nobroadcast = broadcast } } ) @@ -1108,8 +1108,9 @@ object AgentService : CoroutineScope { /* * 自动播放音乐 * */ - fun autoHandleFcunCallResult(functionCallResult: JSONObject): String{ + fun autoHandleFcunCallResult(functionCallResult: JSONObject): Pair{ val metaStr = functionCallResult.optString("meta") + var broadcast = false; if (metaStr.isNotEmpty()) { val meta = JSONObject(metaStr) // Log.d(TAG, "mcp调用结果: $metaStr") @@ -1122,6 +1123,7 @@ object AgentService : CoroutineScope { val sgener = cardMusic.optString("sgener", "") val image = cardMusic.optString("image", "") processMusicPlay(mapOf("id" to id,"url" to url, "title" to name, "artist" to sgener,"coverUrl" to image)) + broadcast = true; }else if (meta.has("card_musiclist")) { //音乐列表 val cardMusiclist = meta.getJSONObject("card_musiclist") val musics = cardMusiclist.optJSONArray("musics") @@ -1138,6 +1140,7 @@ object AgentService : CoroutineScope { } if (playlist.isNotEmpty()) { Log.w(TAG, "自动播放音乐列表 ${playlist}") + broadcast = true; processMusicPlayList(playlist) } else { Log.w(TAG, "card_musiclist 中没有有效的音乐条目") @@ -1149,11 +1152,12 @@ object AgentService : CoroutineScope { val cardNavigation = meta.getJSONObject("card_navigation") val start = cardNavigation.optString("start", "") val end = cardNavigation.optString("end", "") + broadcast = true; processNavigation(start,end); } - return metaStr; + return Pair(metaStr, broadcast); } - return ""; + return Pair("", false); } /**