str.swap(result);
}
- static int fouce_count = 0; //
+ static int fouce_count = 0; //
void AiVoiceModel::ProcessTextByPunctuation()
{
const std::string punctuation = ",。!?;:))“”、\"\""; // 要替换的中文标点
- const char replacement = ','; // 替换为英文逗号
- const size_t MAX_SEGMENT_LENGTH = 120; // 最大分段长度
- const size_t MIN_SEGMENT_LENGTH = 1; // 最小发送长度(可调整)
+ const char replacement = ','; // 替换为英文逗号
+ const size_t MAX_SEGMENT_LENGTH = 120; // 最大分段长度
+ const size_t MIN_SEGMENT_LENGTH = 1; // 最小发送长度(可调整)
if (accumulatedText.empty())
return;
// 发送失败,等待下次发送
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送");
fouce_count++;
- if(fouce_count >= 3)
+ if (fouce_count >= 3)
{
uapi_start_tts();
fouce_count = 0;
// 发送失败,等待下次发送
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送");
fouce_count++;
- if(fouce_count >= 3)
+ if (fouce_count >= 3)
{
uapi_start_tts();
fouce_count = 0;
auto it = selectAiModelToTextId.find(GetSelectAiModel());
if (it != selectAiModelToTextId.end())
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
+ // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
if (get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW)
{
uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH);
}
else
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelectAiModel fail!!", size, it->second.second);
+ // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelectAiModel fail!!", size, it->second.second);
}
ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
if (LISTENING_TIMEOUT <= 0)
{
// AiVoiceModel::GetInstance().StopListenAndRecordingUserQuestion(); // 停止聆听用户问题
- AiVoiceModel::GetInstance().stop_listening_timer(); // 停止聆听定时器
+ AiVoiceModel::GetInstance().stop_listening_timer(); // 停止聆听定时器
AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance();
if (AiVoicePresenter::GetInstance() && AivoiceListeningView::GetInstance())
{
}
}
}
-#if 0
+#if 1
else
{
if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G");
if (AiVoiceModel::GetInstance().GetInit_4gai_task())
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111:%d",AiVoiceModel::GetInstance().get_is_delay_start_asr());
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "222:%d",get_ai_asr_service_init_flag());
- if (!AiVoiceModel::GetInstance().get_is_delay_start_asr())
+ if (get_asr_is_ready_start())
{
- if (get_ai_asr_service_init_flag() == 0)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "发送查询");
- uapi_UI_start_asr(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
- AI_IS_READY_TIMEOUT = 5;
- AiVoiceModel::GetInstance().set_is_delay_start_asr(true);
- }
- else
- {
- usleep(10000);
- }
+ bool state = true;
+ SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
}
}
}
{
if (view_ != nullptr && p_AiVoicePresenter != nullptr)
{
- if(uapi_get_server_state_is_end())
+ if (uapi_get_server_state_is_end())
{
init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
return;
AiVoiceModel::GetInstance().ProcessTextByPunctuation();
}
- #if 0
+#if 0
// 当前回调中get_bk_websocket_tts_tick()是否为0
bool current_tick_zero = (get_bk_websocket_tts_tick() == 0);
}
}
}
- #endif
+#endif
return;
}
}
}
-
static osTimerId_t g_uapi_stop_tts_Handle = nullptr;
static void AI4G_UAPI_STOP_TTS_CallbackProc(int data)
{
return;
}
}
-
+
void AiVoiceModel::stop_uapi_stop_tts_timer(void)
{
// 检查定时器是否存在
{
return bk_websocket_tts_tick;
}
+
+static uint8_t asr_is_ready_start = 0;
+uint8_t get_asr_is_ready_start(void)
+{
+ return asr_is_ready_start;
+}
void asr_on_ws_packet_callback(uint8_t* data, size_t datalen, WebSocketMessageType type)
{
if(asr_client !=NULL && asr_client->msg_queue !=NULL)
chat_reconnect = 0;
retry_count = 0;
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting chat client...");
+ msleep(100);
goto char_reconnet;
}
+
//查询是否可以对话
void uapi_start_asr(void)
{
\"3fa6b9e6a30b407ea38ad7ae69e6c291\"},\"payload\":{\"format\":\"MP3\",\"sample_rate\":16000}}";
if (send_websocket_message(asr_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
+ AI_LOCK();
+ asr_is_ready_start = 0;
+ AI_UNLOCK();
+ }
else
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message erro\n");
// //上传文件
// }
- bool state = true;
- SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
+ // bool state = true;
+ // SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
+ AI_LOCK();
+ asr_is_ready_start = 1;
+ AI_UNLOCK();
}
if(strcmp(event_str,"TranscriptionCompleted")==0) //asr 结束
msleep(10); // 避免过度占用CPU
}
- if (disconnect_server == 0) {
- WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting ASR client...");
- goto ASR_SATRT;
- }
+
AI_LOCK();
set_ai_asr_service_init_flag(0);
AI_UNLOCK();
asr_client = NULL;
ws_queue_cleanup(&asr_msg_queue);
+
+ if (disconnect_server == 0) {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting ASR client...");
+ msleep(100);
+ goto ASR_SATRT;
+ }
+
asr_client_ping = 0;
- msleep(1000);
+ // msleep(1000);
}
asr_cleanup_and_exit:
retry_count = 0;
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting TTS client...");
tts_reconnect = 0;
+ msleep(100);
goto TTS_SATRT;
}
}