From 3969ec170660eead550ef8a88659bc7f9038bd95 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 28 May 2025 10:42:03 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A04GAI=E7=9A=84Ui=E5=A4=84?= =?utf8?q?=E7=90=86=E9=80=BB=E8=BE=91=E5=BE=85=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 8 +++++ .../nativeui/aivoice/src/AiVoiceModel.cpp | 31 ++++++++++++++++++- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 7 +++++ .../peripheral/slip/cat1Service/cat1_ws.cpp | 14 ++++++--- .../peripheral/slip/cat1Service/cat1_ws.h | 20 ++++++++++++ 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h index f45155f05..5317eba88 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -118,6 +118,11 @@ namespace OHOS void SetIsLimitDisplayed(bool value); bool GetIsLimitDisplayed(void); + void SetAI_4G_state(bool state); + bool GetAI_4G_state(void); + void SetAI_BT_state(bool state); + bool GetAI_BT_state(void); + private: AiVoiceModel(); ~AiVoiceModel(); @@ -145,6 +150,9 @@ namespace OHOS int16_t curView{0}; bool isClickable{false}; bool isLimitDisplayed{false};//AI答案是否显示到极限了 + + bool AI_4G_state{false}; //4gAI状态 + bool AI_BT_state{false}; //蓝牙AI状态 }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index 41216d698..69f42333b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -28,6 +28,7 @@ #include #include "bleService.h" #include +#include "cat1_ws.h" namespace OHOS { // 声明定时器变量 @@ -165,7 +166,15 @@ namespace OHOS if (it != selectAiModelToTextId.end()) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] SelectAiModel = %d", it->second.second); - inquire_AI_is_ready(it->second.second); + if(GetAI_4G_state() == true) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] GetAI_4G_state = true"); + uapi_start_asr(); + } + else + { + inquire_AI_is_ready(it->second.second); + } } } @@ -625,6 +634,9 @@ namespace OHOS int32_t argc = 1; uint8_t *argv = (uint8_t *)"stop"; AudioCaptureSample(argc, (const char **)&argv); + if(GetAI_4G_state() == true){ + uapi_stop_asr(); + } uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP_AI);//TOOD* return; } @@ -1070,6 +1082,23 @@ namespace OHOS return ConfigModel::GetInstance()->GetSelectAiModel(); } + void AiVoiceModel::SetAI_4G_state(bool state) + { + AI_4G_state = state; + } + bool AiVoiceModel::GetAI_4G_state(void) + { + return AI_4G_state; + } + void AiVoiceModel::SetAI_BT_state(bool state) + { + AI_BT_state = state; + } + bool AiVoiceModel::GetAI_BT_state(void) + { + return AI_BT_state; + } + /*获取已选择的ai模型的textid*/ int AiVoiceModel::GetAiModelTextId() { diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 9a8bd3371..9ba9c85c4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -25,6 +25,8 @@ #include "bleService.h" #include "player/include/PlayersModel.h" +#include "cat1_ws.h" + namespace OHOS { #define BLE_CONNECT_INTERVAL_HIGH_AI 10 @@ -380,9 +382,14 @@ namespace OHOS bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "netWork4GState = %d,appBluetoothConnectState = %d", netWork4GState, appBluetoothConnectState); + //暂时4g可以用 + netWork4GState = true; + model->SetAI_4G_state(netWork4GState); + if (netWork4GState) // 1.手表4G网络正常 { // 通过4G调用大模型 + ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING } else if (appBluetoothConnectState) // 3.只有与APP蓝牙连接正常 { diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp index 606b4e6f0..e892084a5 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp @@ -919,9 +919,8 @@ char asr_recv_buf[1024]={0}; WebSocketClient *asr_client; -// - -void uapi_start_asr() +//查询是否可以对话 +void uapi_start_asr(void) { char *jsonString = "{\"header\":{\"event\":\"StartTranscription\",\"trace_id\": \ \"3fa6b9e6a30b407ea38ad7ae69e6c291\"},\"payload\":{\"format\":\"MP3\",\"sample_rate\":16000}}"; @@ -932,7 +931,8 @@ void uapi_start_asr() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ erro\n"); } -void uapi_stop_asr() +//停止对话 +void uapi_stop_asr(void) { char *jsonString ="{\"header\":{\"event\":\"StopTranscription\",\"trace_id\":\"3fa6b9e6a30b407ea38ad7ae69e6c291\"}}"; @@ -977,6 +977,7 @@ void record_test(void) fclose(fp); } #include "audio_capture_wrapper.h" +#include // {"status":20000000,"msg":"success","task_id":"80228c9f62821ffe3f867e1a5042d887","event":"TranscriptionStarted","result":null} // {"status":20000000, @@ -1030,7 +1031,10 @@ bool aer_result_analysis(char *buf) } if(strcmp(event_str,"TranscriptionStarted")==0) { - streamingRecordAndSend_AI(0); + //查询结果 + // streamingRecordAndSend_AI(0); + bool state = true; + SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool)); } cJSON_Delete(root); diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h new file mode 100644 index 000000000..9c16aca53 --- /dev/null +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h @@ -0,0 +1,20 @@ +#ifndef __CAT1_WS_H__ +#define __CAT1_WS_H__ +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +void uapi_start_asr(void); + +void uapi_stop_asr(void); + + + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif \ No newline at end of file -- 2.17.1