|
|
@ -601,7 +601,7 @@ object AgentService : CoroutineScope { |
|
|
Log.d(TAG, "recognizeCallback") |
|
|
Log.d(TAG, "recognizeCallback") |
|
|
val success = azureAsrHelper?.setupEventListeners(object : |
|
|
val success = azureAsrHelper?.setupEventListeners(object : |
|
|
AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
AzureAsrHelper.ContinuousRecognizeCallback { |
|
|
override fun onRecognizing(sessiondid:String, recognizing: String, detectedLanguage: String) { |
|
|
override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { |
|
|
if (recognizing.isNotEmpty()&&isKeepResult==true) { |
|
|
if (recognizing.isNotEmpty()&&isKeepResult==true) { |
|
|
// 检测到语音,更新状态 |
|
|
// 检测到语音,更新状态 |
|
|
|
|
|
|
|
|
@ -645,17 +645,17 @@ object AgentService : CoroutineScope { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onResult(sessiondid:String,result: String, detectedLanguage: String) { |
|
|
override fun onResult(sessionid:String,result: String, detectedLanguage: String) { |
|
|
if (result.isNotEmpty()&&isKeepResult==true) {//加入是否结束要输出最后的结果判读 |
|
|
if (result.isNotEmpty()&&isKeepResult==true) {//加入是否结束要输出最后的结果判读 |
|
|
sendEvent( |
|
|
sendEvent( |
|
|
"recognition_result", mapOf( |
|
|
"recognition_result", mapOf( |
|
|
"sessiondid" to sessiondid, |
|
|
"sessionid" to sessionid, |
|
|
"text" to result, |
|
|
"text" to result, |
|
|
"language" to detectedLanguage |
|
|
"language" to detectedLanguage |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
processWithChatApi(sessiondid,result) |
|
|
processWithChatApi(sessionid,result) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -665,8 +665,8 @@ object AgentService : CoroutineScope { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onSessionStarted(sessiondid:String) { |
|
|
override fun onSessionStarted(sessionid:String) { |
|
|
sendEvent("recognition_started", mapOf("sessiondid" to sessiondid, "status" to "started")) |
|
|
sendEvent("recognition_started", mapOf("sessionid" to sessionid, "status" to "started")) |
|
|
// 使用模式感知的空闲检测启动方法 |
|
|
// 使用模式感知的空闲检测启动方法 |
|
|
audioPlayer?.playAudio(R.raw.start) |
|
|
audioPlayer?.playAudio(R.raw.start) |
|
|
|
|
|
|
|
|
@ -674,35 +674,35 @@ object AgentService : CoroutineScope { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onSessionStopped(sessiondid:String) { |
|
|
override fun onSessionStopped(sessionid:String) { |
|
|
sendEvent("recognition_stopped", mapOf("sessiondid" to sessiondid, "status" to "stopped")) |
|
|
sendEvent("recognition_stopped", mapOf("sessionid" to sessionid, "status" to "stopped")) |
|
|
_isRecognitionActive.set(false) |
|
|
_isRecognitionActive.set(false) |
|
|
stopIdleCheck() |
|
|
stopIdleCheck() |
|
|
audioPlayer?.playAudio(R.raw.stop) |
|
|
audioPlayer?.playAudio(R.raw.stop) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onCanceled(sessiondid: String,reason: String, errorDetails: String) { |
|
|
override fun onCanceled(sessionid: String,reason: String, errorDetails: String) { |
|
|
_isRecognitionActive.set(false) |
|
|
_isRecognitionActive.set(false) |
|
|
stopIdleCheck() |
|
|
stopIdleCheck() |
|
|
Log.d(TAG, "recognition_canceled:") |
|
|
Log.d(TAG, "recognition_canceled:") |
|
|
BleService.closeCodec() |
|
|
BleService.closeCodec() |
|
|
sendEvent( |
|
|
sendEvent( |
|
|
"recognition_canceled", mapOf( |
|
|
"recognition_canceled", mapOf( |
|
|
"sessiondid" to sessiondid, |
|
|
"sessionid" to sessionid, |
|
|
"reason" to reason, |
|
|
"reason" to reason, |
|
|
"details" to errorDetails |
|
|
"details" to errorDetails |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onError(sessiondid:String, code: Int, error: String) { |
|
|
override fun onError(sessionid:String, code: Int, error: String) { |
|
|
_isRecognitionActive.set(false) |
|
|
_isRecognitionActive.set(false) |
|
|
stopIdleCheck() |
|
|
stopIdleCheck() |
|
|
BleService.closeCodec() |
|
|
BleService.closeCodec() |
|
|
Log.d(TAG, "语音识别错误: $error") |
|
|
Log.d(TAG, "语音识别错误: $error") |
|
|
sendEvent( |
|
|
sendEvent( |
|
|
"error", mapOf( |
|
|
"error", mapOf( |
|
|
"sessiondid" to sessiondid, |
|
|
"sessionid" to sessionid, |
|
|
"code" to code, |
|
|
"code" to code, |
|
|
"message" to error |
|
|
"message" to error |
|
|
) |
|
|
) |
|
|
|