${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/apikeys/NotSetApiKeysView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/apikeys/SetApiKeysView.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/Aivoice4gServiceConView.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AiVoiceSelectView.cpp
#Ai Models
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aimodels/src/AiModelsModel.cpp
namespace OHOS
{
+#define AI_SELECT_DEFAULT -1
+#define AI_SELECT_4G 1
+#define AI_SELECT_BT 0
class AiVoiceModel
{
void start_ai_isready_timer(uint32_t interval = 1000);
void stop_ai_isready_timer(void);
+ void start_ai4g_connect_timer(uint32_t interval = 1000);
+ void stop_ai4g_connect_timer(void);
+
void SetSelectAiModel(int index);
int GetSelectAiModel(void);
int GetAiModelTextId(void);
bool GetAI_4G_state(void);
void SetAI_BT_state(bool state);
bool GetAI_BT_state(void);
+ void SetInit_4gai_task(bool state);
+ bool GetInit_4gai_task(void);
+ void SetSelect4gorbt(int state);
+ int GetSelect4gorbt(void);
private:
AiVoiceModel();
bool isClickable{false};
bool isLimitDisplayed{false};//AI答案是否显示到极限了
- bool AI_4G_state{false}; //4gAI状态
- bool AI_BT_state{false}; //蓝牙AI状态
+ bool AI_4G_state{false}; //4g网络状态
+ bool AI_BT_state{false}; //蓝牙连接状态
+ bool init_4gai_task{false}; //4g服务器连接状态
+ uint8_t select4gorbt{-1}; //0:4g 1:蓝牙 -1:未连接
};
}
--- /dev/null
+#ifndef AIVOICESELECTVIEW_H
+#define AIVOICESELECTVIEW_H
+#include "components/ui_scroll_view.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_button.h"
+
+namespace OHOS
+{
+ static constexpr const char *AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID = "aivoice_select_view_button4g_view_id"; // 选择界面4G连接按钮
+ static constexpr const char *AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID = "aivoice_select_view_buttonbt_view_id"; // 选择界面蓝牙连接按钮
+
+ class AiVoiceSelectView
+ {
+ public:
+ AiVoiceSelectView();
+ ~AiVoiceSelectView();
+ static AiVoiceSelectView *GetInstance(void);
+ UIScrollView *CreateAiVoiceSelectView(void);
+
+ private:
+ void ClearAll(void);
+ UILabelExt *title{nullptr};
+ UIScrollView *scrollView{nullptr};
+ UILabelExt *label4g{nullptr};
+ UILabelExt *labelbt{nullptr};
+ UIButton *button4g{nullptr};
+ UIButton *buttonbt{nullptr};
+ };
+}
+
+#endif
\ No newline at end of file
#include "aivoice/include/apikeys/NotSetApiKeysView.h"
#include "aivoice/include/apikeys/ApiKeysDeleteView.h"
#include "aivoice/include/AiVoiceConnectingView.h"
+#include "aivoice/include/AiVoiceSelectView.h"
+#include "aivoice/include/Aivoice4gServiceConView.h"
#include "ui_resource_string.h"
#include "iostream"
#include "string"
AIVOICE_NOTSETAPIKEYS, // API Keys notset界面
AIVOICE_APIKEYS_DELETE, // API Keys 删除界面
AIVOICE_AIMODE_CONNECTING, // AI Mode正在连接视图
+ AIVOICE_SELECT_VIEW, // AI选择界面
+ AIVOICE_4GSERVICECON_VIEW, // AI4G连接中界面
MAX_AIVOICE_VIEWID,
} AIVOICEVIEWID;
bool ChangeAiVoicNotSetApiKeysView(int16_t thisView);
bool ChangeAiVoicApiKeysDeleteView(int16_t thisView);
bool ChangeAiVoicConnectingView(int16_t thisView);
+ bool ChangeAiVoicSelectView(int16_t thisView);
+ bool ChangeAiVoic4gServiceConView(int16_t thisView);
void SetAiVoiceViewAllComponentsVisibilityStatus();
void ChangeAiModelAndUpdateComponentsStatus(void);
NotSetApiKeysView *p_NotSetApiKeysView{nullptr};
ApiKeysDeleteView *p_ApiKeysDeleteView{nullptr};
AiVoiceConnectingView *p_AiVoiceConnectingView{nullptr};
+ AiVoiceSelectView *p_AiVoiceSelectView{nullptr};
+ AiVoice4gServiceConView *p_Aivoice4gServiceConView{nullptr};
private:
UILabelExt *AiVoiceViewLabelInit(LabelConfig &labelconfig);
--- /dev/null
+#ifndef AIVOICE4GSERVICECONVIEW_H
+#define AIVOICE4GSERVICECONVIEW_H
+#include "components/ui_scroll_view.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_button.h"
+#include "components/ui_image_animator.h"
+
+namespace OHOS
+{
+ class AiVoice4gServiceConView
+ {
+ public:
+ AiVoice4gServiceConView();
+ ~AiVoice4gServiceConView();
+ static AiVoice4gServiceConView *GetInstance(void);
+ UIScrollView *CreateAiVoice4gServiceConView(void);
+
+ private:
+ void ClearAll(void);
+ UIScrollView *scrollView{nullptr};
+ UILabelExt *label{nullptr};
+ UIImageAnimatorView *AI4GImageAni{nullptr};
+ ImageAnimatorInfo AI4GsearchImageInfo[8];
+ };
+}
+#endif
\ No newline at end of file
#include "bleService.h"
#include <custom_save_runtime.h>
#include "cat1_ws.h"
+#include "custom_runtime.h"
namespace OHOS
{
// 声明定时器变量
// 获取4G网络是否正常
bool AiVoiceModel::GetMobileDataIsOpen(void)
{
- return false;
+ return (uapi_dev_runtime_get_cat1_networkstat() ? true : false);
}
/*查询用户选择的AI模型是否已经连接*/
if (it != selectAiModelToTextId.end())
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] SelectAiModel = %d", it->second.second);
- if(GetAI_4G_state() == true)
+ if (GetSelect4gorbt() == AI_SELECT_4G)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] GetAI_4G_state = true");
- uapi_start_asr();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G");
+ if (init_4gai_task)
+ {
+ uapi_start_asr();
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init_4gai_task fail!!");
+ }
}
- else
+ else if (GetSelect4gorbt() == AI_SELECT_BT)
{
inquire_AI_is_ready(it->second.second);
}
void AiVoiceModel::CancelCurAIChat(void)
{
// cancel_AI_cur_chat(); //线程发送取消当前对话
- cancel_AI_cur_chat_();// 直接发送取消当前对话
+ cancel_AI_cur_chat_(); // 直接发送取消当前对话
}
int AiVoiceModel::GetAIResponseType(void)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateUserQuestionStr");
- if(!RemoveLastTwoItemsOrClear())
+ if (!RemoveLastTwoItemsOrClear())
{
return false;
}
-
+
if (!AddUserQuestionToChatItems())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!");
bool AiVoiceModel::UpdateAiAnswerStr()
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateAiAnswerStr");
- #if 0
+#if 0
AiVoiceView *view_ = AiVoiceView::GetInstance();
if(view_!= nullptr )
{
}
}
}
- #endif
+#endif
int index = GetChatContentListCount() - 1;
if (index < 0 || index >= MaxChatContentListCount)
// 将更新后的 AI 回答内容添加到列表
adapter->GetChatContentItem().push_back(chatTtems[GetChatContentListCount() - 1]);
if (AiVoicePresenter::GetInstance())
- AiVoicePresenter::GetInstance()->calculateChatContentItemViewHeight(chatTtems[GetChatContentListCount() - 1].text, true);
+ AiVoicePresenter::GetInstance()->calculateChatContentItemViewHeight(chatTtems[GetChatContentListCount() - 1].text, true);
p_AivoiceReturnResultTextView->GetChatContentList()->RefreshList();
}
else
{
isClickable = value;
}
-
+
bool AiVoiceModel::GetIsClickable(void)
{
return isClickable;
/*设置用户问题的字符串*/
void AiVoiceModel::SetUserQuestionStr(std::string str)
{
- if (!entryTextViewState)
+ if (GetSelect4gorbt() == AI_SELECT_4G) // 4G
{
- SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0);
- entryTextViewState = true; // 进入返回结果界面的标志 避免重复发消息
- usleep(50000); // 延时等待创建完成,0.05秒
+ userQuestionStr = str;
+ SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
+ }
+ else if (GetSelect4gorbt() == AI_SELECT_BT) // 蓝牙
+ {
+ if (!entryTextViewState)
+ {
+ SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0);
+ entryTextViewState = true; // 进入返回结果界面的标志 避免重复发消息
+ usleep(50000); // 延时等待创建完成,0.05秒
+ }
+ /* -------------------------------------------------------------------------- */
+ 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);
}
- /* -------------------------------------------------------------------------- */
- 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);
}
/*获取Ai回答的字符串*/
{
AIResponseType = type;
errnote = str;
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIResponseType = %d,errnote = %s\n", AIResponseType, errnote.c_str());
- //如果是:AI录音解析错误或AI 回应错误 ,或者重传多次录音数据->跳转AI回应错误界面
- if (AIResponseType == AiVoiceModel::AI_RECORDING_PARSING_ERROR || AIResponseType == AiVoiceModel::AI_RESPONSE_ERROR
- || AIResponseType == AiVoiceModel::AI_BLE_ERROR)
+ AiVoiceView *view_ = AiVoiceView::GetInstance();
+ if (GetSelect4gorbt() == AI_SELECT_4G) // 4G
{
- SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)errnote.c_str(), errnote.length());
- return;
+ if (view_ != nullptr)
+ {
+ if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
+ {
+ if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
+ {
+ aiAnswerStr += str;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
+ SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+ }
+ }
+ }
}
- else if (AiVoiceModel::AI_RESPONSE_END) // 如果是AI 回应结束
+ else if (GetSelect4gorbt() == AI_SELECT_BT) // 蓝牙
{
- if (errnote.empty()) // 如果没有回应数据
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIResponseType = %d,errnote = %s\n", AIResponseType, errnote.c_str());
+ // 如果是:AI录音解析错误或AI 回应错误 ,或者重传多次录音数据->跳转AI回应错误界面
+ if (AIResponseType == AiVoiceModel::AI_RECORDING_PARSING_ERROR || AIResponseType == AiVoiceModel::AI_RESPONSE_ERROR || AIResponseType == AiVoiceModel::AI_BLE_ERROR)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::GetErrnote is empty!!");
- AiVoiceModel::GetInstance().SetErrnote("响应内容为空");
- std::string str = AiVoiceModel::GetInstance().GetErrnote();
- SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+ SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)errnote.c_str(), errnote.length());
return;
}
- }
- AiVoiceView *view_ = AiVoiceView::GetInstance();
- if(view_!= nullptr )
- {
- if(view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
+ else if (AiVoiceModel::AI_RESPONSE_END) // 如果是AI 回应结束
+ {
+ if (errnote.empty()) // 如果没有回应数据
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::GetErrnote is empty!!");
+ AiVoiceModel::GetInstance().SetErrnote("响应内容为空");
+ std::string str = AiVoiceModel::GetInstance().GetErrnote();
+ SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+ return;
+ }
+ }
+ if (view_ != nullptr)
{
- if(!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) //如果ai答案没有显示到极限了,就更新ai答案字符串
- {
- aiAnswerStr += str;
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
- SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+ if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
+ {
+ if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
+ {
+ aiAnswerStr += str;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
+ SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
+ }
}
}
}
#endif
int32_t AudioCaptureSample(int32_t argc, const char *argv[]);
int32_t streamingRecordAndSend_AI(int type);
- #define IS_SUPPORT_REALTIME_RECORD_SEND_AI 1 //是否支持实时发送录音数据
+ void is_4g_enable_AI(int enable);
+#define IS_SUPPORT_REALTIME_RECORD_SEND_AI 1 // 是否支持实时发送录音数据
#ifdef __cplusplus
};
#endif
#if IS_SUPPORT_REALTIME_RECORD_SEND_AI
int type = GetCurUsingAiModelType();
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "type = %d", type);
- streamingRecordAndSend_AI(type);//实时发送录音数据
+ is_4g_enable_AI(GetSelect4gorbt());
+ streamingRecordAndSend_AI(type); // 实时发送录音数据
#else
std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath();
if (uapi_delete_files(audioPath.c_str())) // 先删除文件
#elif CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_MSBC
const char *defaultArgs[6] = {"01", "msbc", "16000", "1", "16", audioPath.c_str()};
#endif
- uapi_save_runtime_log(RUNTIME_LOG_RECORD_START_AI);//TOOD*
- AudioCaptureSample(6, (const char **)defaultArgs);
+ uapi_save_runtime_log(RUNTIME_LOG_RECORD_START_AI); // TOOD*
+ AudioCaptureSample(6, (const char **)defaultArgs);
#endif
}
return;
void AiVoiceModel::StopListenAndRecordingUserQuestion(void)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "停止录音");
+ if (GetSelect4gorbt() == AI_SELECT_4G) // 选的是4G需要关闭asr
+ {
+ uapi_stop_asr();
+ }
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*
+ uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP_AI); // TOOD*
return;
}
if (it != selectAiModelToTextId.end())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
- if(get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW)
+ if (get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW)
{
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH);
}
if (it != selectAiModelToTextId.end())
{
// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
- if(get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW)
+ if (get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW)
{
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH);
}
entryTextViewState = false;
isClickable = false;
isLimitDisplayed = false;
+ AI_4G_state = false;
+ AI_BT_state = false;
+ // init_4gai_task = false;//TOOD:之后需要销毁
ClearQuestionAndAiAnswerStr();
StopListenAndRecordingUserQuestion();
}
}
else
{
- // 4g中途断连待扩展
-
- // 蓝牙的连接状态判断,如果AI思考过程中途断连,直接弹窗提示,不在硬等
- if (get_ble_connect() == false)
+ if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
{
- AiVoiceModel::GetInstance().SetErrnote("手机蓝牙已断开");
- std::string str = AiVoiceModel::GetInstance().GetErrnote();
- SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+ // AiVoiceModel::GetInstance().AIVoice_StopTimer();//TOOD:之后修改
+ return;
+ }
+ else if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT)
+ {
+ if (get_ble_connect() == false) // 蓝牙的连接状态判断,如果AI思考过程中途断连,直接弹窗提示,不在硬等
+ {
+ AiVoiceModel::GetInstance().SetErrnote("手机蓝牙已断开");
+ std::string str = AiVoiceModel::GetInstance().GetErrnote();
+ SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
+ }
}
}
return;
bool AiVoiceModel::get_screen60s_timer_is_stop(void)
{
- if(g_screen60s_timer == nullptr)
+ if (g_screen60s_timer == nullptr)
return true;
else
return false;
}
static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器
- static int8_t AI_IS_READY_TIMEOUT = 5; // 5s钟超时
+ static int8_t AI_IS_READY_TIMEOUT = 5; // 5s钟超时
static void AI_IS_READY_CallbackProc(int data)
{
if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时
}
}
+ /* -------------------------------------------------------------------------- */
+ static osTimerId_t g_ai4g_is_suc_connected_Handle = nullptr; // 处理AI4G连接定时器
+ static int8_t AI4G_IS_SUC_CON_TIMEOUT = 20; // 20s钟超时
+ static void AI4G_IS_SUC_CON_CallbackProc(int data)
+ {
+ AiVoiceView *view_ = AiVoiceView::GetInstance();
+ AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance();
+ if (AI4G_IS_SUC_CON_TIMEOUT <= 0) // 4g服务器连接失败
+ {
+ AiVoiceModel::GetInstance().stop_ai4g_connect_timer();
+ if (view_ != nullptr && p_AiVoicePresenter != nullptr)
+ {
+ if ((view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW) != nullptr) &&
+ (view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW)->IsVisible()))
+ {
+ p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+ }
+ }
+ }
+ else
+ {
+ if (view_ != nullptr && p_AiVoicePresenter != nullptr)
+ {
+ if (AiVoiceModel::GetInstance().GetInit_4gai_task())
+ {
+ uapi_start_asr();
+ AiVoiceModel::GetInstance().stop_ai4g_connect_timer();
+ p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODE_CONNECTING);
+ }
+ }
+ }
+ return;
+ }
+ static void AI4G_IS_SUC_CON_Callback(int data)
+ {
+ AI4G_IS_SUC_CON_TIMEOUT--;
+ GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI4G_IS_SUC_CON_CallbackProc, data));
+ }
+ /*处理AI4G连接定时器到期时的处理*/
+ void AiVoiceModel::start_ai4g_connect_timer(uint32_t interval)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_ai_isready_timer");
+ /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
+ if (g_ai4g_is_suc_connected_Handle != nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!");
+ return;
+ }
+ /* --------------------------------- 2.创建定时器 -------------------------------- */
+ g_ai4g_is_suc_connected_Handle = osTimerNew((osTimerFunc_t)AI4G_IS_SUC_CON_Callback, osTimerPeriodic, nullptr, nullptr);
+ // 检查定时器创建是否成功
+ if (g_ai4g_is_suc_connected_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_suc_connected_Handle, tick);
+ /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
+ if (ret != osOK)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+ if (g_ai4g_is_suc_connected_Handle != nullptr)
+ {
+ ret = osTimerDelete(g_ai4g_is_suc_connected_Handle);
+ }
+ g_ai4g_is_suc_connected_Handle = nullptr;
+ return;
+ }
+ return;
+ }
+
+ void AiVoiceModel::stop_ai4g_connect_timer(void)
+ {
+ // 检查定时器是否存在
+ if (g_ai4g_is_suc_connected_Handle != nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::stop_ai_isready_timer");
+ osTimerStop(g_ai4g_is_suc_connected_Handle);
+ // 删除定时器并置为 nullptr
+ osStatus_t ret = osTimerDelete(g_ai4g_is_suc_connected_Handle);
+ if (ret != osOK)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+ }
+ g_ai4g_is_suc_connected_Handle = nullptr;
+ AI4G_IS_SUC_CON_TIMEOUT = 20;
+ }
+ }
+
// 设置选择的ai模型
void AiVoiceModel::SetSelectAiModel(int index)
{
{
return AI_BT_state;
}
+ void AiVoiceModel::SetInit_4gai_task(bool state)
+ {
+ init_4gai_task = state;
+ }
+ bool AiVoiceModel::GetInit_4gai_task(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::GetInit_4gai_task %d", init_4gai_task);
+ return init_4gai_task;
+ }
+
+ void AiVoiceModel::SetSelect4gorbt(int state)
+ {
+ select4gorbt = state;
+ }
+ int AiVoiceModel::GetSelect4gorbt(void)
+ {
+ return select4gorbt;
+ }
/*获取已选择的ai模型的textid*/
int AiVoiceModel::GetAiModelTextId()
{
- #if 0
+#if 0
int language = ConfigModel::GetInstance()->GetLanguage();
int textId;
};
textId = STR_AIMODES_CHATGPT;
}
- #endif
- //客户新需求需要改模型顺序:
+#endif
+ // 客户新需求需要改模型顺序:
int textId = 0;
selectAiModelToTextId = {
{0, {STR_DEEPSEEK, 4}},
#include "gfx_utils/mem_check.h"
#include "bleService.h"
#include "player/include/PlayersModel.h"
+#include "aivoice/include/AiVoiceSelectView.h"
#include "cat1_ws.h"
namespace OHOS
{
+#ifdef __cplusplus
+ extern "C"
+ {
+#endif
+
+#include "pm.h"
+#include "pm_veto.h"
+
+ void remove_4GAI_vote(void)
+ {
+ uint8_t cnt = pm_veto_get_id_cnt(PM_ID_4G_AI);
+ if (cnt == 1)
+ {
+ uapi_pm_remove_sleep_veto(PM_ID_4G_AI);
+ }
+ }
+
+ void add_4GAI_vote(void)
+ {
+ uint8_t cnt = pm_veto_get_id_cnt(PM_ID_4G_AI);
+ if (cnt == 0)
+ {
+ uapi_pm_add_sleep_veto(PM_ID_4G_AI);
+ }
+ }
+
+#ifdef __cplusplus
+ }
+#endif
#define BLE_CONNECT_INTERVAL_HIGH_AI 10
// 当前Presenter属性实例化的内存指针
static AiVoicePresenter *g_pAiVoicePresenter = nullptr;
ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
// 开启一个60s取消长亮屏timer
model->ai_start_screen60s_timer();
+ add_4GAI_vote();//4g投票
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI);
}
model->ai_stop_screen60s_timer();
model->stop_listening_timer();
model->stop_ai_isready_timer();
+ model->stop_ai4g_connect_timer();
+ remove_4GAI_vote();//移除4g投票
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
}
view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())
{
preHeight = 0;
- ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID);
+ ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_RETURN_RESULT_TEXT_VIEWID);
}
else
{
bool AiVoicePresenter::ChangeToAIVoiceListeningView(bool val)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeToAIVoiceListeningView");
- if (view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible())
+ if (model->GetSelect4gorbt() == AI_SELECT_4G)
{
model->stop_ai_isready_timer(); // 停止定时器
if (val) /*如果查询的AI模型可用跳转到聆听中界面*/
{
- ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_LISTENING_VIEWID);
+ ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_LISTENING_VIEWID);
}
else
{
- if(model->GetAiModelTextId() == STR_AIMODES_CHATGPT) //如果当前是在chatgpt模型*/
+ if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/
{
- ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/
+ ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/
}
else
{
- ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+ ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+ }
+ }
+ }
+ else if (model->GetSelect4gorbt() == AI_SELECT_BT)
+ {
+ if (view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible())
+ {
+ model->stop_ai_isready_timer(); // 停止定时器
+ if (val) /*如果查询的AI模型可用跳转到聆听中界面*/
+ {
+ ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_LISTENING_VIEWID);
+ }
+ else
+ {
+ if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/
+ {
+ ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/
+ }
+ else
+ {
+ ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+ }
}
}
}
void AiVoicePresenter::FunctionKeyOnClickToChangeAIModel(void)
{
- if(view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
+ if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
{
int index = model->GetSelectAiModel() + 1;
if (index >= AIMODES_MAX_NUM)
// 右滑切换模型
void AiVoicePresenter::DragLeftToRightChangeAIModel(void)
{
- if(view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
+ if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
{
int index = model->GetSelectAiModel() - 1;
if (index < 0)
// 左滑切换模型
void AiVoicePresenter::DragRightToLetfChangeAIModel(void)
{
- if(view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
+ if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
{
int index = model->GetSelectAiModel() + 1;
if (index >= AIMODES_MAX_NUM)
return true;
}
- bool AiVoicePresenter::OnPress(UIView& view, const PressEvent& event)
+ bool AiVoicePresenter::OnPress(UIView &view, const PressEvent &event)
{
UNUSED(event);
std::string viewId = view.GetViewId();
model->reset_ai_screen60s_timer_time();
/* -------------------------------------------------------------------------- */
std::unordered_map<std::string, std::pair<int16_t, int16_t>> viewIdMap = {
- {AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面,并清除手表聊天记录
- {AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听,并清除手表聊天记录
+ {AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面,并清除手表聊天记录
+ {AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听,并清除手表聊天记录
};
auto it = viewIdMap.find(viewId);
if (it != viewIdMap.end())
{
- #if 0
+#if 0
if(!model->GetIsClickable())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "当前还不可点击");
return true;
}
- #endif
+#endif
if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat");
- AiVoiceModel::GetInstance().CancelCurAIChat();
- // AiVoiceModel::GetInstance().sendAIIsReady();
+ if (model->GetSelect4gorbt() == AI_SELECT_4G)
+ {
+ uapi_start_asr();
+ }
+ else if (model->GetSelect4gorbt() == AI_SELECT_BT)
+ {
+ AiVoiceModel::GetInstance().CancelCurAIChat();
+ // AiVoiceModel::GetInstance().sendAIIsReady();
+ }
PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐
PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐
}
/* ----------------------------- 重置60s取消常亮屏timer ---------------------------- */
model->reset_ai_screen60s_timer_time();
/* -------------------------------------------------------------------------- */
-
- // if ((viewId == AIVOICE_CHAT_BUTTON_VIEW_ID) && model->IsExistOpenAIAPIKeys() == false) // 如果点击的是(对话按钮)且未配置apikey
- // {
- // ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/
- // return true;
- // }
if (viewId == AIVOICE_APIKEYS_BUTTON_VIEW_ID) // 如果点击的是API Keys按钮(注:暂时不用)
{
if (model->IsExistOpenAIAPIKeys() == true)
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网络正常
+ model->SetAI_BT_state(appBluetoothConnectState);
+ if (netWork4GState && appBluetoothConnectState)
+ {
+ // 用户自行进行选择哪种方式
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SELECT_VIEW); // LOADING
+ }
+ else if (netWork4GState) // 1.手表4G网络正常
{
// 通过4G调用大模型
- ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING
+ model->SetSelect4gorbt(AI_SELECT_4G);
+ if (!model->GetInit_4gai_task())
+ {
+ init_ai_task();
+ model->start_ai4g_connect_timer();
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING
+ }
+ else
+ {
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING
+ }
}
else if (appBluetoothConnectState) // 3.只有与APP蓝牙连接正常
{
// 通过蓝牙连接APP调用大模型
+ model->SetSelect4gorbt(AI_SELECT_BT);
ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING
}
else // 4.两者连接都异常
{
// 返回错误
+ model->SetSelect4gorbt(AI_SELECT_DEFAULT);
ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID);
- // ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
}
return true;
}
ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
return true;
}
+ else if (viewId == AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID) // 如果点击的是4G连接方式
+ {
+ // 通过4G调用大模型
+ model->SetSelect4gorbt(AI_SELECT_4G);
+ if (!model->GetInit_4gai_task())
+ {
+ init_ai_task();
+ model->start_ai4g_connect_timer();
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING
+ }
+ else
+ {
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING
+ }
+ return true;
+ }
+ else if (viewId == AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID) // 如果点击的是蓝牙连接方式
+ {
+ model->SetSelect4gorbt(AI_SELECT_BT);
+ ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODE_CONNECTING);
+ }
std::unordered_map<std::string, std::pair<int16_t, int16_t>> viewIdMap = {
{ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID, {AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面
{AIVOICECONNECTTIMEOUT_ENSURE_BUTTON_VIEW_ID, {AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面
{CANCEL_THINKING_BUTTON_VIEW_ID, {AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面
{AIVOICECONNECTINGVIEW_CANCEL_BUTTON_VIEW_ID, {AIVOICE_AIMODE_CONNECTING, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面
- // {AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面,并清除手表聊天记录
- // {AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听,并清除手表聊天记录
};
auto it = viewIdMap.find(viewId);
if (it != viewIdMap.end())
{
- // if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题
- // {
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat");
- // AiVoiceModel::GetInstance().CancelCurAIChat();
- // PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐
- // PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐
- // }
ChangeViewAndLogicOperator(it->second.first, it->second.second);
return true;
}
void AiVoicePresenter::OnPickerStoped(UIPicker &picker)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnPickerStoped,%d", picker.GetSelected());
- if(view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
+ if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
{
model->SetSelectAiModel(picker.GetSelected());
view_->ChangeAiModelAndUpdateComponentsStatus();
return;
}
- //监听高度是否变化
+ // 监听高度是否变化
void AiVoicePresenter::Notify()
{
if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) &&
--- /dev/null
+#include "aivoice/include/AiVoicePresenter.h"
+#include "aivoice/include/AiVoiceSelectView.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+ static AiVoiceSelectView *g_pAivoiceSelectView{nullptr};
+ AiVoiceSelectView::AiVoiceSelectView()
+ {
+ g_pAivoiceSelectView = this;
+ }
+ AiVoiceSelectView::~AiVoiceSelectView()
+ {
+ ClearAll();
+ g_pAivoiceSelectView = nullptr;
+ }
+
+ AiVoiceSelectView *AiVoiceSelectView::GetInstance(void)
+ {
+ return g_pAivoiceSelectView;
+ }
+
+ void AiVoiceSelectView::ClearAll(void)
+ {
+ if (scrollView != nullptr)
+ {
+ scrollView->RemoveAll();
+ delete title;
+ title = nullptr;
+ delete label4g;
+ label4g = nullptr;
+ delete labelbt;
+ labelbt = nullptr;
+ delete button4g;
+ button4g = nullptr;
+ delete buttonbt;
+ buttonbt = nullptr;
+ delete scrollView;
+ scrollView = nullptr;
+ }
+ }
+
+ UIScrollView *AiVoiceSelectView::CreateAiVoiceSelectView(void)
+ {
+ if (scrollView == nullptr)
+ {
+ scrollView = new UIScrollView();
+ if (scrollView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::scrollView new fail!");
+ return nullptr;
+ }
+ }
+ scrollView->SetPosition(0, 0, 466, 466);
+ UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(AiVoicePresenter::GetInstance());
+ if (dragListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::dragListener new fail!");
+ return nullptr;
+ }
+ scrollView->SetOnDragListener(dragListener);
+ scrollView->SetTouchable(true);
+ scrollView->SetDraggable(true);
+ /* -------------------------------------------------------------------------- */
+ if (title == nullptr)
+ {
+ title = new UILabelExt();
+ if (title == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!");
+ return nullptr;
+ }
+ }
+ title->SetPosition(83, 50, 300, 35);
+ title->SetStyle(STYLE_TEXT_FONT, 30);
+ title->SetStyle(STYLE_LINE_HEIGHT, 35);
+ title->SetText("AI对话");
+ title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ title->SetRollSpeed(23);
+ title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ scrollView->Add(title);
+ /* -------------------------------------------------------------------------- */
+ int y1 = 123;
+ if (label4g == nullptr)
+ {
+ label4g = new UILabelExt();
+ if (label4g == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!");
+ return nullptr;
+ }
+ }
+ label4g->SetPosition(83, y1 + 33, 300, 35);
+ label4g->SetStyle(STYLE_TEXT_FONT, 30);
+ label4g->SetStyle(STYLE_LINE_HEIGHT, 35);
+ label4g->SetText("4G连接");
+ label4g->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ label4g->SetRollSpeed(23);
+ label4g->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ label4g->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* -------------------------------------------------------------------------- */
+ int y2 = 243;
+ if (labelbt == nullptr)
+ {
+ labelbt = new UILabelExt();
+ if (labelbt == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!");
+ return nullptr;
+ }
+ }
+ labelbt->SetPosition(83, y2 + 33, 300, 35);
+ labelbt->SetStyle(STYLE_TEXT_FONT, 30);
+ labelbt->SetStyle(STYLE_LINE_HEIGHT, 35);
+ labelbt->SetText("蓝牙连接");
+ labelbt->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ labelbt->SetRollSpeed(23);
+ labelbt->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ labelbt->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* -------------------------------------------------------------------------- */
+ if (button4g == nullptr)
+ {
+ button4g = new UIButton();
+ if (button4g == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!");
+ return nullptr;
+ }
+ }
+ button4g->SetPosition(43, 123, 380, 100);
+ button4g->SetViewId(AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID);
+ button4g->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ button4g->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ button4g->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED);
+ UIView::OnTouchListener *listener4g = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+ if (listener4g == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::listener4g new fail!");
+ return nullptr;
+ }
+ button4g->SetOnTouchListener(listener4g);
+ /* -------------------------------------------------------------------------- */
+ if (buttonbt == nullptr)
+ {
+ buttonbt = new UIButton();
+ if (buttonbt == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!");
+ return nullptr;
+ }
+ }
+ buttonbt->SetPosition(43, 243, 380, 100);
+ buttonbt->SetViewId(AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID);
+ buttonbt->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ buttonbt->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ buttonbt->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED);
+ UIView::OnTouchListener *listenerbt = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
+ if (listenerbt == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::listenerbt new fail!");
+ return nullptr;
+ }
+ buttonbt->SetOnTouchListener(listenerbt);
+
+ scrollView->Add(button4g);
+ scrollView->Add(buttonbt);
+ scrollView->Add(label4g);
+ scrollView->Add(labelbt);
+
+ return scrollView;
+ }
+}
\ No newline at end of file
delete p_AiVoiceConnectingView;
p_AiVoiceConnectingView = nullptr;
}
+ if (p_AiVoiceSelectView != nullptr)
+ {
+ delete p_AiVoiceSelectView;
+ p_AiVoiceSelectView = nullptr;
+ }
+ if (p_Aivoice4gServiceConView != nullptr)
+ {
+ delete p_Aivoice4gServiceConView;
+ p_Aivoice4gServiceConView = nullptr;
+ }
}
}
label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height);
label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize);
label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh);
- //TOOD: 待优化
- if(labelconfig.textId == STR_DEEPSEEK) {
+ // TOOD: 待优化
+ if (labelconfig.textId == STR_DEEPSEEK)
+ {
label->SetText("DeepSeek");
- } else
+ }
+ else
label->SetTextId(labelconfig.textId);
label->SetLineBreakMode(labelconfig.lineBreakMode);
label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
return true;
}
+ bool AiVoiceView::ChangeAiVoicSelectView(int16_t thisView)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicSelectView");
+ if (AiVoiceScrollView[thisView] == nullptr)
+ {
+ p_AiVoiceSelectView = new AiVoiceSelectView();
+ if (p_AiVoiceSelectView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+ return false;
+ }
+ UIScrollView *scrollview = p_AiVoiceSelectView->CreateAiVoiceSelectView();
+ if (scrollview == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+ return false;
+ }
+ AiVoiceScrollView[thisView] = scrollview;
+ container_->Add(AiVoiceScrollView[thisView]);
+ }
+ return true;
+ }
+
+ bool AiVoiceView::ChangeAiVoic4gServiceConView(int16_t thisView)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoic4gServiceConView");
+ if (AiVoiceScrollView[thisView] == nullptr)
+ {
+ p_Aivoice4gServiceConView = new AiVoice4gServiceConView();
+ if (p_Aivoice4gServiceConView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+ return false;
+ }
+ UIScrollView *scrollview = p_Aivoice4gServiceConView->CreateAiVoice4gServiceConView();
+ if (scrollview == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+ return false;
+ }
+ AiVoiceScrollView[thisView] = scrollview;
+ container_->Add(AiVoiceScrollView[thisView]);
+ }
+ return true;
+ }
+
struct AiVoiceViewMapper
{
const int16_t viewId;
{AIVOICE_NOTSETAPIKEYS, &AiVoiceView::ChangeAiVoicNotSetApiKeysView},
{AIVOICE_APIKEYS_DELETE, &AiVoiceView::ChangeAiVoicApiKeysDeleteView},
{AIVOICE_AIMODE_CONNECTING, &AiVoiceView::ChangeAiVoicConnectingView},
+ {AIVOICE_SELECT_VIEW, &AiVoiceView::ChangeAiVoicSelectView},
+ {AIVOICE_4GSERVICECON_VIEW, &AiVoiceView::ChangeAiVoic4gServiceConView},
};
bool AiVoiceView::ClickFunc(int16_t interface)
static const int16 AiVoiceDestroyMapper[] = {
AIVOICE_AIMODE_CONNECTING,
+ AIVOICE_4GSERVICECON_VIEW,
};
void AiVoiceView::DestroyTempView(int16_t hideView)
p_AiVoiceConnectingView = nullptr;
}
break;
+ case AIVOICE_4GSERVICECON_VIEW:
+ if (p_Aivoice4gServiceConView)
+ {
+ delete p_Aivoice4gServiceConView;
+ p_Aivoice4gServiceConView = nullptr;
+ }
+ break;
default:
break;
}
int textId = AiVoiceModel::GetInstance().GetAiModelTextId();
if (title)
{
- if(textId == STR_DEEPSEEK)
+ if (textId == STR_DEEPSEEK)
{
title->SetText("DeepSeek");
- }
- else
+ }
+ else
{
- title->SetTextId(textId);
- title->ForceResetText();
+ title->SetTextId(textId);
+ title->ForceResetText();
}
}
if (aiModelImage)
--- /dev/null
+#include "aivoice/include/Aivoice4gServiceConView.h"
+#include "aivoice/include/AiVoicePresenter.h"
+#include "wearable_log.h"
+#include "common/image_cache_manager.h"
+#include "UiConfig.h"
+namespace OHOS
+{
+ static const int16_t AI4GANILABEL_X_FIRST = 83;
+ static const int16_t AI4GANILABEL_Y_FIRST = 257;
+ static const int16_t AI4GANILABEL_WIDTH_FIRST = 300;
+ static const int16_t AI4GANILABEL_HEIGHT_FIRST = 48;
+ static const char *AI4GANILABEL_TEXT_FIRST = (char *)"服务器连接中";
+ static const int16_t AI4GANILABEL_FONT_FIRST = 38;
+
+ const char *AI4GsearchImagePath[] = {
+ PNG_A019_080_IMAGE_PATH,
+ PNG_A019_081_IMAGE_PATH,
+ PNG_A019_082_IMAGE_PATH,
+ PNG_A019_083_IMAGE_PATH,
+ PNG_A019_084_IMAGE_PATH,
+ PNG_A019_085_IMAGE_PATH,
+ PNG_A019_086_IMAGE_PATH,
+ PNG_A019_087_IMAGE_PATH,
+ };
+
+ static const int16_t AI4GALIPAY_BIND_IMAGE_X = 162;
+ static const int16_t AI4GALIPAY_BIND_IMAGE_Y = 112;
+ static const int16_t AI4GALIPAY_BIND_IMAGE_WIDTH = 128;
+ static const int16_t AI4GALIPAY_BIND_IMAGE_HEIGHT = 128;
+ static const int16_t AI4GALIPAY_BIND_IMAGE_DELAY = 100;
+
+ static AiVoice4gServiceConView *g_pAiVoice4gServiceConView{nullptr};
+ AiVoice4gServiceConView::AiVoice4gServiceConView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoice4gServiceConView::AiVoice4gServiceConView");
+ g_pAiVoice4gServiceConView = this;
+ }
+
+ AiVoice4gServiceConView::~AiVoice4gServiceConView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoice4gServiceConView::~AiVoice4gServiceConView");
+ ClearAll();
+ g_pAiVoice4gServiceConView = nullptr;
+ }
+
+ AiVoice4gServiceConView *AiVoice4gServiceConView::GetInstance(void)
+ {
+ return g_pAiVoice4gServiceConView;
+ }
+
+ void AiVoice4gServiceConView::ClearAll(void)
+ {
+ if (scrollView != nullptr)
+ {
+ scrollView->RemoveAll();
+ delete label;
+ label = nullptr;
+ delete AI4GImageAni;
+ AI4GImageAni = nullptr;
+ delete scrollView;
+ scrollView = nullptr;
+ }
+ }
+
+ UIScrollView *AiVoice4gServiceConView::CreateAiVoice4gServiceConView(void)
+ {
+ if (scrollView == nullptr)
+ {
+ scrollView = new UIScrollView();
+ if (scrollView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::scrollView new fail!");
+ return nullptr;
+ }
+ }
+ scrollView->SetPosition(0, 0, 466, 466);
+ UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(AiVoicePresenter::GetInstance());
+ if (dragListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::dragListener new fail!");
+ return nullptr;
+ }
+ scrollView->SetOnDragListener(dragListener);
+ scrollView->SetTouchable(true);
+ scrollView->SetDraggable(true);
+ /* -------------------------------------------------------------------------- */
+ label = new UILabelExt();
+ if (label == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayBindAni::InitExit new label fail");
+ return nullptr;
+ }
+ label->SetPosition(AI4GANILABEL_X_FIRST, AI4GANILABEL_Y_FIRST, AI4GANILABEL_WIDTH_FIRST, AI4GANILABEL_HEIGHT_FIRST);
+ label->SetText(AI4GANILABEL_TEXT_FIRST);
+ label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, AI4GANILABEL_FONT_FIRST);
+ label->SetStyle(STYLE_TEXT_FONT, AI4GANILABEL_FONT_FIRST);
+ label->SetAlign(TEXT_ALIGNMENT_CENTER);
+ label->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ scrollView->Add(label);
+ /* -------------------------------------------------------------------------- */
+ AI4GImageAni = new UIImageAnimatorView();
+ if (AI4GImageAni == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayBindAni::AlipayInitImageAni new AI4GImageAni fail");
+ return nullptr;
+ }
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ AI4GsearchImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(AI4GsearchImagePath[i]);
+ AI4GsearchImageInfo[i].imageType = IMG_SRC_IMAGE_INFO;
+ AI4GsearchImageInfo[i].pos.x = AI4GALIPAY_BIND_IMAGE_X;
+ AI4GsearchImageInfo[i].pos.y = AI4GALIPAY_BIND_IMAGE_Y;
+ AI4GsearchImageInfo[i].width = AI4GALIPAY_BIND_IMAGE_WIDTH;
+ AI4GsearchImageInfo[i].height = AI4GALIPAY_BIND_IMAGE_HEIGHT;
+ }
+ AI4GImageAni->SetPosition(AI4GALIPAY_BIND_IMAGE_X, AI4GALIPAY_BIND_IMAGE_Y, AI4GALIPAY_BIND_IMAGE_WIDTH, AI4GALIPAY_BIND_IMAGE_HEIGHT);
+ AI4GImageAni->SetImageAnimatorSrc(AI4GsearchImageInfo, 8, AI4GALIPAY_BIND_IMAGE_DELAY);
+ AI4GImageAni->SetRepeat(true);
+ AI4GImageAni->SetAutoEnable(false);
+ AI4GImageAni->SetResizeMode(UIImageView::FILL);
+ scrollView->Add(AI4GImageAni);
+ AI4GImageAni->Start();
+
+ return scrollView;
+ }
+}
UI_UPDATE_HEARTRATE_DATA, //更新心率曲线
UI_UPDATE_DIALSTATE_DATA, //更新主界面状态
+ UI_4G_AI_INIT_STAUS, //4G AI 初始化状态
UI_AI_JUMP_TO_RESULT_VIEW, //跳转到返回结果视图
UI_AI_JUMP_TO_LISTENING_VIEW,//跳转到AI聆听界面
UI_AI_JUMP_TO_RESPONDERR_VIEW,//处理跳转AI回应错误界面
static void HandleUpdateAlarmInfo(Request *request);
static void HandleUpdateGoalInfo(Request *request);
static void HandleUpdateLanguageInfo(Request *request);
+ static void HandleUpdateInit_4gai_task(Request *request);
// 消息处理程序项数组(每个消息类型对应一个处理函数,函数名以 Handle 开头)
MsgHandlerEntry msgHandlers[] = {
{UI_UPDATE_HEARTRATE_DATA, HandleUpdateHeartRate},
{UI_UPDATE_DIALSTATE_DATA, HandleUpdateDialState},
{UI_UPDATE_ALARM_INFO, HandleUpdateAlarmInfo},
+ {UI_4G_AI_INIT_STAUS, HandleUpdateInit_4gai_task},
};
/* -------------------------------------------------------------------------- */
void ScreenTurnOn(int32_t timeout)
std::bind(&OHOS::LanguageSwitchModel::LanguageSwitchViewupdata, &OHOS::LanguageSwitchModel::GetInstance(),id));
}
+ static void HandleUpdateInit_4gai_task(Request *request)
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleUpdateInit_4gai_task");
+ uint8_t data = *((uint8_t *)request->data);
+ GraphicService::GetInstance()->PostGraphicEvent(
+ std::bind(&OHOS::AiVoiceModel::SetInit_4gai_task, &OHOS::AiVoiceModel::GetInstance(),data));
+ }
+
/* -------------------------------------------------------------------------- */
#ifdef __cplusplus
}
if(strcmp("middle",type_str)==0)
{
+ if(strlen(content_str)>0) {
memset_s(content_str_chat,64,0,64);
memcpy_s(content_str_chat,64,content_str,strlen(content_str));
ble_set_ai_Answer_str(content_str_chat,2);
+ }
}
cJSON_Delete(root);
if(is_end_bool==true)
{
memset_s(result_str_asr,256,0,256);
- memcpy_s(result_str_asr,256,result_str,strlen(result_str));
+ memcpy_s(result_str_asr,256,result_str,strlen(result_str));
+ SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0);//先跳转到结果界面
ble_set_ai_Question_str(result_str_asr);
send_ai_txt(0,result_str_asr);
}
uapi_cat1_keep_wakeup(1);
WebSocketMessageType type;
+ bool state = true;
+ SendMsgToUIService(UI_4G_AI_INIT_STAUS, 0,&state, sizeof(bool));
+
while (1)
{
memset_s(asr_recv_buf,1024,0,1024);
void uapi_stop_asr(void);
-
+bool init_ai_task(void);
#ifdef __cplusplus
#if __cplusplus
PM_ID_CAT1,//Cat1 communication
PM_ID_P_TEST,//产测
PM_ID_BUTTON_GPIO,//gpio按键
+ PM_ID_4G_AI,//4g AI
PM_ID_MAX,
} pm_id_t;
"PM_ID_CAT1",//Cat1 communication
"PM_ID_P_TEST",
"PM_ID_BUTTON_GPIO",//GPIO按键
+ "PM_ID_4G_AI",//AI投票
"PM_ID_MAX"
};
#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)
{
#if AI_RECORD_TEST
int32_t streamingRecordAndSend_AI(int type)
{
- const char *argv[] = {"01", "mp3", "16000", "1", "16", "/user/aiRecord.sbc"};
+ // 定义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";
+ }
int32_t argc = 6;
Cur_AI_Model = type;
if (g_audioSourceProcessInput.bThreadRun) {
int32_t streamingRecordAndSend_AI(int type);
+void is_4g_enable_AI(uint8_t enable);
+
#ifdef __cplusplus
};
#endif