소스 검색

成功打断,但是8次左右,系统会崩溃

xuxinyi 4 달 전
부모
커밋
5904f700a2
1개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 16 1
      main/application.cc

+ 16 - 1
main/application.cc

@@ -271,6 +271,7 @@ void Application::ToggleChatState() {
     }
 }
 
+//开启音频
 void Application::StartListening() {
     if (device_state_ == kDeviceStateActivating) {
         SetDeviceState(kDeviceStateIdle);
@@ -461,6 +462,7 @@ void Application::Start() {
             SetDeviceState(kDeviceStateIdle);
         });
     });
+    //后台控制指令
     protocol_->OnIncomingJson([this, display](const cJSON* root) {
         // Parse JSON data
         auto type = cJSON_GetObjectItem(root, "type");
@@ -853,8 +855,21 @@ void Application::SetDeviceState(DeviceState state) {
             display->SetStatus(Lang::Strings::SPEAKING);
             ResetDecoder();
             codec->EnableOutput(true);
+            //成功打断,但是8次左右,系统会崩溃
+            Schedule([this]() {
+                    if (device_state_ == kDeviceStateSpeaking) {
+                        background_task_->WaitForCompletion();
+                        if (keep_listening_) {
+                            protocol_->SendStartListening(kListeningModeAutoStop);
+                            // SetDeviceState(kDeviceStateListening);
+                            
+                        } else {
+                            SetDeviceState(kDeviceStateIdle);
+                        }
+                    }
+                });
 #if CONFIG_USE_AUDIO_PROCESSOR
-            audio_processor_.Stop();
+            // audio_processor_.Stop();
 #endif
             break;
         default: