/**
* @brief 初始化WebSocket消息队列
*/
-static int ws_queue_init(ws_message_queue_t* queue)
+static int ws_queue_init(ws_message_queue_t* queue,uint32_t queue_size)
{
if (!queue) return -1;
memset(queue, 0, sizeof(ws_message_queue_t));
/* 创建osal消息队列 */
- int ret = osal_msg_queue_create("ws_queue", WS_QUEUE_SIZE, &queue->queue_id, 0, sizeof(ws_message_item_t));
+ uint32_t true_queue_size;
+ if(queue_size!=0)
+ true_queue_size=queue_size;
+ else
+ true_queue_size=WS_QUEUE_SIZE;
+
+ int ret = osal_msg_queue_create("ws_queue", true_queue_size, &queue->queue_id, 0, sizeof(ws_message_item_t));
if (ret != OSAL_SUCCESS) {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create osal message queue for ws queue");
return -1;
ws_queue_deinit(&tts_msg_queue);
}
- ret |= ws_queue_init(&chat_msg_queue);
- ret |= ws_queue_init(&asr_msg_queue);
- ret |= ws_queue_init(&tts_msg_queue);
+ ret |= ws_queue_init(&chat_msg_queue,256);
+ ret |= ws_queue_init(&asr_msg_queue,0);
+ ret |= ws_queue_init(&tts_msg_queue,0);
// ret |= ws_queue_init(&voice_msg_queue);
if (ret != 0) {
}
#endif
+ uapi_start_tts();
+
if(stop_AudioCaptureProcess_AI())
{
asr_is_stop=1;
}
-
-
+char tts_task_id_buf[128]={0};
+uint8_t tts_is_ready=0;
void uapi_start_tts(void)
{
char *jsonString =
"{\"header\": \
{ \"event\": \"StartSynthesis\",\
- \"trace_id\": \"3fa6b9e6a30b407ea38ad7ae69e6c291\"},\
+ \"trace_id\": \"\"},\
\"payload\": \
{\"voice\":\"xiaoyun\",\
\"format\":\"mp3\",\
\"speech_rate\":0}\
}";
- printf("uapi_start_tts : %s\r\n",jsonString);
+ printf("uapi_start_tts :%s\r\n",jsonString);
+
if (send_websocket_message(tts_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
+{
+ memset_s(tts_task_id_buf,128,0,128);
+ tts_is_ready=0;
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
}
+
+}
void uapi_stop_tts(void)
{
char *jsonString =
" { \
- \"header \": { \
+ \"header\": { \
\"event\": \"StopSynthesis\", \
- \"trace_id\": \" 3fa6b9e6a30b407ea38ad7ae69e6c291 \" \
+ \"trace_id\": \"\" \
} \
} ";
printf("uapi_start_tts : %s\r\n",jsonString);
if (send_websocket_message(tts_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
+{
+ tts_is_ready=0;
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
}
+
+}
void uapi_start_tts_single(void)
{
+
char *jsonString =
" { \"header\": { \
\"event\": \"LongTextStream\",\
}
-bool uapi_start_tts_single_txt(char *buf)
+void uapi_start_tts_single_txt(char *buf)
{
+
+ if(tts_is_ready!=1)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_start_tts_single_txt no tts_is_ready \n");
+ return;
+ }
char *jsonString = (char *)malloc(strlen(buf)+300);// [512] ={0};
sprintf(jsonString,
- // " {\" header\" : { \
- // \"event\": \" RunSynthesis\", \
- // \"trace_id \": \" 3fa6b9e6a30b407ea38ad7ae69e6c291 \" \
- // }, \
- // \"payload \": { \
- // \"text \":\" %s \" \
- // }}"
-
- " { \"header\": { \
- \"event\": \"LongTextStream\", \
- \"trace_id\": \"3fa6b9e6a30b407ea38ad7ae69e6c291\"\
- },\
- \"payload\": {\
- \"voice\":\"xiaoyun\",\
- \"format\":\"mp3\",\
- \"sample_rate\":16000,\
- \"volume\":80,\
- \"speech_rate\":0,\
- \"text\":\"%s\"\
- } } "
+ "{\"header\" : { \
+ \"event\": \"RunSynthesis\", \
+ \"trace_id\": \"%s\" \
+ }, \
+ \"payload\": { \
+ \"text\":\"%s\" \
+ }}"
+
+ // "{ \"header\": { \
+ // \"event\": \"LongTextStream\", \
+ // \"trace_id\": \"3fa6b9e6a30b407ea38ad7ae69e6c291\"\
+ // },\
+ // \"payload\": {\
+ // \"voice\":\"xiaoyun\",\
+ // \"format\":\"mp3\",\
+ // \"sample_rate\":16000,\
+ // \"volume\":80,\
+ // \"speech_rate\":0,\
+ // \"text\":\"%s\"\
+ // } }"
- ,buf);
+ ,tts_task_id_buf,buf);
- printf("uapi_start_tts : %s\r\n",jsonString);
+ printf("uapi_start_tts_single_txt :%s\r\n",jsonString);
if (send_websocket_message(tts_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
{
fclose(fp);
}
}
+// {"header":{"event":"StartedSynthesis","msg":"success","status":20000000,"task_id":"8e8996f9148b66738309602ec3219412"}}
+bool tts_analysis(char *buf)
+{
+ cJSON* root = cJSON_Parse((const char *)buf);
+ if (root == NULL) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析失败\n");
+ return false;
+ }
+ char *event_str=NULL;
+ char *task_id_str=NULL;
+ char *msg_str=NULL;
+
+
+
+ cJSON* header = cJSON_GetObjectItem(root, "header");
+ if(header)
+ {
+ cJSON* event = cJSON_GetObjectItem(header, "event");
+ if (event && cJSON_IsString(event)) {
+ event_str= event->valuestring;
+ }
+
+ cJSON* msg = cJSON_GetObjectItem(header, "msg");
+ if (msg && cJSON_IsString(msg)) {
+ msg_str= msg->valuestring;
+
+ if(strcmp("StartedSynthesis",event_str)==0 && strcmp("success",msg_str)==0)
+ {
+ tts_is_ready=1;
+ }
+ }
+
+ cJSON* task_id = cJSON_GetObjectItem(header, "task_id");
+
+ if (task_id && cJSON_IsString(task_id))
+ {
+ memcpy_s(tts_task_id_buf,128,task_id->valuestring,strlen(task_id->valuestring));
+ }
+ }
+ cJSON_Delete(root);
+ return true;
+}
+
uint8_t is_bk_websocket_tts=0;
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "TTS binary data received: %d bytes", len);
msleep(1);
} else if (type == WS_TEXT) {
- WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "TTS text data received: %s %d %d", tts_recv_buf,bk_websocket_tts_tick,osKernelGetTickCount());
- send_msg_data_into_Ai_msg_queue((uint8_t *)tts_recv_buf, len, 201);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "TTS text data received: %s", tts_recv_buf);
+ // send_msg_data_into_Ai_msg_queue((uint8_t *)tts_recv_buf, len, 201);
bk_websocket_tts_tick = 0;
+ if(tts_analysis(tts_recv_buf))
+ {
+ // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "TTS text tts_analysis: %s", tts_recv_buf);
+ }
} else if (type == WS_PONG) {
tts_client_ping = 0;
}