#include "custom_runtime.h"
#include "voice_call_volte_sample_wrapper.h"
#include <los_base.h>
+#include <websocket_server_manager.h>
namespace OHOS
{
// 声明定时器变量
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G");
if (GetInit_4gai_task())
{
-#if AI_VOICE_ENABLE
- uapi_UI_start_asr(GetCurUsing4GAiModelType());
-#endif
- }
+ // uapi_UI_start_asr(GetCurUsing4GAiModelType());
+ uapi_start_asr_StartTranscription();
+ }
else
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init_4gai_task fail!!");
{
return false;
}
-
+
if (!AddUserQuestionToChatItems())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!");
{
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();
}
}
}
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();
+ uapi_stop_asr_StopTranscription();
}
else if (GetSelect4gorbt() == AI_SELECT_BT)
{
AiVoiceModel::GetInstance().AIVoice_StopTimer();
AiVoiceModel::GetInstance().SetErrnote("连接超时,请重新开始对话");
std::string str = AiVoiceModel::GetInstance().GetErrnote();
-#if AI_VOICE_ENABLE
- dinit_ai_task(); // 所有服务都删除重新连一下服务器
-#endif
+
+ if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+ {
+ // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+ stop_all_websocket_servers();
+ destroy_all_websocket_servers();
+ }
+
SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
}
else
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
if ((view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr) &&
(view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible()))
{
-#if AI_VOICE_ENABLE
- dinit_ai_task(); // 所有服务都删除重新连一下服务器
-#endif
+ if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+ {
+ // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+ stop_all_websocket_servers();
+ destroy_all_websocket_servers();
+ }
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));
if ((view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW) != nullptr) &&
(view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW)->IsVisible()))
{
-#if AI_VOICE_ENABLE
- dinit_ai_task(); // 所有服务都删除重新连一下服务器
-#endif
+ // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+ stop_all_websocket_servers();
+ destroy_all_websocket_servers();
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)
- {
- return clear_queue_stream;
- }
+#ifdef BLE_INSTRUCT
- // 清空队列中可能存在的音频数据
- void set_clear_queue_stream(uint8_t state)
- {
- clear_queue_stream = state;
- }
-
-
- #ifdef BLE_INSTRUCT
-
- #include "bleEvent.h"
- #include "bleInstruct.h"
+#include "bleEvent.h"
+#include "bleInstruct.h"
void ble_set_ai_Question_str_(char *buf)
{
OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf));
}
-
- void ble_set_ai_Answer_str_(char *buf,uint8_t type)
+ void ble_set_ai_Answer_str_(char *buf, uint8_t type)
{
- OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf),type);
+ OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf), type);
}
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_;
}
- #endif
-
+#endif
#ifdef __cplusplus
#if __cplusplus
#include "NativeRegisterManager.h"
#include "aivoice/include/AiVoiceSelectView.h"
#include "graphic_service.h"
+#include "websocket_server_manager.h"
namespace OHOS
{
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();
-#endif
+
+ stop_all_websocket_servers();
+ destroy_all_websocket_servers();
+
+ // dinit_ai_task();
+ // ai_cleanup_resources();
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop end");
}
if (!model->GetInit_4gai_task())
{
+ /* -------------------------------------------------------------------------- */
// init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+ init_all_websocket_servers();
+ start_all_websocket_servers(); // 连接服务器
+ /* -------------------------------------------------------------------------- */
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());
+ init_all_websocket_servers();
+ start_all_websocket_servers(); // 连接服务器
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();
-#endif
+ stop_all_websocket_servers();
+ destroy_all_websocket_servers();
}
}
ChangeViewAndLogicOperator(it->second.first, it->second.second);
{
if (model->GetSelect4gorbt() == AI_SELECT_4G)
{
-#if AI_VOICE_ENABLE
- dinit_ai_task();
-#endif
- LOS_Msleep(50);
+ // dinit_ai_task();
+ stop_all_websocket_servers();
+ destroy_all_websocket_servers();
}
}
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界面*/