* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:14:43
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-31 16:53:36
+ * @LastEditTime: 2024-08-01 15:01:20
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
*/
#ifndef AI_VOICE_MODEL_H
bool GetAPPBluetoothIsConnect(void);
bool GetMobileDataIsOpen(void);
bool GetAiVoiceConnectStatus(void);
+ void SetAiVoiceConnectStatus(bool state);
+ void QuerySelectedAiModelIsConnect();
// 聊天内容管理
bool InitchatContentItems(void);
ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false}; // 对话项数组
bool entryTextViewState{false}; // 进入返回结果界面的标志
std::map<int, std::pair<int, int>> selectAiModelToTextId;
+ bool AiVoiceConnectStatus{false}; //与AI模型的连接状态
};
}
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:14:50
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-31 18:07:20
+ * @LastEditTime: 2024-08-01 16:01:59
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
*/
#include "aivoice/include/AiVoiceModel.h"
// 获取与AI模型的连接状态
bool AiVoiceModel::GetAiVoiceConnectStatus(void)
{
- return true;
+ return AiVoiceConnectStatus;
+ }
+
+ // 设置与AI模型的连接状态
+ void AiVoiceModel::SetAiVoiceConnectStatus(bool state)
+ {
+ AiVoiceConnectStatus = state;
+ }
+
+ /*查询用户选择的AI模型是否已经连接*/
+ void AiVoiceModel::QuerySelectedAiModelIsConnect()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::QuerySelectedAiModelIsConnect");
+ auto it = selectAiModelToTextId.find(GetSelectAiModel());
+ if (it != selectAiModelToTextId.end())
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SelectAiModel = %d", it->second.second);
+ inquire_AI_is_ready(it->second.second);
+ }
}
/*列表数量*/
aiAnswerStr = "";
}
+ /*获取AI音频路径*/
std::string AiVoiceModel::GetAIAudioPath(void)
{
// CreateIfNotExists();
auto it = selectAiModelToTextId.find(GetSelectAiModel());
if (it != selectAiModelToTextId.end())
{
- size, it->second.second;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
+ send_AI_is_ready(it->second.second);
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelectAiModel fail!!", size, it->second.second);
}
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
- send_AI_is_ready(it->second.second);
ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
}
fclose(file);
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:11:17
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-31 16:14:11
+ * @LastEditTime: 2024-08-01 15:55:48
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
*/
#include "AppViewIDs.h"
}
else if (viewId == AIVOICE_START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮
{
+ /* ------------------------ 如果点击的是开始对话按钮,先查询AI模型是否可用 ------------------------ */
+ model->QuerySelectedAiModelIsConnect();
+ /* -------------------------------------------------------------------------- */
/*
* 进入对话流程:
* 1.当手表4G网络正常+与app连接正常 -> 通过4G调用大模型
*/
bool netWork4GState = model->GetMobileDataIsOpen();
bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect();
+ bool aivoiceConnectState = model->GetAiVoiceConnectStatus();
- if (netWork4GState && appBluetoothConnectState) // 1.当手表4G网络正常+与app连接正常
+ if (netWork4GState) // 1.手表4G网络正常
{
- // 通过4G调用大模型
+ if (aivoiceConnectState) /*如果模型是连接成功的*/
+ {
+ // 通过4G调用大模型
+ }
+ else
+ {
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+ }
}
- else if (netWork4GState && !appBluetoothConnectState) // 2.只有手表4G网络正常
+ else if (appBluetoothConnectState) // 3.只有与APP蓝牙连接正常
{
- // 通过4G调用大模型
+ if (aivoiceConnectState) /*如果模型是连接成功的*/
+ {
+ // 通过蓝牙连接APP调用大模型
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID);
+ }
+ else
+ {
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
+ }
}
- else if (!netWork4GState && appBluetoothConnectState) // 3.只有与APP蓝牙连接正常
- {
- // 通过蓝牙连接APP调用大模型
- ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID);
- }
- else if (!netWork4GState && !appBluetoothConnectState) // 4.两者连接都异常
+ else // 4.两者连接都异常
{
// 返回错误
ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID);
// ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
}
-
return true;
}
else if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮
//在此处实现,给UI回复消息。
void ble_app_reply(bool data)
{
-
+ OHOS::AiVoiceModel::GetInstance().SetAiVoiceConnectStatus(data);
}
void SetisFirstTimeStart(bool value);
bool GetisFirstTimeStart(void);
/* ---------------------------- 设置OpenAI APIKeys ---------------------------- */
- void SetOpenAIAPIKeys(char * value);
+ void SetOpenAIAPIKeys(const char * value);
std::string GetOpenAIAPIKeys(void);
/* --------------------------------- 用户配置信息 --------------------------------- */
void SetUserAge(int age);
}
/*设置API Keys*/
- void ConfigModel::SetOpenAIAPIKeys(char * value)
+ void ConfigModel::SetOpenAIAPIKeys(const char * value)
{
set_condigData_String(CONFIGMODEL_ITEM_OPEN_AI_API_KEYS,value);
}