|
|
@ -151,6 +151,7 @@ object AgentService : CoroutineScope { |
|
|
private var isKeepResult = true; |
|
|
private var isKeepResult = true; |
|
|
// 识别结果 |
|
|
// 识别结果 |
|
|
private var recognitionResult = "" |
|
|
private var recognitionResult = "" |
|
|
|
|
|
private var pendingProcessJob: Job? = null |
|
|
|
|
|
|
|
|
// 打断防抖相关 |
|
|
// 打断防抖相关 |
|
|
private var lastInterruptTime = 0L |
|
|
private var lastInterruptTime = 0L |
|
|
@ -669,6 +670,7 @@ object AgentService : CoroutineScope { |
|
|
AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { |
|
|
override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { |
|
|
Log.d(TAG, "liwei-------- onRecognizing: $sessionid") |
|
|
Log.d(TAG, "liwei-------- onRecognizing: $sessionid") |
|
|
|
|
|
pendingProcessJob?.cancel() |
|
|
if (recognizing.isNotEmpty()&&isKeepResult==true) { |
|
|
if (recognizing.isNotEmpty()&&isKeepResult==true) { |
|
|
// 检测到语音,更新状态 |
|
|
// 检测到语音,更新状态 |
|
|
_hasSpeechDetected.set(true) |
|
|
_hasSpeechDetected.set(true) |
|
|
@ -685,10 +687,13 @@ object AgentService : CoroutineScope { |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
}else{ |
|
|
}else{ |
|
|
text = recognizing |
|
|
text = recognitionResult + recognizing |
|
|
|
|
|
if(recognitionResult.isEmpty()){ |
|
|
|
|
|
currsessionId = sessionid |
|
|
|
|
|
} |
|
|
sendEvent( |
|
|
sendEvent( |
|
|
"recognizing", mapOf( |
|
|
"recognizing", mapOf( |
|
|
"sessionid" to sessionid, |
|
|
"sessionid" to currsessionId, |
|
|
"text" to text, |
|
|
"text" to text, |
|
|
"language" to detectedLanguage |
|
|
"language" to detectedLanguage |
|
|
) |
|
|
) |
|
|
@ -730,14 +735,22 @@ object AgentService : CoroutineScope { |
|
|
if (currentRecognitionMode == "push_to_talk") { //按住说话 |
|
|
if (currentRecognitionMode == "push_to_talk") { //按住说话 |
|
|
recognitionResult += result |
|
|
recognitionResult += result |
|
|
}else{ |
|
|
}else{ |
|
|
sendEvent( |
|
|
recognitionResult += result |
|
|
"recognition_result", mapOf( |
|
|
pendingProcessJob?.cancel() |
|
|
"sessionid" to sessionid, |
|
|
pendingProcessJob = launch { |
|
|
"text" to result, |
|
|
delay(1000) |
|
|
"language" to detectedLanguage |
|
|
if (recognitionResult.isNotEmpty()) { |
|
|
) |
|
|
sendEvent( |
|
|
) |
|
|
"recognition_result", mapOf( |
|
|
processWithChatApi(sessionid,result) |
|
|
"sessionid" to currsessionId, |
|
|
|
|
|
"text" to recognitionResult, |
|
|
|
|
|
"language" to detectedLanguage |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
processWithChatApi(currsessionId, recognitionResult) |
|
|
|
|
|
recognitionResult = "" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|