From: p15692025051 <846603105@qq.com> Date: Wed, 16 Jul 2025 06:28:19 +0000 (+0800) Subject: 文件更新 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=ee4ae299f8aac7c09bfb81ea2b69567731a5c246;p=mirrors%2FFX01.git 文件更新 --- diff --git a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c index 68013d3..41a9ac0 100644 --- a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c +++ b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c @@ -38,6 +38,7 @@ #include "bk_make_time.h" // #include "opus/include/opus.h" char FXH01_Version[100]; + u8 current_card_id = 0; u8 VC_TTS_PLAY_EVENT = 0; typedef enum @@ -46,7 +47,7 @@ typedef enum attributes_format_OPUS, }attributes_format_type; attributes_format_type inbound_attributes_format = attributes_format_PCM; -attributes_format_type outbound_attributes_format = attributes_format_OPUS; +attributes_format_type outbound_attributes_format = attributes_format_PCM; #define OPUS_ENCODER_PACK_MS 60 //多少ms一帧数据 @@ -91,6 +92,10 @@ static void AI_VC_play_task(void *thread_input);//音频播放线程 static void AI_VC_record_task(void *thread_input);//录音线程 static void AI_client_VC_synthesis(char *str); static void AI_VC_put_record_data(char *data,u32 len); +//websocket 资源管控,防止不释放 +#define WEBSOCKET_MAX_NUM 12 +WebSocketClient* websocket_res[WEBSOCKET_MAX_NUM] = {0}; + WebSocketClient *AI_client_VC = NULL; static u32 close_timerout = 0; static u32 VC_pingping_timerout = 0; @@ -110,7 +115,7 @@ static void play_file_stop(void); int get_AI_key_longstate(void); -static void AI_VC_send_satrt(void); +static void AI_VC_send_satrt(char is_greeting); static aos_status AI_VC_send_data(char *data,u32 len,u8 AIC_WEBSOCKET_OPCODE); VC_state_type VC_state = VC_State_None; static u8 uid[50]; @@ -272,7 +277,7 @@ void reset_VC_cfg(void) { vc_cfg.start_flag = 0xaaaa; vc_cfg.end_flag = 0xaaaa; - vc_cfg.dev_type = DEV_FX1_H;//产品 + //vc_cfg.dev_type = DEV_FX1_H;//产品 //vc_cfg.dev_type = DEV_ADS;//奥德赛 vc_cfg.dev_type = DEV_JSWM;//金山完美 //vc_cfg.dev_type = DEV_ALY;//阿里云 @@ -615,8 +620,8 @@ static void AI_client_VC_synthesis(char *str) free(json_str); cJSON_Delete(root); } -//开始事件 -static void AI_VC_send_satrt(void) +//开始事件 is_greeting//是否开启开场白 +static void AI_VC_send_satrt(char is_greeting) { // 创建根对象 cJSON *root = cJSON_CreateObject(); @@ -658,9 +663,17 @@ static void AI_VC_send_satrt(void) // 创建 greeting 对象 cJSON *greeting = cJSON_CreateObject(); - cJSON_AddBoolToObject(greeting, "enabled", FALSE); - cJSON_AddStringToObject(greeting, "content", "123456789123456789"); - cJSON_AddItemToObject(dialog_cfg, "greeting", greeting); + if(is_greeting == 1) + { + cJSON_AddBoolToObject(greeting, "enabled", TRUE);//是否播放提示词 + cJSON_AddStringToObject(greeting, "content", "你好"); + cJSON_AddItemToObject(dialog_cfg, "greeting", greeting); + }else + { + cJSON_AddBoolToObject(greeting, "enabled", FALSE);//是否播放提示词 + + } + // 创建 bot_option 对象 cJSON *bot_option = cJSON_CreateObject(); @@ -673,7 +686,7 @@ static void AI_VC_send_satrt(void) if(vc_cfg.dev_type == DEV_ADS) { cJSON_AddBoolToObject(bot_option, "use_workflow", 0);//奥德赛 - cJSON_AddStringToObject(bot_option, "bot_id", "7507478798502625295");//奥德赛 + cJSON_AddStringToObject(bot_option, "bot_id", "7525301449820291111");//奥德赛 cJSON_AddStringToObject(bot_option, "workflow_id", ""); }else @@ -872,43 +885,43 @@ static void AI_VC_send_audio_completed(void) free(json_str); cJSON_Delete(root); } -//打断 -static void AI_VC_send_cancel(void) -{ - // 创建根对象 - cJSON *root = cJSON_CreateObject(); - if (root == NULL) { - bk_printf("Failed to create root object.\n"); - return ; - } - - // 设置 "event" 字段 - cJSON_AddStringToObject(root, "event", "cancel"); - - // 创建 "payload" 对象 - cJSON *payload = cJSON_CreateObject(); - if (payload == NULL) { - bk_printf("Failed to create payload object.\n"); - cJSON_Delete(root); - return ; - } - // 将 "payload" 对象添加到根对象中 - cJSON_AddItemToObject(root, "payload", payload); - - // 将 JSON 对象转换为字符串 - char *json_str = cJSON_Print(root); - if (json_str == NULL) { - bk_printf("Failed to print JSON object.\n"); - cJSON_Delete(root); +// //打断 +// static void AI_VC_send_cancel(void) +// { +// // 创建根对象 +// cJSON *root = cJSON_CreateObject(); +// if (root == NULL) { +// bk_printf("Failed to create root object.\n"); +// return ; +// } + +// // 设置 "event" 字段 +// cJSON_AddStringToObject(root, "event", "cancel"); + +// // 创建 "payload" 对象 +// cJSON *payload = cJSON_CreateObject(); +// if (payload == NULL) { +// bk_printf("Failed to create payload object.\n"); +// cJSON_Delete(root); +// return ; +// } +// // 将 "payload" 对象添加到根对象中 +// cJSON_AddItemToObject(root, "payload", payload); + +// // 将 JSON 对象转换为字符串 +// char *json_str = cJSON_Print(root); +// if (json_str == NULL) { +// bk_printf("Failed to print JSON object.\n"); +// cJSON_Delete(root); - } - AI_VC_send_data(json_str,strlen(json_str),AIC_WEBSOCKET_OPCODE_TEXT_FRAME);//发送数据 +// } +// AI_VC_send_data(json_str,strlen(json_str),AIC_WEBSOCKET_OPCODE_TEXT_FRAME);//发送数据 - // 释放内存 - free(json_str); - cJSON_Delete(root); -} +// // 释放内存 +// free(json_str); +// cJSON_Delete(root); +// } //TTS播放 static void VC_TTS_Play(const char *str) { @@ -923,7 +936,7 @@ static void VC_TTS_Play(const char *str) //VC_record_End(); VC_Play_End(); websocket_deconnect_VC(); - AI_VC_start(); + AI_VC_start(0); } //pinpin发送 void AI_VC_send_ping_ping(void) @@ -1496,7 +1509,7 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 { int ret=0; //bk_stream_play_start(); - AI_VC_audio_queue_t AI_VC_play_queue_data; + AI_VC_audio_queue_t AI_VC_play_queue_data = {0}; aos_status queue_ret = AOS_ERROR; AI_VC_play_task_flag = 1; bk_printf("AI_VC_play_task go......"); @@ -1524,6 +1537,11 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 queue_ret = aos_recv_from_queue(AI_VC_play_queue,&AI_VC_play_queue_data,AOS_NO_WAIT); if( queue_ret== AOS_SUCCESS) { + if(AI_VC_play_queue_data.len> 32*1024)//数据太大,可能是出错了 + { + bk_printf("AI_VC_play_queue 数据太大!!!!!!!!!!!"); + break; + } if( AI_VC_play_queue_data.data) { ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, @@ -1581,15 +1599,79 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 } +int add_websocket_res(WebSocketClient* websocket) +{ + //if(AI_client_VC->sockfd >=0)//做socket资源回收,防止socket占用 + + for(int i = 0;isockfd); + websocket_res[i] = NULL; + } + } +} +//获取ws可以资源 +int get_websocket_res_num(void) +{ + int num = 0; + for(int i = 0;isockfd); + } //创建发送线程 if(AI_VC_send_task_id == 0) @@ -1660,7 +1759,10 @@ static int websocket_connect_VC(void) AOS_AUTO_START); bk_printf("创建读线程 AI_VC_read_task_id:%d",AI_VC_read_task_id); } - return 0; + CONNECT_RET: + if(url) + aic_free(url); + return ret; } static void websocket_deconnect_VC(void) @@ -1675,6 +1777,7 @@ static void websocket_deconnect_VC(void) // } if(AI_client_VC)//先断开再关闭读线程 { + delete_websocket_res(AI_client_VC);//删除该对象ws资源管控 close_websocket_client(AI_client_VC); AI_client_VC = NULL; } @@ -2142,7 +2245,7 @@ void AI_key_press(void) VC_state = VC_State_None; VC_record_Start() ; - if(AI_VC_start()==0) + if(AI_VC_start(0)==0) { play_file_stream_data("C:/chenggong.pcm"); //audio_play_tone(3,300);//播放提示音,测试用,位置不能变,和双向流有冲突 @@ -2223,7 +2326,8 @@ int32_t bk_audio_start_callback(void *p_param, uint32_t size) return 0; } char AI_VC_start_lock = 0; -int AI_VC_start(void) +//is_greeting,是否播放开场白 +int AI_VC_start(char is_greeting) { power_off_count = 6*60*24;//24小时倒计时 int ret = 0,status = 0; @@ -2303,6 +2407,12 @@ int AI_VC_start(void) conf.vad_log_level = 0; int init_vad_ret = 0; strcpy(conf.auth_info.dmp_token, get_token()); + static int imsl_nn_init_flag = -1; + if (imsl_nn_init_flag != 0) { + extern imsl_nn_printf_func imsl_nn_printf; + imsl_nn_printf = bk_printf; + imsl_nn_init_flag = 0; + } init_vad_ret = init_vad(&conf); @@ -2343,7 +2453,7 @@ int AI_VC_start(void) } //aos_sleep(5); - AI_VC_send_satrt();// + AI_VC_send_satrt(is_greeting);// close_timerout = 0; AI_VC_start_RET: AI_VC_start_lock = 0; @@ -2370,7 +2480,7 @@ void AI_VC_Close(void) // aic_gpio_output(GPIO_20,GPIO_OUTPUT_LVL_LOW ); bk_printf("AI_VC_Close!!!!!!!!!!!!"); - + websocket_deconnect_VC();//断开连接 //销毁录音线程 if(AI_VC_record_task_id != 0) { @@ -2458,7 +2568,7 @@ void AI_VC_Close(void) VC_Play_End(); bk_printf("AI_VC_Close2!!!!!!!!!!!!"); - websocket_deconnect_VC(); + //销毁发送队列,不在websocket_deconnect_VC里调用,避免重连需要发指令 if(AI_VC_send_queue != NULL) { @@ -2585,6 +2695,8 @@ static void sys_10S_timeout_even(void) // aut_active();//没有密钥走激活 // //每小时登录一次 // aut_login(); + static u8 chg_status_tmp = 0; + static u8 is_Low_power_warning = 0; login_timer_count++; if(login_timer_count>60*6) { @@ -2602,16 +2714,31 @@ static void sys_10S_timeout_even(void) } struct psy_info psy_info; get_psy_info(&psy_info); - if(psy_info.bat_capacity> 15 &&psy_info.bat_capacity<=25 && AI_VC_stata == 0) - { - play_audio_file("C:/Low_power_warning.mp3"); - }else if(psy_info.bat_capacity<=15) + //bk_printf("充电状态:%d",psy_info.bat_chg_status); + if(psy_info.bat_chg_status == 2)//没在充电状态 { - // AI_AMP_MSG_put(NULL,0,VC_CLOSE);//关闭对话 - // play_audio_file("C:/didianguanji.mp3");//播放低电关机 - AI_AMP_MSG_put("C:/didianguanji.mp3",strlen("C:/didianguanji.mp3"),POWER_OFF); + + if(psy_info.bat_capacity> 15 &&psy_info.bat_capacity<=25 && AI_VC_stata == 0 && is_Low_power_warning == 0 )//只响一次 + { + play_audio_file("C:/Low_power_warning.mp3"); + is_Low_power_warning =1; + }else if(psy_info.bat_capacity<=15) + { + // AI_AMP_MSG_put(NULL,0,VC_CLOSE);//关闭对话 + // play_audio_file("C:/didianguanji.mp3");//播放低电关机 + AI_AMP_MSG_put("C:/didianguanji.mp3",strlen("C:/didianguanji.mp3"),POWER_OFF); + + } + }else if(psy_info.bat_chg_status == 1)//充电状态 + { + } + if(chg_status_tmp != psy_info.bat_chg_status)//状态发生改变,清掉状态 + { + is_Low_power_warning =0; + } + chg_status_tmp = psy_info.bat_chg_status; // bk_printf("电量查询:psy_name:%s bat_vol:%d bat_cap:%d chg_status%d chg_type:%d bat_min_voltage:%d bat_max_voltage:%d\n", // psy_info.psy_name, @@ -2684,8 +2811,14 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 // { // aos_sleep(1000); // } - - VC_TTS_Play(vc_cfg.power_on_tone);//开启vc播放tts + if(vc_cfg.dev_type == DEV_JSWM)//金三完美使用dmp配置开场白 + { + AI_VC_start(1); + } + else{ + VC_TTS_Play(vc_cfg.power_on_tone);//开启vc播放tts + } + while (1) { if(AI_AMP_task_queue) { @@ -2717,7 +2850,7 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 VC_state = VC_State_None; websocket_deconnect_VC(); websocket_connect_VC();//重连 - AI_VC_send_satrt();//发送开始 + AI_VC_send_satrt(0);//发送开始 break; @@ -2725,7 +2858,7 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 AI_VC_Close(); break; case VC_START: - AI_VC_start(); + AI_VC_start(0); break; case VC_PLAY_START: VC_Play_Start(); diff --git a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h index 5ae70da..0f4d2da 100644 --- a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h +++ b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h @@ -121,7 +121,7 @@ typedef struct u32 len; }AI_VC_audio_queue_t; -int AI_VC_start(void); +int AI_VC_start(char is_greeting); void AI_VC_Close(void); int bk_printf(const char *format, ...); void bk_print_hex(u8 *data,int data_len); diff --git a/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c b/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c index 7db4371..a4f06fb 100644 --- a/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c +++ b/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c @@ -106,14 +106,14 @@ void set_url_error(BK_URL *url, const char *error_msg) { // 解析URL的函数 BK_URL parse_url(const char *url) { bk_printf("parse_url url=%s.\n",url); - BK_URL result = {NULL, NULL, 0, NULL, NULL, 0, NULL}; + BK_URL result = {NULL, NULL, 0,{0}, NULL, NULL, 0, NULL}; char *temp_url_t = bk_strdup(url); char *temp_url = temp_url_t; if (!temp_url) { set_url_error(&result, "Failed to allocate memory for temp_url"); return result; } - + // 解析协议 char *colon = strchr(temp_url, ':'); if (!colon) { @@ -151,7 +151,7 @@ BK_URL parse_url(const char *url) { aic_free(temp_url_t); return result; } - + result.port = atoi(colon_port + 1); if (!result.port) { set_url_error(&result, "Invalid port number"); @@ -714,10 +714,16 @@ WebSocketClient *init_websocket_client(const char *url, const char *headers) { } close( client->sockfd ); - goto client_ERROR; - bk_printf("init_websocket_client connect error"); + + } freeaddrinfo(addr_list); // 释放资源 + if(client->sockfd<0) + { + bk_printf("init_websocket_client connect error"); + goto client_ERROR; + } + bk_printf("init_websocket_client connect ok,sockfd:%d",client->sockfd); // client->sockfd = socket(AF_INET, SOCK_STREAM, 0); // if (client->sockfd < 0) { @@ -930,7 +936,7 @@ int http_get_client(const char *url, const char *headers,const char *Content_Typ // goto client_ERROR; // } - + close(client->sockfd); free_url(parsed_url); if(client) aic_free(client); diff --git a/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h b/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h index df41968..466205c 100644 --- a/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h +++ b/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h @@ -1,23 +1,42 @@ -#include +#ifndef _IMSL_KWS_DLL +#define _IMSL_KWS_DLL + +#ifndef _IMSL_NN_COMMON +#define _IMSL_NN_COMMON +typedef int (*imsl_nn_printf_func)(const char *format, ...); + +struct AuthInfo +{ + char dmp_token[64]; +}; +#endif + struct KwsConfig { - int min_activate_len; // 最小检测多少ms的激活才算检测到关键词 !!! 必须小于 max_activate_gap 和 200 + int min_activate_len; // 最小检测多少ms的激活才算检测到关键词 int max_activate_gap; // 关键词激活点最长持续时间 比如 100ms 时检测到关键词但是未达到最短长度,直到100ms + max_activate_gap 这个时间点使激活失效 int active_threshold; // 激活阈值 int kws_log_level; // kws log打印控制, 0 不打印,1 INFO,2 INFO DEBUG + + struct AuthInfo auth_info; }; /* 初始化kws解码器,默认配置见下方的example */ -int init_kws(struct KwsConfig* conf); +int init_kws(const struct KwsConfig* conf); void run_kws(const int16_t* data, const int data_len); int kws_detect(); void kws_clear(); void free_kws(); +#endif + /* example 只使用kws +// 设置log函数 +extern imsl_nn_printf_func imsl_nn_printf; +imsl_nn_printf = printf; // 初始化 struct KwsConfig kws_conf; @@ -40,7 +59,9 @@ if (kws_status == 1) { free_kws(); */ -/* example 配合vad使用 + + +/* example 2 配合vad使用 // 初始化 diff --git a/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h b/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h index 22647f1..d6911cc 100644 --- a/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h +++ b/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h @@ -2,12 +2,15 @@ #define _IMSL_VAD_DLL #include +#ifndef _IMSL_NN_COMMON +#define _IMSL_NN_COMMON typedef int (*imsl_nn_printf_func)(const char *format, ...); struct AuthInfo { char dmp_token[64]; }; +#endif // 注意这个必须要与imsl_vad.h中的定义一致 struct VadConfig diff --git a/2.code/aicos/app/AI_AMP_2_5/libimslkws.a b/2.code/aicos/app/AI_AMP_2_5/libimslkws.a index e5f8d9c..e4210fa 100644 Binary files a/2.code/aicos/app/AI_AMP_2_5/libimslkws.a and b/2.code/aicos/app/AI_AMP_2_5/libimslkws.a differ diff --git a/2.code/aicos/app/AI_AMP_2_5/libimslnn.a b/2.code/aicos/app/AI_AMP_2_5/libimslnn.a index ae4ac3e..9cd5608 100644 Binary files a/2.code/aicos/app/AI_AMP_2_5/libimslnn.a and b/2.code/aicos/app/AI_AMP_2_5/libimslnn.a differ diff --git a/2.code/aicos/app/AI_AMP_2_5/libimslvad.a b/2.code/aicos/app/AI_AMP_2_5/libimslvad.a index 1a82937..1541997 100644 Binary files a/2.code/aicos/app/AI_AMP_2_5/libimslvad.a and b/2.code/aicos/app/AI_AMP_2_5/libimslvad.a differ