//查询是否可以对话
void uapi_start_asr(void)
{
-// bool state = true;
-// SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"查询uapi_start_asr是否可用\n");
char *jsonString = "{\"header\":{\"event\":\"StartTranscription\",\"trace_id\": \
else
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message erro\n");
- // lwip_close_websocket_client(asr_client);
- // asr_client=NULL;
- // disconnect_server=1;
}
- // uapi_tts_paly_stop();
}
void uapi_start_asr_task(void)
do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_AI_SEND_TEST, nullptr, 0);
- // char *jsonString = "{\"header\":{\"event\":\"StartTranscription\",\"trace_id\": \
- // \"3fa6b9e6a30b407ea38ad7ae69e6c291\"},\"payload\":{\"format\":\"MP3\",\"sample_rate\":16000}}";
-
- // if (send_websocket_message(asr_client,( const unsigned char *)jsonString,strlen(jsonString),WS_TEXT)==0)
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
- // else
- // {
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message erro\n");
- // // lwip_close_websocket_client(asr_client);
- // // asr_client=NULL;
- // // disconnect_server=1;
- // }
}
{
char *jsonString ="{\"header\":{\"event\":\"StopTranscription\",\"trace_id\":\"3fa6b9e6a30b407ea38ad7ae69e6c291\"}}";
- // uapi_tts_paly_init();
-
if (send_websocket_message(asr_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
else
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message erro\n");
- // lwip_close_websocket_client(asr_client);
- // asr_client=NULL;
-
- // disconnect_server=1;
}
}
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message fail 0\n");
}
- //
+
}
void record_test(void)
if(read_size!=0)
{
send_msg_data_into_Ai_msg_queue((void *)buf,(uint16_t)read_size,0);
- // send_ai_bin(buf,read_size);
- // bk_sleep(100);
read_size_num+=read_size;
}
memset_s(result_str_asr,256,0,256);
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);
+ ble_set_ai_Question_str(result_str_asr);
stop_AudioCaptureProcess_AI();
- // uapi_stop_asr();
send_ai_txt(0,result_str_asr);
- // uapi_stop_asr();
- // stop_AudioCaptureProcess_AI();
}
if(strcmp(event_str,"TranscriptionStarted")==0) //可以对话了,切换到聆听界面
{
//查询结果
- // streamingRecordAndSend_AI(0);
startAudioCaptureTask();
-// do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_AI_SEND_TEST, nullptr, 0);
-
- if(asr_is_start==0)
- {
- asr_is_start=1;
-
- 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));
- // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_AI_SEND_TEST, nullptr, 0);
-
- }
- else
- {
- // uapi_stop_asr();
- }
-
}
- if(strcmp(event_str,"TranscriptionCompleted")==0) //可以对话了,切换到聆听界面
+ if(strcmp(event_str,"TranscriptionCompleted")==0) //asr 结束
{
- //查询结果
- // streamingRecordAndSend_AI(0);
- // startAudioCaptureTask();
- {
- asr_is_start=0;
- }
return false;
-
}
if(strcmp(event_str,"Failed")==0)
{
stop_AudioCaptureProcess_AI();
- asr_is_start=0;
-
- // bool state = false;
- // SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
- // uapi_stop_asr();
return false;
}
while (client_count)
{
- tts_client = init_websocket_client("ws://118.145.158.207:22080/tts/stream?audio_buffer_size=8192",NULL,0);
+ tts_client = init_websocket_client("ws://118.145.158.207:22080/tts/stream?audio_buffer_size=4096",NULL,0);
if (tts_client== NULL)
{
{
- memset_s(tts_recv_buf,1024*8,0,1024*8);
- int len=receive_websocket_message(tts_client,(unsigned char *)tts_recv_buf,1024*8,&type);
+ memset_s(tts_recv_buf,1024*4,0,1024*4);
+ int len=receive_websocket_message(tts_client,(unsigned char *)tts_recv_buf,1024*4,&type);
// if(type==WS_CONT ||
if( type==WS_CLOSE || len==-1)//|| type==WS_CONT )
{
// tts_cache_file((uint8_t *)tts_recv_buf,len);——
// AIStreamWrite((uint8_t *)tts_recv_buf,len);
send_msg_data_into_Ai_msg_queue((uint8_t *)tts_recv_buf,len,200);
-
+ printf("bk_websocket_demo tts %d\n",len);
//
bk_sleep(1);
- printf("bk_websocket_demo %d\n",len);
+
}
else if(type==WS_TEXT)
{