From: luozheng <1732036298@qq.com> Date: Thu, 12 Jun 2025 02:02:14 +0000 (+0800) Subject: 4GAIUI提交 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=31b182b1ea59037c1e1772b31ac73f3f2536be2b;p=mirrors%2FFD230.git 4GAIUI提交 --- 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 4526dec53..9240d8075 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -112,6 +112,9 @@ namespace OHOS void start_ai4g_connect_timer(uint32_t interval = 1000); void stop_ai4g_connect_timer(void); + void start_ai4g_tts_play_timer(uint32_t interval = 1000); + void stop_ai4g_tts_play_timer(void); + void SetSelectAiModel(int index); int GetSelectAiModel(void); int GetAiModelTextId(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModelC.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModelC.h new file mode 100644 index 000000000..be87d5074 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModelC.h @@ -0,0 +1,19 @@ +#ifndef AI_VOICE_MODELC_H +#define AI_VOICE_MODELC_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +#include + + uint8_t getselect4gorbtai(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif \ No newline at end of file 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 76cf73d65..d68303fd4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -6,6 +6,7 @@ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" +#include "aivoice/include/AiVoiceModelC.h" #include "aivoice/include/AiVoicePresenter.h" #include "aivoice/include/AiVoiceView.h" #include "aivoice/include/AivoiceReturnResultTextView.h" @@ -30,6 +31,7 @@ #include #include "cat1_ws.h" #include "custom_runtime.h" +#include "voice_call_volte_sample_wrapper.h" namespace OHOS { // 声明定时器变量 @@ -548,6 +550,7 @@ namespace OHOS { if (view_ != nullptr) { + start_ai4g_tts_play_timer();//开启一个定时器,用于播放tts音频 if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()) { if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串 @@ -614,7 +617,6 @@ namespace OHOS #endif int32_t AudioCaptureSample(int32_t argc, const char *argv[]); int32_t streamingRecordAndSend_AI(int type); - void is_4g_enable_AI(int enable); #define IS_SUPPORT_REALTIME_RECORD_SEND_AI 1 // 是否支持实时发送录音数据 #ifdef __cplusplus }; @@ -636,8 +638,14 @@ namespace OHOS #if IS_SUPPORT_REALTIME_RECORD_SEND_AI int type = GetCurUsingAiModelType(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "type = %d", type); - is_4g_enable_AI(GetSelect4gorbt()); - streamingRecordAndSend_AI(type); // 实时发送录音数据 + if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT) + { + streamingRecordAndSend_AI(type); // 实时发送录音数据 + } + else if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) + { + startAudioCaptureTask(); + } #else std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath(); if (uapi_delete_files(audioPath.c_str())) // 先删除文件 @@ -669,10 +677,14 @@ namespace OHOS if (GetSelect4gorbt() == AI_SELECT_4G) // 选的是4G需要关闭asr { uapi_stop_asr(); + stop_AudioCaptureProcess_AI(); + } + else if(GetSelect4gorbt() == AI_SELECT_BT) + { + int32_t argc = 1; + uint8_t *argv = (uint8_t *)"stop"; + AudioCaptureSample(argc, (const char **)&argv); } - int32_t argc = 1; - uint8_t *argv = (uint8_t *)"stop"; - AudioCaptureSample(argc, (const char **)&argv); uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP_AI); // TOOD* return; } @@ -873,8 +885,10 @@ namespace OHOS { // 60s后息屏停止定时 AiVoiceModel::GetInstance().ai_stop_screen60s_timer(); - // 取消常亮屏 - ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); + if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT) + { + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消常亮屏 + } } } static void ai_start_screen60s_timer_callback(int data) @@ -1117,7 +1131,8 @@ namespace OHOS /* -------------------------------------------------------------------------- */ static osTimerId_t g_ai4g_is_suc_connected_Handle = nullptr; // 处理AI4G连接定时器 - static int8_t AI4G_IS_SUC_CON_TIMEOUT = 20; // 20s钟超时 + static uint8_t AI4G_IS_SUC_CON_TIME = 25; + static int8_t AI4G_IS_SUC_CON_TIMEOUT = AI4G_IS_SUC_CON_TIME; // AI4G_IS_SUC_CON_TIME秒超时 static void AI4G_IS_SUC_CON_CallbackProc(int data) { AiVoiceView *view_ = AiVoiceView::GetInstance(); @@ -1138,8 +1153,15 @@ namespace OHOS { if (view_ != nullptr && p_AiVoicePresenter != nullptr) { - if (AiVoiceModel::GetInstance().GetInit_4gai_task()) + uint8_t asr_state = 0; + uint8_t chat_state = 0; + asr_state = get_ai_asr_service_init_flag(); + chat_state = get_ai_chat_service_init_flag(); + if (asr_state == 1 && chat_state == 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "4gAi服务初始化成功"); + bool state = true; + SendMsgToUIService(UI_4G_AI_INIT_STAUS, 0, &state, sizeof(bool)); uapi_start_asr(); AiVoiceModel::GetInstance().stop_ai4g_connect_timer(); p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODE_CONNECTING); @@ -1203,7 +1225,91 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); } g_ai4g_is_suc_connected_Handle = nullptr; - AI4G_IS_SUC_CON_TIMEOUT = 20; + AI4G_IS_SUC_CON_TIMEOUT = AI4G_IS_SUC_CON_TIME; + } + } + + /* -------------------------------- tts播放定时器 -------------------------------- */ + static osTimerId_t g_ai4g_is_start_tts_play_Handle = nullptr; + static uint8_t AI4G_IS_START_TTS_PLAY_TIME = 1; + + static void AI4G_IS_START_TTS_CallbackProc(int data) + { + if (AI4G_IS_START_TTS_PLAY_TIME <= 0) + { + AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); + std::string str = AiVoiceModel::GetInstance().GetAiAnswerStr(); + // 移除所有换行符(包括 '\n' 和 '\r') + str.erase( + std::remove(str.begin(), str.end(), '\n'), + str.end() + ); + str.erase( + std::remove(str.begin(), str.end(), '\r'), + str.end() + ); + uapi_start_tts_single_txt((char *)str.c_str()); + } + } + + static void AI4G_IS_START_TTS_Callback(int data) + { + AI4G_IS_START_TTS_PLAY_TIME--; + AI4G_IS_START_TTS_CallbackProc(data); + // GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI4G_IS_START_TTS_CallbackProc, data)); + } + + void AiVoiceModel::start_ai4g_tts_play_timer(uint32_t interval) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_ai_isready_timer"); + AI4G_IS_START_TTS_PLAY_TIME = 1; + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_ai4g_is_start_tts_play_Handle != nullptr) + { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); + return; + } + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_ai4g_is_start_tts_play_Handle = osTimerNew((osTimerFunc_t)AI4G_IS_START_TTS_Callback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_ai4g_is_start_tts_play_Handle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); + return; + } + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_ai4g_is_start_tts_play_Handle, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + if (g_ai4g_is_start_tts_play_Handle != nullptr) + { + ret = osTimerDelete(g_ai4g_is_start_tts_play_Handle); + } + g_ai4g_is_start_tts_play_Handle = nullptr; + return; + } + return; + } + + void AiVoiceModel::stop_ai4g_tts_play_timer(void) + { + // 检查定时器是否存在 + if (g_ai4g_is_start_tts_play_Handle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::stop_ai_isready_timer"); + osTimerStop(g_ai4g_is_start_tts_play_Handle); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_ai4g_is_start_tts_play_Handle); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_ai4g_is_start_tts_play_Handle = nullptr; + AI4G_IS_START_TTS_PLAY_TIME = 1; } } @@ -1310,3 +1416,24 @@ namespace OHOS } } + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif /* __cplusplus */ +#endif /* __cplusplus */ + uint8_t getselect4gorbtai(void) // 获取AI模型选择的是4G还是蓝牙 + { + if (OHOS::AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) + { + return 1; + } + return 0; + } + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ \ No newline at end of file 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 8b7012d36..f7572ea3d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -37,6 +37,7 @@ namespace OHOS #include "pm.h" #include "pm_veto.h" +#include void remove_4GAI_vote(void) { @@ -128,6 +129,7 @@ namespace OHOS model->stop_listening_timer(); model->stop_ai_isready_timer(); model->stop_ai4g_connect_timer(); + model->stop_ai4g_tts_play_timer(); remove_4GAI_vote();//移除4g投票 uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW); @@ -385,17 +387,20 @@ namespace OHOS if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题 { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat"); + PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐 + PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐 if (model->GetSelect4gorbt() == AI_SELECT_4G) { uapi_start_asr(); + usleep(50000); + ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID,AIVOICE_AIMODE_CONNECTING); + return true; } else if (model->GetSelect4gorbt() == AI_SELECT_BT) { AiVoiceModel::GetInstance().CancelCurAIChat(); // AiVoiceModel::GetInstance().sendAIIsReady(); } - PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐 - PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐 } ChangeViewAndLogicOperator(it->second.first, it->second.second); return true; @@ -449,9 +454,9 @@ namespace OHOS { // 通过4G调用大模型 model->SetSelect4gorbt(AI_SELECT_4G); + init_ai_task(); if (!model->GetInit_4gai_task()) { - init_ai_task(); model->start_ai4g_connect_timer(); ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING } @@ -483,9 +488,9 @@ namespace OHOS { // 通过4G调用大模型 model->SetSelect4gorbt(AI_SELECT_4G); + init_ai_task(); if (!model->GetInit_4gai_task()) { - init_ai_task(); model->start_ai4g_connect_timer(); ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING } @@ -582,6 +587,11 @@ namespace OHOS /*连接超时界面右滑退到AI对话界面*/ ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_STARTCHAT_VIEWID); } + else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_SELECT_VIEW)) + { + /*连接超时界面右滑退到AI对话界面*/ + ChangeViewAndLogicOperator(AIVOICE_SELECT_VIEW, AIVOICE_STARTCHAT_VIEWID); + } AiVoicePresenter::X_DRAG_FLAG = false; } else if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT && event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) /*上滑*/ 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 2313bbb57..335234188 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -47,8 +47,8 @@ extern "C" { #include "BluetoothWrapper.h" #endif #include "custom_save_runtime.h" - - +#include "aivoice/include/AiVoiceModelC.h" +#include "voice_call_volte_sample_wrapper.h" // extern void bts_data_to_uuid_len2(uint16_t uuid_data, bt_uuid_t *out_uuid); // extern void bts_init_128bit_uuid(const bt_uuid_t *uuid); // #include "ble_hid_take_photo_server.h" @@ -2353,7 +2353,6 @@ void send_Ai_record(uint16_t len,uint8_t *data,uint32_t count) LOS_Msleep(AI_interval+get_ble_interval()); } -#define ENABLE_4GAI 0 static void blesrvAi_send_service_task(void const *arg) { unused(arg); @@ -2393,16 +2392,27 @@ static void blesrvAi_send_service_task(void const *arg) // if(get_ble_connect()) - #if ENABLE_4GAI - if(mail.msg_data && mail.msg_len!=0) + if(getselect4gorbtai() == 1) //选择的是4g { - send_ai_bin(mail.msg_data,mail.msg_len); + if(mail.msg_data && mail.msg_len!=0) + { + if(server_handle == 200) + { + AIStreamWrite(mail.msg_data,mail.msg_len); + } + else{ + send_ai_bin(mail.msg_data,mail.msg_len); + } + } } - #else - if(mail.msg_data && mail.msg_len!=0) - send_Ai_record(mail.msg_len,mail.msg_data,AI_data_count); - #endif - + else //蓝牙 + { + if(mail.msg_data && mail.msg_len!=0) + { + send_Ai_record(mail.msg_len,mail.msg_data,AI_data_count); + } + } + if(mail.msg_data) { @@ -2480,9 +2490,36 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) if (buff == NULL) return ERRCODE_FAIL; uint32_t sendlen = sizeof(blesrv_custom_cmd_t); - uint32_t singlebuflen= ble_nus_max_data_len-20; + // uint32_t singlebuflen= ble_nus_max_data_len-20; + uint32_t singlebuflen = 0; + if(getselect4gorbtai() == 1) { + singlebuflen = 600;//4G + } else { + singlebuflen = ble_nus_max_data_len-20;//BT + } blesrv_mail.msg_data=0; + if(type == 200) + { + + blesrv_mail.service_handle = type; + blesrv_mail.msg_len = len; + blesrv_mail.msg_data = (uint8_t*)malloc(len); + + if(blesrv_mail.msg_data==NULL) + { + return ERRCODE_FAIL; + } + memcpy_s((void *)(blesrv_mail.msg_data),len,buff,len); + + ret = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0); + if (ret != OSAL_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"len<=singlebuflen Error blesrv Check send failed! err=0x%X %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count); + } + return OSAL_SUCCESS; + + } if(len<=singlebuflen) { if(type==1) diff --git a/code/sdk/application/wearable/service/ble_service/transspecard/transspecard.c b/code/sdk/application/wearable/service/ble_service/transspecard/transspecard.c index 3f1bf8e9c..58aaa0d5f 100644 --- a/code/sdk/application/wearable/service/ble_service/transspecard/transspecard.c +++ b/code/sdk/application/wearable/service/ble_service/transspecard/transspecard.c @@ -236,7 +236,7 @@ uint8_t send_transspecard_data(uint8_t type_id, void *data, uint16_t datalen) { send_packet_total++; } - + printf("get_alipay_ble_nus_max_data_len: %u\r\n",get_alipay_ble_nus_max_data_len()); printf("总数据长度: %u 字节, 预计分包数量: %u 个\n", datalen, send_packet_total); // 单包传输逻辑 @@ -591,7 +591,7 @@ uint8_t parse_transspecard_data(void *buf, uint16_t event_size) uint32_t current_packet_id = *(uint32_t *)(buf + 11); uint16_t current_datalen = *(uint16_t *)(buf + 15); -#if alipay_transspecard_log +#if 1 // 打印头部信息 printf("Message Header: 0x%02X\n", message_header); printf("Message Type: 0x%02X\n", message_type); diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp index 00b80818f..e7dcda5bf 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp @@ -813,11 +813,14 @@ WebSocketClient *init_websocket_client(const char *url, const char *headers,uint printf("init_websocket_client end 2"); return client; client_ERROR: - if(buffer) + if(buffer) { free(buffer); - if(client) + buffer=NULL; + } + if(client){ free(client); - + client = NULL; + } free_url(parsed_url); return NULL; @@ -913,13 +916,13 @@ bool chat_result_analysis(char *buf) memcpy_s(content_str_chat,64,content_str,strlen(content_str)); ble_set_ai_Answer_str(content_str_chat,2); // uapi_start_tts_single_txt(content_str_chat); - static uint8_t test=1; - if(test) - { - uapi_start_tts_single(); - test=0; + // static uint8_t test=1; + // if(test) + // { + // uapi_start_tts_single(); + // test=0; - } + // } } @@ -944,6 +947,43 @@ bool chat_ws_url_init(char * put_buf) } uint8_t is_bk_websocket_chat=0; +static uint8_t ai_asr_service_init_flag = 0; //asr初始化标志 +static uint8_t ai_chat_service_init_flag = 0; //chat初始化标志 +static uint8_t ai_tts_server_init_flag = 0; //tts初始化标志 +// 获取ASR服务初始化标志 +uint8_t get_ai_asr_service_init_flag(void) +{ + return ai_asr_service_init_flag; +} + +// 设置ASR服务初始化标志 +void set_ai_asr_service_init_flag(uint8_t flag) +{ + ai_asr_service_init_flag = flag; +} + +// 获取Chat服务初始化标志 +uint8_t get_ai_chat_service_init_flag(void) +{ + return ai_chat_service_init_flag; +} + +// 设置Chat服务初始化标志 +void set_ai_chat_service_init_flag(uint8_t flag) +{ + ai_chat_service_init_flag = flag; +} + +// 获取tts服务初始化标志 +uint8_t get_ai_tts_server_init_flag(void) +{ + return ai_tts_server_init_flag; +} +// 设置tts服务初始化标志 +void set_ai_tts_server_init_flag(uint8_t flag) +{ + ai_tts_server_init_flag = flag; +} void bk_websocket_demo(void *data) { @@ -991,7 +1031,7 @@ void bk_websocket_demo(void *data) { // send_ai_txt(1,"你是谁"); - + set_ai_chat_service_init_flag(1); WebSocketMessageType type; while (1) { @@ -1020,7 +1060,7 @@ void bk_websocket_demo(void *data) { #include "common_def.h" #include "los_printf.h" -#define CAT1_SERVICE_TASK_SIZE (2048) +#define CAT1_SERVICE_TASK_SIZE (3072) #define CAT1_SERVICE_TASK_PRIO 5 @@ -1084,7 +1124,7 @@ void uapi_stop_asr(void) { char *jsonString ="{\"header\":{\"event\":\"StopTranscription\",\"trace_id\":\"3fa6b9e6a30b407ea38ad7ae69e6c291\"}}"; - uapi_tts_paly_init(); + // uapi_tts_paly_init(); if (send_websocket_message(asr_client,( const unsigned char *)jsonString,strlen(jsonString),WS_TEXT)==0) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n"); @@ -1137,6 +1177,7 @@ void record_test(void) } #include "audio_capture_wrapper.h" #include +#include // {"status":20000000,"msg":"success","task_id":"80228c9f62821ffe3f867e1a5042d887","event":"TranscriptionStarted","result":null} // {"status":20000000, @@ -1198,16 +1239,16 @@ bool aer_result_analysis(char *buf) ble_set_ai_Question_str(result_str_asr); send_ai_txt(0,result_str_asr); - uapi_stop_asr(); - stop_AudioCaptureProcess_AI(); + // uapi_stop_asr(); + // stop_AudioCaptureProcess_AI(); } - if(strcmp(event_str,"TranscriptionStarted")==0) + if(strcmp(event_str,"TranscriptionStarted")==0) //可以对话了,切换到聆听界面 { //查询结果 // streamingRecordAndSend_AI(0); - // bool state = true; - // SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool)); - startAudioCaptureTask(); + // startAudioCaptureTask(); + bool state = true; + SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool)); } if(strcmp(event_str,"Failed")==0) { @@ -1295,7 +1336,7 @@ void bk_websocket_asr(void *data) { // uapi_start_asr(); // SendMsgToUIService(UI_4G_AI_INIT_STAUS, 0,&state, sizeof(bool)); - + set_ai_asr_service_init_flag(1); while (1) { memset_s(asr_recv_buf,1024,0,1024); @@ -1418,7 +1459,7 @@ void uapi_start_tts_single(void) void uapi_start_tts_single_txt(char *buf) { - char jsonString[512] ={0}; + char *jsonString = (char *)malloc(512); sprintf(jsonString, " { \"header\": { \ \"event\": \"LongTextStream\",\ @@ -1426,7 +1467,7 @@ void uapi_start_tts_single(void) }, \ \"payload\": { \ \"voice\":\"xiaoyun\", \ - \"format\":\"pcm\", \ + \"format\":\"mp3\", \ \"sample_rate\":16000, \ \"volume\":50, \ \"speech_rate\":0, \ @@ -1437,6 +1478,9 @@ void uapi_start_tts_single(void) if (send_websocket_message(tts_client,( const unsigned char *)jsonString,strlen(jsonString),WS_TEXT)==0) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n"); + + free(jsonString); + jsonString = NULL; } // char *tts_txt_str= @@ -1541,7 +1585,8 @@ void bk_websocket_tts(void *data) { printf("bk_websocket_tts bk_websocket_tts %d\r\n",type); if(type==WS_BINARY) { - AIStreamWrite((uint8_t *)tts_recv_buf,len); + // AIStreamWrite((uint8_t *)tts_recv_buf,len); + send_msg_data_into_Ai_msg_queue((uint8_t *)tts_recv_buf,len,200); } // aer_result_analysis(asr_recv_buf); diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h index 508f23a7b..c48092d5d 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h @@ -12,9 +12,14 @@ void uapi_stop_asr(void); bool init_ai_task(void); - void uapi_start_tts_single_txt(char *buf); - +void uapi_start_tts_single_txt(char *buf); +uint8_t get_ai_asr_service_init_flag(void); +void set_ai_asr_service_init_flag(uint8_t flag); +uint8_t get_ai_chat_service_init_flag(void); +void set_ai_chat_service_init_flag(uint8_t flag); +uint8_t get_ai_tts_server_init_flag(void); +void set_ai_tts_server_init_flag(uint8_t flag); #ifdef __cplusplus #if __cplusplus } 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 028b4c422..06eae885a 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 @@ -422,11 +422,6 @@ EXIT: #include "bleService.h" static uint32_t AI_audio_size=0; static uint8_t Cur_AI_Model= 0; -static uint8_t ai_4g_enable_flag = 0; -void is_4g_enable_AI(uint8_t enable) -{ - ai_4g_enable_flag = enable; -} static void* AudioCaptureProcess_AI(void* arg) { @@ -495,17 +490,7 @@ static void* AudioCaptureProcess_AI(void* arg) int32_t streamingRecordAndSend_AI(int type) { // 定义argv数组在更大的作用域 - const char *argv[6]; - // if(ai_4g_enable_flag == 1) - { - argv[0] = "01"; argv[1] = "mp3"; argv[2] = "16000"; - argv[3] = "1"; argv[4] = "16"; argv[5] = "/user/aiRecord.sbc"; - } - // else - // { - // argv[0] = "01"; argv[1] = "sbc"; argv[2] = "16000"; - // argv[3] = "1"; argv[4] = "16"; argv[5] = "/user/aiRecord.sbc"; - // } + const char *argv[6] ={"01", "sbc", "16000", "1", "16", "/user/aiRecord.sbc"}; int32_t argc = 6; Cur_AI_Model = type; if (g_audioSourceProcessInput.bThreadRun) { 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 b01995801..b6ac5fc2f 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 @@ -18,7 +18,6 @@ int32_t AudioCaptureSample(int32_t argc, const char *argv[]); int32_t streamingRecordAndSend_AI(int type); -void is_4g_enable_AI(uint8_t enable); #ifdef __cplusplus }; diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/voice_call_volte_sample_wrapper.cpp b/code/sdk/middleware/services/media/foundation/sample/wrapper/voice_call_volte_sample_wrapper.cpp index a58bdcf23..d9529de5f 100755 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/voice_call_volte_sample_wrapper.cpp +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/voice_call_volte_sample_wrapper.cpp @@ -1159,7 +1159,7 @@ static int32_t RunVoiceCallVolteAI(VoiceCallVolteContext *context) // 16000 32000 44100 48000 AudioRendererConfig renderConfig = {}; - renderConfig.audioFormat = PCM; + renderConfig.audioFormat = MP3; renderConfig.channelCount = 1; renderConfig.linkDir = AUDIO_DOWN_LINK; renderConfig.sampleRate = 16000; @@ -1276,8 +1276,11 @@ static void* AudioCaptureProcess_AI(void* arg) MEDIA_ERR_LOG("g_stream_in_uplink->Start"); uint8_t* data_buf=(uint8_t *)malloc(1024); - - MEDIA_ERR_LOG("malloc"); + if(data_buf == NULL) + { + MEDIA_ERR_LOG("malloc"); + return NULL; + } AudioCaptureTask_is_run=1; @@ -1298,6 +1301,7 @@ static void* AudioCaptureProcess_AI(void* arg) // 蓝牙接口发送实时录音数据 } free(data_buf); + data_buf = NULL; MEDIA_ERR_LOG("AI_audio_size %d",AI_audio_size); ret = g_stream_in_uplink->Stop(); diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c index 195c5d347..cc93ac20e 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/sys_arch.c @@ -49,7 +49,8 @@ static int lwprot_count = 0; #endif /* LOSCFG_KERNEL_SMP */ #define ROUND_UP_DIV(val, div) (((val) + (div) - 1) / (div)) -#define LWIP_LOG_BUF_SIZE 64 +// #define LWIP_LOG_BUF_SIZE 64 +#define LWIP_LOG_BUF_SIZE 512 //修改后,解决缓冲区溢出 死机问题 /** * Thread and System misc @@ -435,10 +436,29 @@ void LwipLogPrintf(const char *fmt, ...) char buf[LWIP_LOG_BUF_SIZE] = {0}; va_list ap; va_start(ap, fmt); + + // 第一次尝试:正常格式化 len = vsprintf_s(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); + if (len < 0) { - LWIP_LOGGER("log param invalid or buf is not enough."); + // 错误处理 + + // 检查是否是缓冲区不足 + va_list ap_check; + va_start(ap_check, fmt); + int needed_len = vsnprintf(NULL, 0, fmt, ap_check); + va_end(ap_check); + + if (needed_len > LWIP_LOG_BUF_SIZE - 1) { + // 缓冲区不足 + printf("log buffer is not enough. Needed: %d, Available: %d", + needed_len, LWIP_LOG_BUF_SIZE - 1); + } else { + // 参数错误或其他问题 + printf("log parameter invalid. vsnprintf needed: %d, vsprintf_s returned: %d", + needed_len, len); + } return; } LWIP_LOGGER(buf);