Browse Source

上传代码

weicu
liwei1dao 12 months ago
parent
commit
f94675ab89
  1. 22
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  2. 2
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt

22
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -480,13 +480,14 @@ object AgentService : CoroutineScope {
"phone_call" -> { "phone_call" -> {
// 通话模式:禁用空闲检测,保持持续激活 // 通话模式:禁用空闲检测,保持持续激活
Log.d(TAG, "通话模式:禁用空闲检测") Log.d(TAG, "通话模式:禁用空闲检测")
startIdleCheck(mode,maxIdleSeconds)
return return
} }
else -> { else -> {
// 未知模式:使用默认的空闲检测 // 未知模式:使用默认的空闲检测
Log.w(TAG, "未知识别模式: $mode,使用默认空闲检测") Log.w(TAG, "未知识别模式: $mode,使用默认空闲检测")
startIdleCheck(maxIdleSeconds) startIdleCheck(mode,maxIdleSeconds)
} }
} }
} }
@ -494,7 +495,7 @@ object AgentService : CoroutineScope {
/** /**
* 启动空闲检测 * 启动空闲检测
*/ */
private fun startIdleCheck(idleSeconds: Int = maxIdleSeconds) { private fun startIdleCheck(mode: String,idleSeconds: Int = maxIdleSeconds) {
stopIdleCheck() // 先停止现有的检查 stopIdleCheck() // 先停止现有的检查
if (!isRecognitionActive) return if (!isRecognitionActive) return
@ -503,8 +504,8 @@ object AgentService : CoroutineScope {
idleCheckJob = launch { idleCheckJob = launch {
try { try {
delay(idleSeconds * 1000L) delay(idleSeconds * 1000L)
Log.d(TAG, "空闲检测触发自动停止,isActive: $isActive, isRecognitionActive: $isRecognitionActive, isTtsSpeaking: $isTtsSpeaking, isAiStreaming: $isAiStreaming, mode: $mode")
if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming) { if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming && mode != "phone_call") {
Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode") Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode")
BleService.closeCodec() BleService.closeCodec()
stopRecognition() stopRecognition()
@ -517,6 +518,10 @@ object AgentService : CoroutineScope {
) )
) )
} }
if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming && mode == "phone_call") {
Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode")
startRecognition(false, mode)
}
} catch (e: CancellationException) { } catch (e: CancellationException) {
// 协程被取消,正常行为 // 协程被取消,正常行为
} catch (e: Exception) { } catch (e: Exception) {
@ -531,6 +536,7 @@ object AgentService : CoroutineScope {
private fun stopIdleCheck() { private fun stopIdleCheck() {
idleCheckJob?.cancel() idleCheckJob?.cancel()
idleCheckJob = null idleCheckJob = null
Log.d(TAG, "空闲检测已停止")
} }
/** /**
@ -643,11 +649,9 @@ object AgentService : CoroutineScope {
override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) {
if (recognizing.isNotEmpty()&&isKeepResult==true) { if (recognizing.isNotEmpty()&&isKeepResult==true) {
// 检测到语音,更新状态 // 检测到语音,更新状态
_hasSpeechDetected.set(true)
_hasSpeechDetected.set(true) Log.d(TAG, "ai识别中重置定时器")
restartIdleCheck()
Log.d(TAG, "ai识别中重置定时器")
restartIdleCheck()
sendEvent( sendEvent(

2
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt

@ -1006,7 +1006,7 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin {
val pcmData = extractPcmFromWav(audioData) val pcmData = extractPcmFromWav(audioData)
if (pcmData.isNotEmpty()) { if (pcmData.isNotEmpty()) {
FileLogger.d(tag, "提取PCM数据,大小=${pcmData.size}字节") FileLogger.d(tag, "提取PCM数据,大小=${pcmData.size}字节")
BleService.writeExternalRightAudioData(pcmData) BleService.writeExternalAudioData(pcmData)
} }
else { else {
FileLogger.e(tag, "提取PCM数据失败,音频数据可能不是WAV格式") FileLogger.e(tag, "提取PCM数据失败,音频数据可能不是WAV格式")

Loading…
Cancel
Save