From: luozheng <1732036298@qq.com> Date: Fri, 10 Oct 2025 08:13:52 +0000 (+0800) Subject: 解决蓝牙ai录音开启不了问题,解决蓝牙发送队列未创建问题 X-Git-Tag: V1.0.9_20251128_194606_LN~212^2~42 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=dbdf9eba74cdb83f3ecb256b95f9cc06572004c3;p=mirrors%2FFD230.git 解决蓝牙ai录音开启不了问题,解决蓝牙发送队列未创建问题 --- diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h index d90540f74..c5ea62451 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h @@ -11,6 +11,7 @@ extern "C" uint8_t getselect4gorbtai(void); void ble_AI_init(void); + void net4g_AI_init(void); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp index 8a95b42cc..74198fb87 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp @@ -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 diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp index b236bb1fc..e1e5e27d1 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -45,7 +45,6 @@ namespace OHOS #include #include #include - 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::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::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; diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 011853cfd..302115ca7 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -1011,6 +1011,7 @@ target = { 'DOWNLOAD_GNSS_SWITCH', 'SUPPORT_GYRO_SERVICE', 'GYRO_SH5001', + 'SUPPORT_AI_SERVICE', ], #添加自定义应用 'ram_component': [ diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp index 8c1a54be2..b13ebac55 100644 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp @@ -566,8 +566,7 @@ static int32_t ActivateAudioInterrupt(AudioSession &sessionId) } MEDIA_INFO_LOG("sessionId:%d", sessionId); g_captureInterruptListener = std::make_shared(); - 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"); diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleService.h b/code/sdk/zhihui/services/ble_service/bleservice/bleService.h index f7974c93a..b95066f1c 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleService.h +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleService.h @@ -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 diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index 8d9fdd2da..19d60e9ae 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -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()) {