|
|
@ -130,6 +130,8 @@ object AgentService : CoroutineScope { |
|
|
|
|
|
|
|
|
//是否播放音乐中 |
|
|
//是否播放音乐中 |
|
|
private var isplaymusic = false; |
|
|
private var isplaymusic = false; |
|
|
|
|
|
//是否保留最终结果 |
|
|
|
|
|
private var isKeepResult = true; |
|
|
|
|
|
|
|
|
// 打断防抖相关 |
|
|
// 打断防抖相关 |
|
|
private var lastInterruptTime = 0L |
|
|
private var lastInterruptTime = 0L |
|
|
@ -265,6 +267,7 @@ object AgentService : CoroutineScope { |
|
|
*/ |
|
|
*/ |
|
|
fun dispose() { |
|
|
fun dispose() { |
|
|
try { |
|
|
try { |
|
|
|
|
|
BleService.closeCodec() |
|
|
stopRecognition() |
|
|
stopRecognition() |
|
|
stopTts() |
|
|
stopTts() |
|
|
stopAiStream() |
|
|
stopAiStream() |
|
|
@ -474,6 +477,7 @@ object AgentService : CoroutineScope { |
|
|
|
|
|
|
|
|
if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming) { |
|
|
if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming) { |
|
|
Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode") |
|
|
Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode") |
|
|
|
|
|
BleService.closeCodec() |
|
|
stopRecognition() |
|
|
stopRecognition() |
|
|
sendEvent( |
|
|
sendEvent( |
|
|
"auto_stop", |
|
|
"auto_stop", |
|
|
@ -516,13 +520,18 @@ object AgentService : CoroutineScope { |
|
|
* @param mode 识别模式:normal, ble_wakeup, phone_call, push_to_talk |
|
|
* @param mode 识别模式:normal, ble_wakeup, phone_call, push_to_talk |
|
|
*/ |
|
|
*/ |
|
|
fun startRecognition(isExternalActive: Boolean, mode: String = "normal"): Boolean { |
|
|
fun startRecognition(isExternalActive: Boolean, mode: String = "normal"): Boolean { |
|
|
|
|
|
if(isExternalActive){ |
|
|
|
|
|
isKeepResult = false |
|
|
|
|
|
BleService.openEncoder()//不发指令。只是录制opus |
|
|
|
|
|
} |
|
|
if (!isInitialized) { |
|
|
if (!isInitialized) { |
|
|
Log.d(TAG, "服务未初始化") |
|
|
Log.d(TAG, "服务未初始化") |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
Log.d("TAG", "开始语音识别startRecognition?") |
|
|
Log.d("TAG", "开始语音识别startRecognition?") |
|
|
stopRecognition() |
|
|
stopRecognition() |
|
|
BleService.openEncoder() |
|
|
|
|
|
|
|
|
|
|
|
// if (isRecognitionActive&&audioSourceType==AzureAsrHelper.AudioSourceType.MICROPHONE){ |
|
|
// if (isRecognitionActive&&audioSourceType==AzureAsrHelper.AudioSourceType.MICROPHONE){ |
|
|
// Log.d(TAG, "开始语音识别stopRecognition") |
|
|
// Log.d(TAG, "开始语音识别stopRecognition") |
|
|
// // BleService.closeCodec() |
|
|
// // BleService.closeCodec() |
|
|
@ -559,6 +568,9 @@ object AgentService : CoroutineScope { |
|
|
AzureAsrHelper.AudioSourceType.MICROPHONE |
|
|
AzureAsrHelper.AudioSourceType.MICROPHONE |
|
|
} |
|
|
} |
|
|
Log.d("TAG", "azureAsrHelper?.startContinuousRecognition") |
|
|
Log.d("TAG", "azureAsrHelper?.startContinuousRecognition") |
|
|
|
|
|
if(isExternalActive){ |
|
|
|
|
|
isKeepResult = true |
|
|
|
|
|
} |
|
|
azureAsrHelper?.startContinuousRecognition(audioSourceType) |
|
|
azureAsrHelper?.startContinuousRecognition(audioSourceType) |
|
|
|
|
|
|
|
|
// 根据模式启动相应的空闲检测 |
|
|
// 根据模式启动相应的空闲检测 |
|
|
@ -630,7 +642,7 @@ object AgentService : CoroutineScope { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onResult(result: String, detectedLanguage: String) { |
|
|
override fun onResult(result: String, detectedLanguage: String) { |
|
|
if (result.isNotEmpty()) { |
|
|
if (result.isNotEmpty()&&isKeepResult==true) {//加入是否结束要输出最后的结果判读 |
|
|
sendEvent( |
|
|
sendEvent( |
|
|
"recognition_result", mapOf( |
|
|
"recognition_result", mapOf( |
|
|
"text" to result, |
|
|
"text" to result, |
|
|
@ -709,11 +721,9 @@ object AgentService : CoroutineScope { |
|
|
Log.d(TAG, "停止语音识别,当前模式: $currentRecognitionMode") |
|
|
Log.d(TAG, "停止语音识别,当前模式: $currentRecognitionMode") |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|
|
|
_isRecognitionActive.set(false) |
|
|
azureAsrHelper?.stopContinuousRecognition() |
|
|
azureAsrHelper?.stopContinuousRecognition() |
|
|
BleService.closeCodec() |
|
|
|
|
|
_isRecognitionActive.set(false) |
|
|
|
|
|
stopIdleCheck() |
|
|
stopIdleCheck() |
|
|
|
|
|
|
|
|
// 重置识别模式 |
|
|
// 重置识别模式 |
|
|
currentRecognitionMode = "normal" |
|
|
currentRecognitionMode = "normal" |
|
|
return |
|
|
return |
|
|
@ -721,7 +731,6 @@ object AgentService : CoroutineScope { |
|
|
Log.e(TAG, "停止语音识别异常: ${e.message}") |
|
|
Log.e(TAG, "停止语音识别异常: ${e.message}") |
|
|
_isRecognitionActive.set(false) |
|
|
_isRecognitionActive.set(false) |
|
|
stopIdleCheck() |
|
|
stopIdleCheck() |
|
|
|
|
|
|
|
|
// 重置识别模式 |
|
|
// 重置识别模式 |
|
|
currentRecognitionMode = "normal" |
|
|
currentRecognitionMode = "normal" |
|
|
return |
|
|
return |
|
|
@ -1055,6 +1064,7 @@ object AgentService : CoroutineScope { |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
if (name == "exit_interaction") { |
|
|
if (name == "exit_interaction") { |
|
|
|
|
|
BleService.closeCodec() |
|
|
stopRecognition() |
|
|
stopRecognition() |
|
|
} |
|
|
} |
|
|
} catch (e: Exception) { |
|
|
} catch (e: Exception) { |
|
|
|