From f572fb5de421014d1bc0579a314166f703d59275 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 14 Mar 2025 09:51:08 +0800 Subject: [PATCH] =?utf8?q?1.=E8=A7=A3=E5=86=B3=E4=B8=8A=E6=AC=A1=E5=AF=B9?= =?utf8?q?=E8=AF=9D=E7=9A=84=E9=97=AE=E9=A2=98=E4=BC=9A=E6=8B=BC=E6=8E=A5?= =?utf8?q?=E5=88=B0=E4=B8=8B=E6=AC=A1=E5=AF=B9=E8=AF=9D=E7=9A=84=E9=97=AE?= =?utf8?q?=E9=A2=98=E4=B8=ADbug=202.=E8=A7=A3=E5=86=B3AI=E5=A4=A7=E6=A8=A1?= =?utf8?q?=E5=9E=8B=E5=AF=B9=E8=AF=9D=E5=8F=AA=E4=BC=9A=E6=98=BE=E7=A4=BA?= =?utf8?q?=E9=97=AE=E9=A2=98=E8=80=8C=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=AD=94?= =?utf8?q?=E6=A1=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 5 ++- .../nativeui/aivoice/src/AiVoiceModel.cpp | 37 +++++++++++++++---- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 6 +-- .../service/ble_service/bleservice/bleEvent.c | 5 +++ .../service/ble_service/bleservice/bleEvent.h | 2 + .../ble_service/bleservice/bleService.c | 5 ++- .../ble_service/bleservice/bleService.h | 3 +- .../sample/wrapper/audio_capture_wrapper.cpp | 14 +++++-- .../sample/wrapper/audio_capture_wrapper.h | 2 +- 9 files changed, 57 insertions(+), 22 deletions(-) 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 ed34b5125..6a393a3b3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:43 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-12 11:10:53 + * @LastEditTime: 2025-03-13 16:02:18 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h */ #ifndef AI_VOICE_MODEL_H @@ -66,7 +66,7 @@ namespace OHOS uint8_t GetChatContentListCount(void); // 更新和清空问题及回答 - void RemoveLastTwoItemsOrClear(); + bool RemoveLastTwoItemsOrClear(); bool UpdateUserQuestionStr(void); bool UpdateAiAnswerStr(void); void ClearQuestionAndAiAnswerStr(void); @@ -77,6 +77,7 @@ namespace OHOS std::string GetAiAnswerStr(void); void SetAiAnswerStrStr(std::string str); void SetAiAnswerStrStr(std::string str,uint8_t type); + uint8_t GetCurUsingAiModelType(void); // 文件检查和AI状态管理 void CheckFileAndSendAIIsReady(); 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 cbd75623b..110c808e8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:50 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-12 11:24:13 + * @LastEditTime: 2025-03-14 09:43:46 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -164,11 +164,22 @@ namespace OHOS auto it = selectAiModelToTextId.find(GetSelectAiModel()); if (it != selectAiModelToTextId.end()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] SelectAiModel = %d", it->second.second); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] SelectAiModel = %d", it->second.second); inquire_AI_is_ready(it->second.second); } } + // 获取当前正在使用的AI模型 + uint8_t AiVoiceModel::GetCurUsingAiModelType(void) + { + auto it = selectAiModelToTextId.find(GetSelectAiModel()); + if (it != selectAiModelToTextId.end()) + { + return it->second.second; + } + return 0; + } + /*取消当前AI对话*/ void AiVoiceModel::CancelCurAIChat(void) { @@ -298,14 +309,14 @@ namespace OHOS } // 函数定义:移除列表的最后两项或清空列表 - void AiVoiceModel::RemoveLastTwoItemsOrClear() + bool AiVoiceModel::RemoveLastTwoItemsOrClear() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::RemoveLastTwoItemsOrClear"); AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance(); if (p_AivoiceReturnResultTextView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!!"); - return; + return false; } // 获取适配器 AivoiceChatContentListAdapter *adapter = p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter(); @@ -329,6 +340,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listSize = %d", listSize); ChatContentListCount -= (listSize < 2 ? listSize : 2); } + return true; } /* 更新用户问题字符串 */ @@ -336,7 +348,11 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateUserQuestionStr"); - RemoveLastTwoItemsOrClear(); + if(!RemoveLastTwoItemsOrClear()) + { + return false; + } + if (!AddUserQuestionToChatItems()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!"); @@ -440,7 +456,9 @@ namespace OHOS usleep(50000); // 延时等待创建完成,0.05秒 } /* -------------------------------------------------------------------------- */ - userQuestionStr += str; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "传入的问题:%s",str.c_str()); + userQuestionStr = str; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "拼接的问题:%s",userQuestionStr.c_str()); /* -------------------------------------------------------------------------- */ SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0); } @@ -484,6 +502,7 @@ namespace OHOS } } aiAnswerStr += str; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str()); SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); } @@ -506,7 +525,7 @@ namespace OHOS { #endif int32_t AudioCaptureSample(int32_t argc, const char *argv[]); - int32_t streamingRecordAndSend_AI(void); + int32_t streamingRecordAndSend_AI(int type); #define IS_SUPPORT_REALTIME_RECORD_SEND_AI 1 //是否支持实时发送录音数据 #ifdef __cplusplus }; @@ -526,7 +545,9 @@ namespace OHOS (view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->IsVisible())) { #if IS_SUPPORT_REALTIME_RECORD_SEND_AI - streamingRecordAndSend_AI();//实时发送录音数据 + int type = GetCurUsingAiModelType(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "type = %d", type); + streamingRecordAndSend_AI(type);//实时发送录音数据 #else std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath(); if (uapi_delete_files(audioPath.c_str())) // 先删除文件 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 a9961c1dd..d22a5c106 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-12 10:45:44 + * @LastEditTime: 2025-03-13 11:52:43 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -320,7 +320,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat"); AiVoiceModel::GetInstance().CancelCurAIChat(); - AiVoiceModel::GetInstance().sendAIIsReady(); + // AiVoiceModel::GetInstance().sendAIIsReady(); PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐 PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐 } @@ -558,7 +558,7 @@ namespace OHOS if (isScroll) { // 监听,让List实现滚动 - AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-150); + AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-120); isScroll = false; } } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 05974aad5..fc9fdb4c5 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -360,6 +360,11 @@ static uint8_t Calculate_CRC(uint8_t *data,uint16_t len)//计算20byte return crcbuf; } +uint8_t Calculate_CRC_AI(uint8_t *data,uint16_t len) +{ + return Calculate_CRC(data,len); +} + static uint8_t Calculate_CRC_Big(uint8_t *data,uint16_t len)//计算20byte { uint8_t crcbuf = 0; diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h index e985db45c..90bccfa5c 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -825,6 +825,8 @@ void inquire_AI_is_ready(uint8_t type); void cancel_AI_cur_chat(void); void cancel_AI_cur_chat_(void); +uint8_t Calculate_CRC_AI(uint8_t *data,uint16_t len); + void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue); bool get_ctkd_flag(void); diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 38882d80f..1f0930e29 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -2440,7 +2440,7 @@ errcode_t uapi_Ai_send_service_init(void) uint32_t send_msg_data_into_Ai_msg_queue_count=0; -void AI_data_assembly(uint8_t type,uint8_t *buf) +void AI_data_assembly(uint8_t type,uint8_t *buf,uint8_t aitype) { memset_s(buf,ble_nus_max_data_len,0,19); @@ -2457,7 +2457,8 @@ void AI_data_assembly(uint8_t type,uint8_t *buf) memcpy(buf + 11, &temp_data, 4); // 数据包ID memcpy(buf + 15, &temp_data, 2); // 包数据长度 - buf[18] = 0; // 计算CRC + buf[17] = aitype; + buf[18] = Calculate_CRC_AI(buf,18);; // 计算CRC } static uint8_t g_blesrv_mail_flag=0; diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h index 3b0c4c09b..5b7eaf73f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h @@ -100,8 +100,7 @@ void Check_ble_adv_status(void); int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type); -void AI_data_assembly(uint8_t type,uint8_t *buf); - +void AI_data_assembly(uint8_t type,uint8_t *buf,uint8_t aitype); void set_AI_interval(uint8_t data); 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 9f4145360..791048adf 100755 --- 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 @@ -417,9 +417,10 @@ EXIT: } /* ------------------------------- AI录音数据上传接口 ------------------------------- */ -#define AI_RECORD_TEST 1 //若需要调试可以打开该宏 +#define AI_RECORD_TEST 0 //若需要调试可以打开该宏 #include "bleService.h" static uint32_t AI_audio_size=0; +static uint8_t Cur_AI_Model= 0; static void* AudioCaptureProcess_AI(void* arg) { #if AI_RECORD_TEST @@ -430,7 +431,7 @@ static void* AudioCaptureProcess_AI(void* arg) g_audioSourceProcessInput.bThreadRun = true; uint8_t start_data[19]={0}; - AI_data_assembly(1,start_data); + AI_data_assembly(1,start_data, Cur_AI_Model); send_msg_data_into_Ai_msg_queue((void *)start_data,19,1); AI_audio_size=0; @@ -460,6 +461,7 @@ static void* AudioCaptureProcess_AI(void* arg) if (readCnt++ > READ_COUNT_MAX) { break; } + #if AI_RECORD_TEST if (readCnt % GET_AUDIO_TIME_INTERVAL_TIMES == 0) { if (g_audioCap->GetAudioTime(timeStamp, Timestamp::Timebase::MONOTONIC)) { MEDIA_INFO_LOG("read %d frames timestamp seconds:%ld, nanoseconds:%ld", @@ -467,13 +469,14 @@ static void* AudioCaptureProcess_AI(void* arg) } } MEDIA_INFO_LOG("audioCap Read readCnt = %d, size = %d", readCnt, ret); + #endif } #if AI_RECORD_TEST fclose(pfd); #endif MEDIA_ERR_LOG("AI_audio_size %d",AI_audio_size); - AI_data_assembly(0,start_data); + AI_data_assembly(0,start_data,Cur_AI_Model); send_msg_data_into_Ai_msg_queue((void *)start_data,19,2); @@ -482,10 +485,11 @@ static void* AudioCaptureProcess_AI(void* arg) return NULL; } -int32_t streamingRecordAndSend_AI(void) +int32_t streamingRecordAndSend_AI(int type) { const char *argv[] = {"01", "sbc", "16000", "1", "16", "/user/aiRecord.sbc"}; int32_t argc = 6; + Cur_AI_Model = type; if (g_audioSourceProcessInput.bThreadRun) { return HandleAudioCaptureCmd(argc, argv); } @@ -534,7 +538,9 @@ int32_t streamingRecordAndSend_AI(void) audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_RECORD; ret = AudioCaptureSetInfo(audioCapturerInfo); if (ret != 0) { + #if AI_RECORD_TEST fclose(pfd); + #endif g_audioCap.reset(); (void)g_amInstance.DeactivateAudioInterrupt(g_sample.interrupt); goto EXIT; diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h index 9c06a9ffe..fbc42bd57 100755 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h @@ -16,7 +16,7 @@ extern "C" { int32_t AudioCaptureSample(int32_t argc, const char *argv[]); -int32_t streamingRecordAndSend_AI(void); +int32_t streamingRecordAndSend_AI(int type); #ifdef __cplusplus }; -- 2.17.1