解决蓝牙ai录音开启不了问题,解决蓝牙发送队列未创建问题
authorluozheng <1732036298@qq.com>
Fri, 10 Oct 2025 08:13:52 +0000 (16:13 +0800)
committerluozheng <1732036298@qq.com>
Fri, 10 Oct 2025 08:13:52 +0000 (16:13 +0800)
code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h
code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/build/config/target_config/brandy/config.py
code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp
code/sdk/zhihui/services/ble_service/bleservice/bleService.h
code/sdk/zhihui/utils/custom_utils.c

index 8a95b42..74198fb 100644 (file)
@@ -2181,12 +2181,14 @@ extern "C"
 
     void ble_set_ai_Question_str_(char *buf)
     {
+        printf("ble_set_ai_Question_str_ %s\n",buf);
         OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf));
     }
 
     void ble_set_ai_Answer_str_(char *buf, uint8_t type)
     {
-        chat_filter_result_chars(buf);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble_set_ai_Answer_str_:%s,type:%d",buf,type);
+        // chat_filter_result_chars(buf);
         OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf), type);
     }
 
@@ -2206,6 +2208,22 @@ extern "C"
         bleInstruct_t.ble_app_reply = ble_app_reply_;
     }
 
+    /*
+     * WebSocket 聊天结果过滤回调包装,匹配 ws_register_chat_filter_callback 的签名
+     */
+    static void ws_chat_filter_cb_wrapper(char *result)
+    {
+        /* 复用现有过滤实现,忽略返回长度 */
+        chat_filter_result_chars(result);
+    }
+
+    void net4g_AI_init(void)
+    {
+        ws_register_chat_filter_callback(ws_chat_filter_cb_wrapper);
+        ws_register_ai_question_callback(ble_set_ai_Question_str_);
+        ws_register_ai_answer_callback(ble_set_ai_Answer_str_);
+    }
+
 #endif
 
 #ifdef __cplusplus
index b236bb1..e1e5e27 100644 (file)
@@ -45,7 +45,6 @@ namespace OHOS
 #include <asm/delay.h>
 #include <aivoice/include/AiVoiceModelC.h>
 #include <los_base.h>
-        extern void set_need_tts_reconnect(uint8_t flag);
 
         void remove_4GAI_vote(void)
         {
@@ -98,12 +97,12 @@ namespace OHOS
     void AiVoicePresenter::OnStart()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStart");
-        Presenter<AiVoiceView>::OnStart();
         ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
         // 开启一个60s取消长亮屏timer
         model->ai_start_screen60s_timer();
         add_4GAI_vote(); // 4g投票
 
+        net4g_AI_init();
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI);
         Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_ASSISTANT, 100);
     }
@@ -112,7 +111,6 @@ namespace OHOS
     void AiVoicePresenter::OnStop(void)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop start");
-        Presenter<AiVoiceView>::OnStop();
         ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
         model->StatusResume();
         model->AIVoice_StopTimer();
@@ -129,9 +127,6 @@ namespace OHOS
         uapi_stop_all_websocket_servers();
         uapi_destroy_all_websocket_servers();
 #endif
-        
-        // dinit_ai_task();
-        // ai_cleanup_resources();
 
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop end");
@@ -340,7 +335,6 @@ namespace OHOS
             break;
 
         case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
-            // set_need_tts_reconnect(0);                                 // 停止tts重连
             AiVoiceModel::GetInstance().ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
             AiVoiceModel::GetInstance().SetIsClickable(false);
             AiVoiceModel::GetInstance().SetIsLimitDisplayed(false);
@@ -364,10 +358,8 @@ namespace OHOS
             AiVoiceModel::GetInstance().start_ai_isready_timer();
             break;
         case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
-            // set_need_tts_reconnect(1); // 开始tts重连
             break;
         case AIVOICE_LISTENING_VIEWID:
-            // set_stop_send_ai_flag(0); // 开始发送AI数据
             AiVoiceModel::GetInstance().StartListenAndRecordingUserQuestion();
             AiVoiceModel::GetInstance().start_listening_timer();
             break;
index 011853c..302115c 100644 (file)
@@ -1011,6 +1011,7 @@ target = {
             'DOWNLOAD_GNSS_SWITCH',
             'SUPPORT_GYRO_SERVICE',
             'GYRO_SH5001',
+            'SUPPORT_AI_SERVICE',
         ],
         #添加自定义应用
        'ram_component': [
index 8c1a54b..b13ebac 100644 (file)
@@ -566,8 +566,7 @@ static int32_t ActivateAudioInterrupt(AudioSession &sessionId)
     }
     MEDIA_INFO_LOG("sessionId:%d", sessionId);
     g_captureInterruptListener = std::make_shared<CaptureInterruptListener>();
-    g_sample.interrupt = { g_streamType, sessionId, g_captureInterruptListener };
-    // g_sample.interrupt = { AUDIO_STREAM_VOICE_ASSISTANT, sessionId, g_captureInterruptListener };
+    g_sample.interrupt = { AUDIO_STREAM_VOICE_RECORD, sessionId, g_captureInterruptListener };
     
 
     if (g_amInstance.ActivateAudioInterrupt(g_sample.interrupt) == INTERRUPT_FAILED) {
@@ -634,8 +633,7 @@ int32_t AudioCaptureSample(int32_t argc, const char **argv)
     }
     audioCapturerInfo.sessionID = sessionId;
     audioCapturerInfo.inputSource = AUDIO_MIC;
-    audioCapturerInfo.streamType = g_streamType;
-    // audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_ASSISTANT;
+    audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_RECORD;
     ret = AudioCaptureSetInfo(audioCapturerInfo);
     if (ret != 0) {
         MEDIA_ERR_LOG("AudioCapture set failed");
index f7974c9..b95066f 100644 (file)
@@ -106,6 +106,7 @@ void AI_data_assembly(uint8_t type,uint8_t *buf,uint8_t aitype);
 
 void set_AI_interval(uint8_t data);
 
+errcode_t uapi_Ai_send_service_init(void);
 #ifdef __cplusplus
 }
 #endif
index 8d9fdd2..19d60e9 100644 (file)
@@ -549,6 +549,7 @@ bool start_custom_ble_service(void)
 #endif
 #endif 
     bluetooth_enable_all();
+    uapi_Ai_send_service_init();
 
     //if(!uapi_dev_runtime_get_saveele_status())
     {