From 79dbc93684ddb9c4147c008f82a6f410cd72fcd7 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Wed, 10 Dec 2025 23:36:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(AndroidManifest):=20=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E5=AE=89=E5=8D=93=E5=90=84=E5=A4=A7=E5=B9=B3=E5=8F=B0=E9=99=90?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E7=A7=BB=E9=99=A4SEND=5FSMS=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c2de8317d..4e946db0e 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -41,7 +41,7 @@ - + From 5b4d80cc0ac0fa549b2ed08395e880ae64fe43cf Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 11 Dec 2025 19:28:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(=E8=AF=AD=E9=9F=B3=E8=AF=86=E5=88=AB):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8C=89=E4=BD=8F=E8=AF=B4=E8=AF=9D?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E7=9A=84=E8=AF=86=E5=88=AB=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改AzureAsrHelper中会话结束事件的条件判断,移除外部音频源限制 在AgentService中添加识别结果缓存,改进按住说话模式下的结果拼接和事件发送 --- .../agent_service/AgentService.kt | 85 +++++++++++++------ .../azure_speech/AzureAsrHelper.kt | 4 +- 2 files changed, 63 insertions(+), 26 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 e931fc06c..710159297 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 @@ -149,6 +149,8 @@ object AgentService : CoroutineScope { private var isplaymusic = false; //是否保留最终结果 private var isKeepResult = true; + // 识别结果 + private var recognitionResult = "" // 打断防抖相关 private var lastInterruptTime = 0L @@ -643,7 +645,7 @@ object AgentService : CoroutineScope { // 根据模式启动相应的空闲检测 startIdleCheckForMode(mode) - // 设置当前识别模式 + // 设置当前识别模式 currentRecognitionMode = mode Log.d(TAG, "设置语音识别模式: $mode") return true @@ -666,20 +668,33 @@ object AgentService : CoroutineScope { val success = azureAsrHelper?.setupEventListeners(object : AzureAsrHelper.ContinuousRecognizeCallback { override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { + Log.d(TAG, "liwei-------- onRecognizing: $sessionid") if (recognizing.isNotEmpty()&&isKeepResult==true) { // 检测到语音,更新状态 _hasSpeechDetected.set(true) Log.d(TAG, "ai识别中重置定时器") restartIdleCheck() - - - sendEvent( - "recognizing", mapOf( - "sessionid" to sessionid, - "text" to recognizing, - "language" to detectedLanguage + var text = "" + if (currentRecognitionMode == "push_to_talk") { + text = recognitionResult + recognizing + sendEvent( + "recognizing", mapOf( + "sessionid" to currsessionId, + "text" to text, + "language" to detectedLanguage + ) ) - ) + }else{ + text = recognizing + sendEvent( + "recognizing", mapOf( + "sessionid" to sessionid, + "text" to text, + "language" to detectedLanguage + ) + ) + } + // 如果TTS正在播放或AI正在生成,检查是否需要打断 if (isTtsSpeaking || isAiStreaming) { @@ -709,45 +724,66 @@ object AgentService : CoroutineScope { } override fun onResult(sessionid:String,result: String, detectedLanguage: String) { + Log.d(TAG, "liwei-------- onResult: $sessionid ") if (result.isNotEmpty()&&isKeepResult==true) {//加入是否结束要输出最后的结果判读 - sendEvent( - "recognition_result", mapOf( - "sessionid" to sessionid, - "text" to result, - "language" to detectedLanguage + // 保存识别结果 + if (currentRecognitionMode == "push_to_talk") { //按住说话 + recognitionResult += result + }else{ + sendEvent( + "recognition_result", mapOf( + "sessionid" to sessionid, + "text" to result, + "language" to detectedLanguage + ) ) - ) - - processWithChatApi(sessionid,result) + processWithChatApi(sessionid,result) + } } - _hasSpeechDetected.set(false) - restartIdleCheck() + restartIdleCheck() } override fun onSessionStarted(sessionid:String) { + Log.d(TAG, "liwei-------- onSessionStarted: $sessionid") sendEvent("recognition_started", mapOf("sessionid" to sessionid, "status" to "started")) // 使用模式感知的空闲检测启动方法 + recognitionResult = "" + currsessionId = sessionid audioPlayer?.playAudio(R.raw.start) - } override fun onSessionStopped(sessionid:String) { - sendEvent("recognition_stopped", mapOf("sessionid" to sessionid, "status" to "stopped")) - _isRecognitionActive.set(false) + Log.d(TAG, "liwei-------- onSessionStopped: $sessionid") + if (currentRecognitionMode == "push_to_talk") { //按住说话 + sendEvent( + "recognition_result", mapOf( + "sessionid" to currsessionId, + "text" to recognitionResult + ) + ) + processWithChatApi(currsessionId,recognitionResult) + + sendEvent("recognition_stopped", mapOf("sessionid" to currsessionId, "status" to "stopped")) + }else{ + sendEvent("recognition_stopped", mapOf("sessionid" to sessionid, "status" to "stopped")) + + audioPlayer?.playAudio(R.raw.stop) + } stopIdleCheck() - audioPlayer?.playAudio(R.raw.stop) + _isRecognitionActive.set(false) + } override fun onCanceled(sessionid: String,reason: String, errorDetails: String) { + Log.d(TAG, "liwei-------- onCanceled: $sessionid $reason $errorDetails") _isRecognitionActive.set(false) stopIdleCheck() - Log.d(TAG, "recognition_canceled:") BleService.closeCodec() sendEvent( "recognition_canceled", mapOf( @@ -759,6 +795,7 @@ object AgentService : CoroutineScope { } override fun onError(sessionid:String, code: Int, error: String) { + Log.d(TAG, "liwei-------- onError: $sessionid $code $error") _isRecognitionActive.set(false) stopIdleCheck() BleService.closeCodec() diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt index a7fc47c20..58fc353b3 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt @@ -421,10 +421,10 @@ class AzureAsrHelper(private val context: Context) { EventHandler { _, _ -> // 直接在当前线程调用回调 Log.d(tag, "会话结束事件") - if (audioSourceType == AudioSourceType.EXTERNAL) { + // if (audioSourceType == AudioSourceType.EXTERNAL) { callback.onSessionStopped(currsessionid) audioStream?.isContinuousRecognitionActive = false - } + // } } ) From 624bdf18d593980e6af861f5ac9501670809eb9a Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 11 Dec 2025 19:36:46 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/modules/agent/views/message_bubble.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/modules/agent/views/message_bubble.dart b/lib/modules/agent/views/message_bubble.dart index 7a845e44c..ae545ae1f 100644 --- a/lib/modules/agent/views/message_bubble.dart +++ b/lib/modules/agent/views/message_bubble.dart @@ -166,6 +166,7 @@ class MessageBubble extends GetView { // 如果是识别中的消息,添加特殊样式 if (isRecognizing) { return Row( + crossAxisAlignment: CrossAxisAlignment.end, mainAxisSize: MainAxisSize.min, children: [ Flexible( @@ -177,7 +178,9 @@ class MessageBubble extends GetView { fontSize: 14, height: 1.4, ), - overflow: TextOverflow.ellipsis, + // 允许自动换行,不再强制单行 + softWrap: true, + maxLines: null, ), ), const SizedBox(width: 8), From 6a41953222d7586f3cd2ca825197832803d8ed01 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 11 Dec 2025 19:45:48 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=A9=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunqiinnovation/agent_service/AgentService.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 710159297..67ca32066 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 @@ -761,14 +761,15 @@ object AgentService : CoroutineScope { override fun onSessionStopped(sessionid:String) { Log.d(TAG, "liwei-------- onSessionStopped: $sessionid") if (currentRecognitionMode == "push_to_talk") { //按住说话 - sendEvent( - "recognition_result", mapOf( - "sessionid" to currsessionId, - "text" to recognitionResult + if (recognitionResult.isNotEmpty()){ + sendEvent( + "recognition_result", mapOf( + "sessionid" to currsessionId, + "text" to recognitionResult + ) ) - ) - processWithChatApi(currsessionId,recognitionResult) - + processWithChatApi(currsessionId,recognitionResult) + } sendEvent("recognition_stopped", mapOf("sessionid" to currsessionId, "status" to "stopped")) }else{ sendEvent("recognition_stopped", mapOf("sessionid" to sessionid, "status" to "stopped"))