From dfcbb07cd6e5d60883f87e5c759c9033b24044a0 Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Fri, 12 Dec 2025 10:34:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=86=E5=88=AB=E7=BB=93=E6=9E=9C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=BB=B6=E8=BF=9F=E5=A4=84=E7=90=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent_service/AgentService.kt | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 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 67ca32066..9a0b45252 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 @@ -151,6 +151,7 @@ object AgentService : CoroutineScope { private var isKeepResult = true; // 识别结果 private var recognitionResult = "" + private var pendingProcessJob: Job? = null // 打断防抖相关 private var lastInterruptTime = 0L @@ -669,6 +670,7 @@ object AgentService : CoroutineScope { AzureAsrHelper.ContinuousRecognizeCallback { override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { Log.d(TAG, "liwei-------- onRecognizing: $sessionid") + pendingProcessJob?.cancel() if (recognizing.isNotEmpty()&&isKeepResult==true) { // 检测到语音,更新状态 _hasSpeechDetected.set(true) @@ -685,10 +687,13 @@ object AgentService : CoroutineScope { ) ) }else{ - text = recognizing + text = recognitionResult + recognizing + if(recognitionResult.isEmpty()){ + currsessionId = sessionid + } sendEvent( "recognizing", mapOf( - "sessionid" to sessionid, + "sessionid" to currsessionId, "text" to text, "language" to detectedLanguage ) @@ -730,14 +735,22 @@ object AgentService : CoroutineScope { if (currentRecognitionMode == "push_to_talk") { //按住说话 recognitionResult += result }else{ - sendEvent( - "recognition_result", mapOf( - "sessionid" to sessionid, - "text" to result, - "language" to detectedLanguage - ) - ) - processWithChatApi(sessionid,result) + recognitionResult += result + pendingProcessJob?.cancel() + pendingProcessJob = launch { + delay(1000) + if (recognitionResult.isNotEmpty()) { + sendEvent( + "recognition_result", mapOf( + "sessionid" to currsessionId, + "text" to recognitionResult, + "language" to detectedLanguage + ) + ) + processWithChatApi(currsessionId, recognitionResult) + recognitionResult = "" + } + } } }