|
|
|
@ -346,18 +346,21 @@ object AgentService : CoroutineScope { |
|
|
|
sendEvent("recognition_started", mapOf("status" to "started")) |
|
|
|
startIdleCheck() |
|
|
|
audioPlayer?.playAudio(R.raw.start) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
override fun onSessionStopped() { |
|
|
|
sendEvent("recognition_stopped", mapOf("status" to "stopped")) |
|
|
|
|
|
|
|
isRecognitionActive = false |
|
|
|
stopIdleCheck() |
|
|
|
sendEvent("recognition_stopped", mapOf("status" to "stopped")) |
|
|
|
audioPlayer?.playAudio(R.raw.stop) |
|
|
|
} |
|
|
|
|
|
|
|
override fun onCanceled(reason: String, errorDetails: String) { |
|
|
|
isRecognitionActive = false |
|
|
|
stopIdleCheck() |
|
|
|
BleService.closeCodec() |
|
|
|
sendEvent("recognition_canceled", mapOf( |
|
|
|
"reason" to reason, |
|
|
|
"details" to errorDetails |
|
|
|
@ -367,6 +370,7 @@ object AgentService : CoroutineScope { |
|
|
|
override fun onError(error: String) { |
|
|
|
isRecognitionActive = false |
|
|
|
stopIdleCheck() |
|
|
|
BleService.closeCodec() |
|
|
|
FileLogger.e(TAG, "语音识别错误: $error") |
|
|
|
sendEvent("error", mapOf( |
|
|
|
"code" to "RECOGNITION_ERROR", |
|
|
|
@ -602,6 +606,7 @@ object AgentService : CoroutineScope { |
|
|
|
} |
|
|
|
|
|
|
|
override fun onComplete() { |
|
|
|
FileLogger.d(TAG, "AI完整回复: $responseBuilder") |
|
|
|
// 视情况决定是否朗读回复 |
|
|
|
if (speakResponse) { |
|
|
|
azureTtsHelper?.flushStream() |
|
|
|
@ -661,6 +666,7 @@ object AgentService : CoroutineScope { |
|
|
|
|
|
|
|
override fun onFunctionCallResult(functionCall: JSONObject, functionCallResult: JSONObject) { |
|
|
|
audioPlayer?.stopAudio() |
|
|
|
FileLogger.d(TAG, "mcp调用结果: $functionCallResult") |
|
|
|
sendEvent("function_call_result", mapOf( |
|
|
|
"function_call" to functionCall.toString(), |
|
|
|
"result" to functionCallResult.toString(), |
|
|
|
|