#include "custom_runtime.h"
#include "voice_call_volte_sample_wrapper.h"
#include <los_base.h>
+#include "websocket_server_manager.h"
+#include "font/ui_font.h"
+
namespace OHOS
{
- // 声明定时器变量
- static osTimerId_t g_timer = nullptr;
- static constexpr uint16_t THIRTY_TIME = 30 / 3;
- static int Time = THIRTY_TIME;
- static int AiModelConnectTimeout = 5;
-
AiVoiceModel::AiVoiceModel()
{
CreateDirectory("/user/userdata/AiRecording/");
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G");
if (GetInit_4gai_task())
{
-#if AI_VOICE_ENABLE
- uapi_UI_start_asr(GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+ uapi_start_AI_asr();
#endif
- }
+ }
else
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init_4gai_task fail!!");
else if (GetSelect4gorbt() == AI_SELECT_BT)
{
#ifdef SUPPORT_BLE_SERVICE
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙:查询Ai是否就绪");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙:查询Ai是否就绪:%d",it->second.second);
inquire_AI_is_ready(it->second.second);
#endif
}
{
return false;
}
-
+
if (!AddUserQuestionToChatItems())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!");
if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
{
delete_start_line_break_str(str);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "传入的str:%s", str.c_str());
aiAnswerStr += str;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
/* -------------------------------------------------------------------------- */
// 累积接收到的文本
- accumulatedText += str;
+ // accumulatedText += str;//tts播放的代码去除掉
/* -------------------------------------------------------------------------- */
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
}
if (view_ != nullptr)
{
if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
{
- start_ai4g_tts_play_timer(); // 开启一个定时器,用于播放tts音频
+ // start_ai4g_tts_play_timer(); // 开启一个定时器,用于播放tts音频
start_update_ai_answer_timer();
}
}
if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
{
aiAnswerStr += str;
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
}
}
}
else if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
{
-#if AI_VOICE_ENABLE
- LOS_Msleep(20);
- startAudioCaptureTask();
-#endif
+ // uapi_start_asr_StartTranscription();录音同步移动到开启asr了,所有这里不调用
}
#else
std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath();
void AiVoiceModel::StopListenAndRecordingUserQuestion(void)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "停止录音");
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "停止录音:%d", GetSelect4gorbt());
if (GetSelect4gorbt() == AI_SELECT_4G) // 选的是4G需要关闭asr
{
- // uapi_stop_asr();
- // stop_AudioCaptureProcess_AI();
- // uapi_UI_stop_asr();
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_AI_asr();
+#endif
}
else if (GetSelect4gorbt() == AI_SELECT_BT)
{
{
ClearQuestionAndAiAnswerStr();
StopListenAndRecordingUserQuestion();
- Time = THIRTY_TIME;
- AiModelConnectTimeout = 5;
AiVoiceConnectStatus = false;
for (int i = 0; i < ChatContentListCount; i++)
}
/* -------------------------------------------------------------------------- */
+ // 声明定时器变量
+ static osTimerId_t g_timer = nullptr;
+ static int Time = DEFAULT_TIMEOUT_10S;
/*定时器到期时的处理*/
static void AIVoice_TimerCallbackProc(int data)
{
// 等待AI思考完成的定时器
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIVoice_TimerCallbackProc,Time = %d", Time);
- if (Time < 0) // 如果思考时间超时30s,进入连接超时界面
+ if (Time < 0) // 如果思考时间超时10s,进入连接超时界面
{
AiVoiceModel::GetInstance().AIVoice_StopTimer();
AiVoiceModel::GetInstance().SetErrnote("连接超时,请重新开始对话");
std::string str = AiVoiceModel::GetInstance().GetErrnote();
-#if AI_VOICE_ENABLE
- dinit_ai_task(); // 所有服务都删除重新连一下服务器
+
+ if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+ {
+ // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_all_websocket_servers();
+ uapi_destroy_all_websocket_servers();
#endif
+ }
+
SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
}
else
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
}
g_timer = nullptr;
- Time = THIRTY_TIME;
- AiModelConnectTimeout = 5;
+ Time = DEFAULT_TIMEOUT_10S;
}
}
// 声明定时器变量
static osTimerId_t g_screen60s_timer = nullptr;
- static int8_t SCREEN_60S_TIME = 60; // 60s
+ static int8_t SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S; // 60s
static void ai_start_screen60s_timer_callbackProc(int data)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME);
- SCREEN_60S_TIME -= 30;
+ SCREEN_60S_TIME -= DEFAULT_TIMEOUT_30S;
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME);
if (SCREEN_60S_TIME <= 0)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
}
g_screen60s_timer = nullptr;
- SCREEN_60S_TIME = 60;
+ SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S;
}
}
void AiVoiceModel::reset_ai_screen60s_timer_time()
{
- SCREEN_60S_TIME = 60;
+ SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S;
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d", SCREEN_60S_TIME);
if (nullptr == g_screen60s_timer)
{
AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance();
if (AiVoicePresenter::GetInstance() && AivoiceListeningView::GetInstance())
{
-#if AI_VOICE_ENABLE
- uapi_UI_stop_asr();
-#endif
- AiVoicePresenter::GetInstance()->ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 切换到思考中界面
+ // uapi_UI_stop_asr();
+ AiVoicePresenter::GetInstance()->ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 切换到思考中界面
}
}
else
}
}
- static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器
- static int8_t AI_IS_READY_TIMEOUT = 5; // 5s钟超时
+ static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器
+ static int8_t AI_IS_READY_TIMEOUT = DEFAULT_TIMEOUT_5S; // 5s钟超时
static void AI_IS_READY_CallbackProc(int data)
{
if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时
if ((view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr) &&
(view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible()))
{
-#if AI_VOICE_ENABLE
- dinit_ai_task(); // 所有服务都删除重新连一下服务器
+ if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+ {
+ // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_all_websocket_servers();
+ uapi_destroy_all_websocket_servers();
#endif
+ }
p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
}
}
if (AiVoiceModel::GetInstance().GetInit_4gai_task())
{
uint8_t state = 0;
-#if AI_VOICE_ENABLE
- state = get_asr_is_ready_start();
-#endif
- if (state)
+ // state = get_asr_is_ready_start();
+ state = get_asr_is_ready_start_old();
+ if (state)
{
bool state = true;
SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
}
g_ai_is_ready_Handle = nullptr;
- AI_IS_READY_TIMEOUT = 5;
+ AI_IS_READY_TIMEOUT = DEFAULT_TIMEOUT_5S;
}
}
if ((view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW) != nullptr) &&
(view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW)->IsVisible()))
{
-#if AI_VOICE_ENABLE
- dinit_ai_task(); // 所有服务都删除重新连一下服务器
+ // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_all_websocket_servers();
+ uapi_destroy_all_websocket_servers();
#endif
p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
}
{
if (view_ != nullptr && p_AiVoicePresenter != nullptr)
{
-#if AI_VOICE_ENABLE
- if (uapi_get_server_state_is_end())
- {
- init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
- return;
- }
-
if (AiVoiceModel::GetInstance().GetInit_4gai_task())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "4gAi服务初始化成功");
AiVoiceModel::GetInstance().stop_ai4g_connect_timer();
p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODE_CONNECTING);
}
-#endif
}
}
return;
else
{
// if(AiVoiceModel::GetInstance().GetUserQuestionStr() !=)
- // SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
+ // SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
}
}
bool AiVoiceModel::GetInit_4gai_task(void)
{
- uint8_t asr_state = 0;
- uint8_t chat_state = 0;
- uint8_t tts_state = 0;
-#if AI_VOICE_ENABLE
- asr_state = get_ai_asr_service_init_flag();
- chat_state = get_ai_chat_service_init_flag();
- tts_state = get_ai_tts_server_init_flag();
-#endif
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "asr_state:%d,chat_state:%d,tts_state:%d", asr_state, chat_state, tts_state);
- if ((asr_state == 1) && (chat_state == 1) && (tts_state == 1))
- {
- init_4gai_task = true;
- }
- else
- {
- init_4gai_task = false;
- }
+ init_4gai_task = are_all_services_ready();
return init_4gai_task;
}
{
return select4gorbt;
}
- // 打断tts播放
- void AiVoiceModel::cancel_tts_play(void)
- {
-#if AI_VOICE_ENABLE
- tts_server_deinit();
-#endif
- }
// 是否需要跳转到结果视图
bool AiVoiceModel::is_need_to_jump_result_view(void)
#endif
return textId;
}
-
}
#ifdef __cplusplus
return 0;
}
- static uint8_t clear_queue_stream = 0;
- uint8_t get_clear_queue_stream(void)
+#ifdef BLE_INSTRUCT
+
+ /**
+ * @brief 过滤字符串中无法显示的文字(使用GetGlyphPathData接口)
+ * @param input_str 输入字符串
+ * @param output_str 输出字符串缓冲区
+ * @param max_len 输出缓冲区最大长度
+ * @return 过滤后的字符串长度,-1表示失败
+ */
+ int32_t chat_filter_unsupported_chars(const char *input_str, char *output_str, uint32_t max_len)
{
- return clear_queue_stream;
+ if (input_str == NULL || output_str == NULL || max_len == 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid parameters for asr_filter_unsupported_chars\n");
+ return -1;
+ }
+
+ // 初始化输出缓冲区
+ memset(output_str, 0, max_len);
+
+ uint32_t input_len = strlen(input_str);
+ uint32_t output_pos = 0;
+ uint32_t input_pos = 0;
+
+ while (input_pos < input_len && output_pos < max_len - 1)
+ {
+ uint32_t char_start = input_pos;
+ uint32_t char_end = input_pos;
+
+ // 获取下一个UTF-8字符
+ uint32_t unicode_char = 0;
+ bool valid_utf8 = false;
+
+ // 简单的UTF-8解码
+ if ((unsigned char)input_str[input_pos] < 0x80)
+ {
+ // ASCII字符
+ unicode_char = (unsigned char)input_str[input_pos];
+ char_end = input_pos + 1;
+ valid_utf8 = true;
+ }
+ else if ((unsigned char)input_str[input_pos] >= 0xC0 && (unsigned char)input_str[input_pos] < 0xE0)
+ {
+ // 2字节UTF-8字符
+ if (input_pos + 1 < input_len)
+ {
+ unicode_char = ((unsigned char)input_str[input_pos] & 0x1F) << 6 |
+ ((unsigned char)input_str[input_pos + 1] & 0x3F);
+ char_end = input_pos + 2;
+ valid_utf8 = true;
+ }
+ }
+ else if ((unsigned char)input_str[input_pos] >= 0xE0 && (unsigned char)input_str[input_pos] < 0xF0)
+ {
+ // 3字节UTF-8字符
+ if (input_pos + 2 < input_len)
+ {
+ unicode_char = ((unsigned char)input_str[input_pos] & 0x0F) << 12 |
+ ((unsigned char)input_str[input_pos + 1] & 0x3F) << 6 |
+ ((unsigned char)input_str[input_pos + 2] & 0x3F);
+ char_end = input_pos + 3;
+ valid_utf8 = true;
+ }
+ }
+ else if ((unsigned char)input_str[input_pos] >= 0xF0 && (unsigned char)input_str[input_pos] < 0xF8)
+ {
+ // 4字节UTF-8字符
+ if (input_pos + 3 < input_len)
+ {
+ unicode_char = ((unsigned char)input_str[input_pos] & 0x07) << 18 |
+ ((unsigned char)input_str[input_pos + 1] & 0x3F) << 12 |
+ ((unsigned char)input_str[input_pos + 2] & 0x3F) << 6 |
+ ((unsigned char)input_str[input_pos + 3] & 0x3F);
+ char_end = input_pos + 4;
+ valid_utf8 = true;
+ }
+ }
+
+ if (!valid_utf8)
+ {
+ // 无效的UTF-8字符,跳过
+ input_pos++;
+ continue;
+ }
+
+ // 使用GetGlyphPathData接口检查字符是否可以在字体中显示
+ bool char_supported = true;
+
+ // 对于ASCII字符,直接支持
+ if (unicode_char < 0x80)
+ {
+ char_supported = true;
+ }
+ else
+ {
+ // 使用字体引擎检查字符是否支持
+ OHOS::UIFont *fontEngine = OHOS::UIFont::GetInstance();
+ if (fontEngine != NULL)
+ {
+ // 使用GetGlyphPathData检查字符是否支持
+ OHOS::GlyphPathData path;
+ if (!fontEngine->GetGlyphPathData(unicode_char, 0, path))
+ {
+ // 字符不支持,标记为不支持
+ char_supported = false;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Character 0x%X not supported by font engine\n", unicode_char);
+ }
+ else
+ {
+ // 字符支持
+ char_supported = true;
+ }
+ }
+ else
+ {
+ // 字体引擎不可用,使用简化的字符范围检查
+ if (unicode_char >= 0x4E00 && unicode_char <= 0x9FFF)
+ {
+ // 中文字符范围
+ char_supported = true;
+ }
+ else if (unicode_char >= 0xAC00 && unicode_char <= 0xD7AF)
+ {
+ // 韩文字符范围
+ char_supported = true;
+ }
+ else if (unicode_char >= 0x3040 && unicode_char <= 0x309F)
+ {
+ // 平假名
+ char_supported = true;
+ }
+ else if (unicode_char >= 0x30A0 && unicode_char <= 0x30FF)
+ {
+ // 片假名
+ char_supported = true;
+ }
+ else if (unicode_char >= 0x2000 && unicode_char <= 0x206F)
+ {
+ // 标点符号
+ char_supported = true;
+ }
+ else
+ {
+ // 其他字符,标记为不支持
+ char_supported = false;
+ }
+ }
+ }
+
+ if (char_supported)
+ {
+ // 字符支持,复制到输出缓冲区
+ uint32_t char_len = char_end - char_start;
+ if (output_pos + char_len < max_len)
+ {
+ memcpy(&output_str[output_pos], &input_str[char_start], char_len);
+ output_pos += char_len;
+ }
+ else
+ {
+ break; // 输出缓冲区已满
+ }
+ }
+ else
+ {
+ // 字符不支持,跳过不支持的字符
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Unsupported character: 0x%X, skipping\n", unicode_char);
+ }
+
+ input_pos = char_end;
+ }
+
+ // 确保输出字符串以null结尾
+ output_str[output_pos] = '\0';
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Filtered string: '%s' -> '%s' (length: %d)\n",
+ input_str, output_str, output_pos);
+
+ return output_pos;
}
- // 清空队列中可能存在的音频数据
- void set_clear_queue_stream(uint8_t state)
+ /**
+ * @brief 过滤chat结果中的无法显示字符
+ * @param result chat识别结果字符串
+ * @return 过滤后的字符串长度,-1表示失败
+ */
+ int32_t chat_filter_result_chars(char *result)
{
- clear_queue_stream = state;
- }
+ if (result == NULL)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " result string is NULL\n");
+ return -1;
+ }
+ uint32_t max_len = strlen(result) + 1;
+ char *temp_buffer = (char *)malloc(max_len);
+ if (temp_buffer == NULL)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for temp buffer\n");
+ return -1;
+ }
- #ifdef BLE_INSTRUCT
+ int32_t filtered_len = chat_filter_unsupported_chars(result, temp_buffer, max_len);
+ if (filtered_len >= 0)
+ {
+ strcpy(result, temp_buffer);
+ }
- #include "bleEvent.h"
- #include "bleInstruct.h"
+ free(temp_buffer);
+ return filtered_len;
+ }
+
+#include "bleEvent.h"
+#include "bleInstruct.h"
void ble_set_ai_Question_str_(char *buf)
{
+ printf("ble_set_ai_Question_str_ %s\n",buf);
OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf));
}
+ void ble_set_ai_Answer_str_(char *buf, uint8_t type)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble_set_ai_Answer_str_:%s,type:%d",buf,type);
+ // chat_filter_result_chars(buf);
+ OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf), type);
+ }
- void ble_set_ai_Answer_str_(char *buf,uint8_t type)
+ void ble_app_reply_(bool data)
{
- OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf),type);
+ bool state = data;
+ printf("ble_app_reply_:%d\n",state);
+ SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
}
extern bleInstruct_t_ bleInstruct_t;
void ble_AI_init(void)
{
- bleInstruct_t.ble_set_ai_Question_str= ble_set_ai_Question_str_;
+ bleInstruct_t.ble_set_ai_Question_str = ble_set_ai_Question_str_;
- bleInstruct_t.ble_set_ai_Answer_str=ble_set_ai_Answer_str_;
+ bleInstruct_t.ble_set_ai_Answer_str = ble_set_ai_Answer_str_;
+ bleInstruct_t.ble_app_reply = ble_app_reply_;
}
- #endif
+ /*
+ * WebSocket 聊天结果过滤回调包装,匹配 ws_register_chat_filter_callback 的签名
+ */
+ static void ws_chat_filter_cb_wrapper(char *result)
+ {
+ /* 复用现有过滤实现,忽略返回长度 */
+ chat_filter_result_chars(result);
+ }
+ void net4g_AI_init(void)
+ {
+ ws_register_chat_filter_callback(ws_chat_filter_cb_wrapper);
+ ws_register_ai_question_callback(ble_set_ai_Question_str_);
+ ws_register_ai_answer_callback(ble_set_ai_Answer_str_);
+ }
+
+#endif
#ifdef __cplusplus
#if __cplusplus
#include "NativeRegisterManager.h"
#include "aivoice/include/AiVoiceSelectView.h"
#include "graphic_service.h"
+#include "websocket_server_manager.h"
+#include "custom_utils.h"
namespace OHOS
{
REGIST_MENU_PRO(VIEW_AI_VOICE, AiVoiceView, AiVoicePresenter,
- PNG_APPLIST_AIVOICE_IMAGE_BIG, PNG_APPLIST_AIVOICE_IMAGE, PNG_APPLIST_AIVOICE_IMAGE, "AI全家桶", STR_AI_FAMILY_MEALS);
+ PNG_APPLIST_AIVOICE_IMAGE_BIG, PNG_APPLIST_AIVOICE_IMAGE, PNG_APPLIST_AIVOICE_IMAGE, "星辰AI", STR_AI_FAMILY_MEALS);
#ifdef __cplusplus
extern "C"
#include <asm/delay.h>
#include <aivoice/include/AiVoiceModelC.h>
#include <los_base.h>
- extern void set_need_tts_reconnect(uint8_t flag);
void remove_4GAI_vote(void)
{
void AiVoicePresenter::OnStart()
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStart");
- Presenter<AiVoiceView>::OnStart();
ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
// 开启一个60s取消长亮屏timer
model->ai_start_screen60s_timer();
add_4GAI_vote(); // 4g投票
+ net4g_AI_init();
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI);
Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_ASSISTANT, 100);
}
void AiVoicePresenter::OnStop(void)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop start");
- Presenter<AiVoiceView>::OnStop();
ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
model->StatusResume();
model->AIVoice_StopTimer();
model->stop_update_ai_answer_timer();
model->stop_uapi_stop_tts_timer();
remove_4GAI_vote(); // 移除4g投票
-#if AI_VOICE_ENABLE
- dinit_ai_task();
- ai_cleanup_resources();
+
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_all_websocket_servers();
+ uapi_destroy_all_websocket_servers();
#endif
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
break;
case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
- // set_need_tts_reconnect(0); // 停止tts重连
AiVoiceModel::GetInstance().ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
AiVoiceModel::GetInstance().SetIsClickable(false);
AiVoiceModel::GetInstance().SetIsLimitDisplayed(false);
AiVoiceModel::GetInstance().start_ai_isready_timer();
break;
case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
- // set_need_tts_reconnect(1); // 开始tts重连
break;
case AIVOICE_LISTENING_VIEWID:
- // set_stop_send_ai_flag(0); // 开始发送AI数据
AiVoiceModel::GetInstance().StartListenAndRecordingUserQuestion();
AiVoiceModel::GetInstance().start_listening_timer();
break;
}
if (!model->GetInit_4gai_task())
{
- // init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+// init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+ uapi_init_all_websocket_servers();
+ uapi_start_all_websocket_servers(0); // 连接服务器
+#endif
model->start_ai4g_connect_timer();
ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING
}
}
if (!model->GetInit_4gai_task())
{
+ /* -------------------------------------------------------------------------- */
// init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+ uapi_init_all_websocket_servers();
+ uapi_start_all_websocket_servers(0); // 连接服务器
+#endif
+ /* -------------------------------------------------------------------------- */
model->start_ai4g_connect_timer();
ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING
}
}
else if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮
{
- if (model->GetSelect4gorbt() == AI_SELECT_4G)
- {
-#if AI_VOICE_ENABLE
- uapi_UI_stop_asr();
-#endif
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FINISH_SPEAKING_BUTTON_VIEW_ID:(%d,%d)", model->is_need_to_jump_result_view(), model->getentryTextViewState());
- if (!model->is_need_to_jump_result_view() && !model->getentryTextViewState()) // 没有数据就跳转到思考中界面
- {
- GraphicService::GetInstance()->PostGraphicEvent(
- std::bind(&OHOS::AiVoicePresenter::JumpThinkingView, OHOS::AiVoicePresenter::GetInstance()));
- }
- }
- else if (model->GetSelect4gorbt() == AI_SELECT_BT)
- {
- ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
- }
+ ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
return true;
}
else if (viewId == AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID) // 如果点击的是4G连接方式
if (!model->GetInit_4gai_task())
{
// init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+ uapi_init_all_websocket_servers();
+ uapi_start_all_websocket_servers(0); // 连接服务器
+#endif
model->start_ai4g_connect_timer();
ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_4GSERVICECON_VIEW); // LOADING
}
{
AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer();
AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer();
- // usleep(50000);
- set_clear_queue_stream(1);
- LOS_Msleep(100);
- // uapi_UI_start_asr(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_AIMODE_CONNECTING);
return true;
}
{
AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer();
AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer();
- set_clear_queue_stream(1);
- LOS_Msleep(100);
-#if AI_VOICE_ENABLE
- dinit_ai_task();
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_all_websocket_servers();
+ uapi_destroy_all_websocket_servers();
#endif
}
}
{
if (model->GetSelect4gorbt() == AI_SELECT_4G)
{
-#if AI_VOICE_ENABLE
- dinit_ai_task();
+ // dinit_ai_task();
+#ifdef SUPPORT_AI_SERVICE
+ uapi_stop_all_websocket_servers();
+ uapi_destroy_all_websocket_servers();
#endif
- LOS_Msleep(50);
}
}
ChangeViewAndLogicOperator(it->second.first, it->second.second);
{
if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID))
{
- //开始对话界面,右滑切换界面
+ // 开始对话界面,右滑切换界面
DragLeftToRightChangeAIModel();
}
else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID))
}
else if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT && event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) /*上滑*/
{
- //如果选择的模型是在chatgpt
+ // 如果选择的模型是在chatgpt
if (model->IsExistOpenAIAPIKeys() == true)
{
ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SETAPIKEYS); /*开始对话界面->API Keys set界面*/
/*
- * @Author: luozheng 1732036298@qq.com
- * @Date: 2024-05-07 11:25:58
- * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2025-03-06 16:07:08
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
- */
+* @Author: luozheng 1732036298@qq.com
+* @Date: 2024-05-07 11:25:58
+* @LastEditors: luozheng 1732036298@qq.com
+* @LastEditTime: 2025-03-06 16:07:08
+* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
+*/
#include "aivoice/include/AiVoicePresenter.h"
#include "aivoice/include/AiVoiceView.h"
#include "aivoice/include/AiVoiceModel.h"
#include "wearable_log.h"
#include "ui_resource_string.h"
#include "ConfigModel.h"
+#include "uiservice/include/ui_service.h"
namespace OHOS
{
VolumeProcess->SetKnobStyle(StyleDefault::GetSliderKnobStyle());
VolumeProcess->RequestFocus();
VolumeProcess->SetRotateFactor(5.0);
- // VolumeProcess->SetVisible(false);
+ VolumeProcess->SetVisible(false);
VolumeProcess->SetOnRotateListener(presenter_);
AddViewToRootContainer(VolumeProcess);
}
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView");
if (!CreateAiVoiceScrollView() || !CreateAiVoiceViewImageView() || !CreateAiVoiceViewPicker() ||
- !CreateAiVoiceViewLabel() || !CreateAiVoiceViewButton() || !CreateAiVoiceVoiceView())
+ !CreateAiVoiceViewLabel() || !CreateAiVoiceViewButton())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView fail!");
return nullptr;
void AiVoiceView::OnStart()
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::OnStart");
+ ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_AIMODE_CONNECTING);
+ GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->SetVisible(false);
+ ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_LISTENING_VIEWID);
+ GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->SetVisible(false);
+ ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_THINKING_VIEWID);
+ GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->SetVisible(false);
ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_STARTCHAT_VIEWID);
#if defined(AI_VOICE_FD230) || defined(AI_VOICE_N9)
CreateAiVoiceVoiceView();
return;
}
-
-
/*切换到开始对话Ai界面*/
bool AiVoiceView::ChangeAiVoiceStartChatView(int16_t thisView)
{
AiVoiceScrollView[thisView] = scrollview;
AddViewToRootContainer(AiVoiceScrollView[thisView]);
}
+ if (!AiVoiceModel::GetInstance().GetUserQuestionStr().empty())
+ {
+ SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
+ }
+ if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+ {
+ if (VolumeProcess)
+ {
+ VolumeProcess->SetVisible(true);
+ }
+ }
return true;
}
AiVoiceScrollView[thisView] = scrollview;
AddViewToRootContainer(AiVoiceScrollView[thisView]);
}
+ if(p_AiVoiceConnectingView)
+ {
+ p_AiVoiceConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(true);
+ }
return true;
}
AiVoiceScrollView[thisView] = scrollview;
AddViewToRootContainer(AiVoiceScrollView[thisView]);
}
+ if(p_Aivoice4gServiceConView)
+ {
+ p_Aivoice4gServiceConView->StartOrStopAiVoice4gServiceConImageAnimatorView(true);
+ }
return true;
}
}
static const int16 AiVoiceDestroyMapper[] = {
- AIVOICE_AIMODE_CONNECTING,
+ // AIVOICE_AIMODE_CONNECTING,
AIVOICE_4GSERVICECON_VIEW,
- AIVOICE_LISTENING_VIEWID,
- AIVOICE_THINKING_VIEWID,
+ // AIVOICE_LISTENING_VIEWID,
+ // AIVOICE_THINKING_VIEWID,
AIVOICE_SELECT_VIEW,
AIVOICE_CONNECT_TIMEOUT_VIEWID,
AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID,
break;
}
}
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DestroyTempView:%d",hideView);
switch (hideView)
{
case AIVOICE_AIMODE_CONNECTING:
if (p_AiVoiceConnectingView)
{
- delete p_AiVoiceConnectingView;
- p_AiVoiceConnectingView = nullptr;
+ // delete p_AiVoiceConnectingView;
+ // p_AiVoiceConnectingView = nullptr;
+ p_AiVoiceConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(false);
}
break;
case AIVOICE_4GSERVICECON_VIEW:
{
delete p_Aivoice4gServiceConView;
p_Aivoice4gServiceConView = nullptr;
+ // p_Aivoice4gServiceConView->StartOrStopAiVoice4gServiceConImageAnimatorView(false);
}
break;
case AIVOICE_LISTENING_VIEWID:
if (p_AivoiceListeningView)
{
- if (p_AivoiceListeningView)
- {
- delete p_AivoiceListeningView;
- p_AivoiceListeningView = nullptr;
- }
- // p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(false);
+ // delete p_AivoiceListeningView;
+ // p_AivoiceListeningView = nullptr;
+ p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(false);
}
break;
case AIVOICE_THINKING_VIEWID:
if (p_AivoiceThinkingView)
{
- delete p_AivoiceThinkingView;
- p_AivoiceThinkingView = nullptr;
- // p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(false);
+ // delete p_AivoiceThinkingView;
+ // p_AivoiceThinkingView = nullptr;
+ p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(false);
}
break;
case AIVOICE_SELECT_VIEW:
void AiVoiceView::ChangeView(int16_t hideView, int16_t showView)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView hideView:%d, showView:%d", hideView, showView);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView hideView:%d, showView:%d", hideView, showView);
if (!CheckViewParam(hideView, showView))
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CheckViewParam failed.");