From: p15692025051 <846603105@qq.com> Date: Tue, 9 Sep 2025 07:09:54 +0000 (+0800) Subject: kws提交,更新了sdk,用杰理原始sdk X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=659d6b767bfd28064f46478324e84f55b7cb3d6c;p=mirrors%2F7PIN_V1_5_Jl_SDK.git kws提交,更新了sdk,用杰理原始sdk --- diff --git a/2.code/1.sdk/Makefile b/2.code/1.sdk/Makefile index bb68dac..90a856a 100644 --- a/2.code/1.sdk/Makefile +++ b/2.code/1.sdk/Makefile @@ -323,6 +323,7 @@ INCLUDES := \ -Iapps/BK_app \ -Iapps/BK_app/BK_drive \ -Iapps/BK_app/lib/vad \ + -Iapps/BK_app/lib/HZ_kws \ -I$(SYS_INC_DIR) \ @@ -1008,9 +1009,11 @@ c_SRC_FILES := \ apps/watch/user_api/vm_api.c \ apps/watch/version.c \ apps/BK_app/bk_app.c\ + apps/BK_app/bk_alg.c\ apps/BK_app/BK_drive/bk_audio.c\ apps/BK_app/BK_drive/mic2dac.c\ apps/BK_app/BK_drive/bk_uart.c \ + apps/BK_app/lib/HZ_kws/voice_app.c \ cpu/br28/adc_api.c \ cpu/br28/audio_codec_clock.c \ cpu/br28/audio_common/app_audio.c \ @@ -1304,6 +1307,8 @@ LFLAGS := \ apps/BK_app/lib/vad/libimslvad.a \ apps/BK_app/lib/vad/libimslnn.a \ apps/BK_app/lib/vad/libimslkws.a \ + apps/BK_app/lib/HZ_kws/libmodel.a \ + apps/BK_app/lib/HZ_kws/libasrengine.a \ --end-group \ -Tcpu/br28/sdk.ld \ -M=cpu/br28/tools/sdk.map \ diff --git a/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c b/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c index bc9ea99..92880f9 100644 --- a/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c +++ b/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.c @@ -322,7 +322,27 @@ void bk_uart_send_smg(bk_uart_msg_event event,char *data,int data_len) } } - os_taskq_post_msg("bk_uart_task", 3, event,(int)data_tmp, data_len); + int ret = os_taskq_post_msg("bk_uart_task", 3, event,(int)data_tmp, data_len); + printf("bk_uart_send_smg event:%d ret:%d--------------------1",event,ret); + if(ret) + { + u8 count=20; + while (count--) + { + ret = os_taskq_post_msg("bk_uart_task", 3, event,(int)data_tmp, data_len); + if(!ret){ + printf("bk_uart_send_smg event:%d ret:%d--------------------2",event,ret); + break; + } + printf("bk_uart_send_smg event:%d ret:%d--------------------3",event,ret); + os_time_dly(1); + } + } + if(ret != 0 && data_tmp) + { + free(data_tmp); + } + } void bk_uart_init() { diff --git a/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.h b/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.h index 924f418..10a7c4d 100644 --- a/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.h +++ b/2.code/1.sdk/apps/BK_app/BK_drive/bk_uart.h @@ -25,5 +25,5 @@ int uart_send_kws(void); void auto_switch_local_mic(void); void clear_earphone_record(void); int uart_send_clear_earphoneok(void); - +void print_hex(char *data ,int len); #endif diff --git a/2.code/1.sdk/apps/BK_app/bk_alg.c b/2.code/1.sdk/apps/BK_app/bk_alg.c new file mode 100644 index 0000000..48f75aa --- /dev/null +++ b/2.code/1.sdk/apps/BK_app/bk_alg.c @@ -0,0 +1,273 @@ +#include "bk_drive/bk_uart.h" +#include "system/includes.h" +#include "bk_app.h" +#define LOG_TAG_CONST APP +#define LOG_TAG "[BK_alg]" +#define LOG_ERROR_ENABLE +#define LOG_DEBUG_ENABLE +#define LOG_INFO_ENABLE +/* #define LOG_DUMP_ENABLE */ +#define LOG_CLI_ENABLE +#include "debug.h" +#include "key_event_deal.h" +static char AI_start_flag = 0; + +#if(USR_KWS_ALG == KWS_BK) +#include "imsl_vad.h" +#include "imsl_kws.h" +#endif +#if(USR_KWS_ALG == KWS_HZ) +#include "voice_config.h" +#include "asr_score.h" +#include "voice_app.h" +#endif +#include "bk_app.h" +#include "BK_versions.h" +#include "aec_user.h" +#include "bk_alg.h" +#define KWS_CBUFF_MAX_LEN (1 * 1024) +cbuffer_t *ALG_MIC_cbuffer = NULL; // adc解码数据的发送和解码buf +static void *ALG_MIC_buf = NULL; +volatile unsigned int alg_count = 0; +volatile unsigned int ALG_KWS_EVENT_count = 0; +int ALG_input_mic_data(char *data, int len) +{ + //printf("ALG_input_mic_data len:%d",len); + volatile u32 wlen; + if(!ALG_MIC_cbuffer) + { + printf("ALG_input_mic_data ALG_MIC_cbuffer 未初始化"); + return 0; + } + + if(ALG_MIC_cbuffer) + { + int rlen = cbuf_is_write_able(ALG_MIC_cbuffer,len); + + if(rlen< len)//出掉多余数据 + { + + //log_info("%s:cbuf_write fill rlen:%d!!!!!!",__FUNCTION__,rlen); + + char *tmp_buf = malloc(len); + if(tmp_buf) + { + cbuf_read(ALG_MIC_cbuffer, tmp_buf, len); + free(tmp_buf); + } + + } + + wlen = cbuf_write(ALG_MIC_cbuffer, data, len); + + bk_ALG_send_smg(ALG_KWS_EVENT,NULL,0); + } + // if(ALG_KWS_EVENT_count <8)//防止滞后,内存撑爆,最多也只保留2k数据,所以再多的解码事件也没用 + // { + // bk_ALG_send_smg(ALG_KWS_EVENT,NULL,0); + // ALG_KWS_EVENT_count++; + // } + return wlen; +} +void alg_kws_event(void) +{ + int len = 512; + int ret = 0; + //ALG_KWS_EVENT_count--; + int rlen = KWS_CBUFF_MAX_LEN - cbuf_is_write_able(ALG_MIC_cbuffer,len); + //printf("alg_kws_event rlen:%d,len:%d,ALG_KWS_EVENT_count:%d",rlen,len,ALG_KWS_EVENT_count); + if(rlen30) + { + printf("bk_ALG_send_smg:alg_count:%d算法阻塞预警!!!!!!!!!!!",alg_count); + } + if(alg_count >200) + { + printf("bk_ALG_send_smg:算法处理时间太久,请关注算法效率!!!!!!!!!!!"); + return; + } + if(data !=NULL && data_len>0) + { + data_tmp= zalloc(data_len); + if(data_tmp) + { + memcpy(data_tmp,data ,data_len); + + }else + { + + log_info("%s:zalloc error",__FUNCTION__); + return; + } + } + + + + int ret = os_taskq_post_msg("ALG_task", 3, event,(int)data_tmp, data_len); + if(ret == 0) + alg_count++; + else + { + if(data_tmp) + free(data_tmp); + } + //printf("bk_ALG_send_smg:alg_count:%d,ret:%d ++++++++",alg_count,ret); +} + +void ALG_task(void *p) +{ + int res,err; + int msg[16]; + log_info("%s:RUN !!!!!!\n",__FUNCTION__); + log_info("%s:RUN !!!!!!\n",__FUNCTION__); + while (1) { + res = os_taskq_pend(NULL, msg, ARRAY_SIZE(msg)); + alg_count--; + //printf("ALG_task:alg_count:%d--------",alg_count); + char *data = (int)msg[2]; + int len = msg[3]; + switch (msg[1]) { + // case ALG_INPUT_MIC_DATA_EVENT: + // ALG_input_mic_data(data,len); + + + // break; + case ALG_KWS_EVENT: + alg_kws_event(); + + break; + case ALG_VAD_EVENT://vad算法执行 + + //printf("VAD_RUN1111\n"); + //vad + // 每次获得语音后调用, 语音长度最好小于100ms + + break; + + default: + break; + } + if(data) + { + free(data); + } + } +} +void alg_clean(void) +{ + #if(USR_KWS_ALG != 0) + cbuf_clear(ALG_MIC_cbuffer); + #endif +} +void alg_init(void) +{ + #if(USR_KWS_ALG != 0) + #if(USR_KWS_ALG == KWS_HZ) + wanson_kws_algorithm_init(); + + #endif + //启用VAD时初始化 + #if(USR_KWS_ALG == KWS_BK) + struct VadConfig conf; + conf.sil_threshold = 63; + conf.energy_threshold = 10000; + conf.min_speech_length = 240; + conf.silence_detect_length = 300; + conf.rule1_min_tailing_silence = 480; + conf.rule2_min_tailing_silence = 960; + conf.rule3_min_tailing_silence = 960; + conf.vad_log_level = 0; + init_vad(&conf); + + struct KwsConfig kws_conf; + kws_conf.min_activate_len = 10; + kws_conf.active_threshold = 32; + kws_conf.max_activate_gap = 160; + kws_conf.kws_log_level = 0; + + int kws_status = init_kws(&kws_conf); + + #endif + if(ALG_MIC_cbuffer ==NULL) + ALG_MIC_cbuffer = zalloc(sizeof(cbuffer_t)); + if(ALG_MIC_buf == NULL) + ALG_MIC_buf = malloc(KWS_CBUFF_MAX_LEN); + if (ALG_MIC_buf != NULL) { + cbuf_init(ALG_MIC_cbuffer, ALG_MIC_buf, KWS_CBUFF_MAX_LEN); + } else { + printf("ALG_MIC_cbuffer err!@!!!"); + } + int err = task_create(ALG_task, NULL, "ALG_task"); + + #endif +} \ No newline at end of file diff --git a/2.code/1.sdk/apps/BK_app/bk_alg.h b/2.code/1.sdk/apps/BK_app/bk_alg.h new file mode 100644 index 0000000..81907ed --- /dev/null +++ b/2.code/1.sdk/apps/BK_app/bk_alg.h @@ -0,0 +1,14 @@ +#ifndef __BK_ALG_H__ +#define __BK_ALG_H__ +#include "bk_alg.h" +typedef enum +{ + ALG_INPUT_MIC_DATA_EVENT = 0, + ALG_VAD_EVENT , + ALG_KWS_EVENT , + +}bk_ALG_msg_event; +void bk_ALG_send_smg(bk_ALG_msg_event event,char *data,int data_len); +void alg_clean(void); +void alg_init(void); +#endif \ No newline at end of file diff --git a/2.code/1.sdk/apps/BK_app/bk_app.c b/2.code/1.sdk/apps/BK_app/bk_app.c index 238563a..7dfd438 100644 --- a/2.code/1.sdk/apps/BK_app/bk_app.c +++ b/2.code/1.sdk/apps/BK_app/bk_app.c @@ -23,6 +23,8 @@ static char AI_start_flag = 0; #endif #include "bk_app.h" #include "BK_versions.h" +#include "aec_user.h" +#include "bk_alg.h" //获取运行状态,返回0代表在休眠,返回1代表在运行 char get_ai_state(void) { @@ -69,6 +71,7 @@ int bk_key_switch(int key_event,int key_value) } return ret; } +#define KWS_TIMER_OUT 5//60*20 //kws多久超时进入休眠 extern u8 esco_flag; extern u8 BT_state; u16 AI_VC_1S_id = 0; @@ -100,7 +103,7 @@ void AI_VC_1S_event(void) if(cat1_io == 0 && AI_start_flag == 1)//cat1退出唤醒,进入休眠 { if(AI_VC_sleep_count<=0) - AI_VC_sleep_count = 80;//60秒后休眠 + AI_VC_sleep_count = KWS_TIMER_OUT;//60秒后休眠 //AI_start_flag = 0; } @@ -146,9 +149,8 @@ void AI_VC_start(void) printf("AI_VC_start:AI_start_flag:%d",AI_start_flag); if(AI_start_flag == 0) { - if(AI_VC_1S_id == 0){ + if(AI_VC_1S_id == 0) AI_VC_1S_id = sys_timer_add(NULL, AI_VC_1S_cb, 1000); - } bk_audio_open(); AI_start_flag = 1; } @@ -167,6 +169,8 @@ void AI_VC_close(void) AI_VC_1S_id = 0; } bk_audio_close(); + printf("AI_VC_close3:AI_start_flag:%d",AI_start_flag); + alg_clean(); AI_start_flag = 0; } } @@ -203,7 +207,7 @@ void bk_app_send_smg(bk_app_msg_event event,char *data,int data_len) u8 count=20; while (count--) { - int ret = os_taskq_post_msg("bk_app_task", 3, event,(int)data_tmp, data_len); + ret = os_taskq_post_msg("bk_app_task", 3, event,(int)data_tmp, data_len); if(!ret){ printf("event:%d ret:%d--------------------2",event,ret); break; @@ -212,6 +216,11 @@ void bk_app_send_smg(bk_app_msg_event event,char *data,int data_len) os_time_dly(1); } } + if(ret != 0 && data_tmp) + { + free(data_tmp); + } + } void bk_app_task(void *p) { @@ -296,26 +305,7 @@ void bk_app_task(void *p) } } } -void bk_ALG_send_smg(bk_ALG_msg_event event,char *data,int data_len) -{ - char *data_tmp =NULL; - if(data !=NULL && data_len>0) - { - data_tmp= zalloc(data_len); - if(data_tmp) - { - memcpy(data_tmp,data ,data_len); - - }else - { - - log_info("%s:zalloc error",__FUNCTION__); - return; - } - } - - os_taskq_post_msg("bk_ALG_task", 3, event,(int)data_tmp, data_len); -} + //蓝牙耳机切换事件回调 void BT_State_Change_cb(void) @@ -360,73 +350,6 @@ void all_key_bt_ai(void) //蓝牙耳机已连接不在通话中 bk_app_send_smg(AI_OPEN,NULL,0); bk_app_send_smg(AI_KEY_PRESS,NULL,0); } -//#include "rtc.h" -//void read_sys_time(struct sys_time *curr_time); -//char vad_data_t[320]; -void bk_ALG_task(void *p) -{ - int res,err; - int msg[16]; - log_info("%s:RUN !!!!!!\n",__FUNCTION__); - log_info("%s:RUN !!!!!!\n",__FUNCTION__); - while (1) { - res = os_taskq_pend(NULL, msg, ARRAY_SIZE(msg)); - char *data = (int)msg[2]; - int len = msg[3]; - switch (msg[1]) { - case ALG_VAD_EVENT://vad算法执行 - - //printf("VAD_RUN1111\n"); - //vad - // 每次获得语音后调用, 语音长度最好小于100ms - #if BK_VAD_KWS - // run_vad(data, len / 2); - // int status = vad_detect(); - // if (status == 1) - // { - // printf("开始说话!!!!!!!!\n"); - // } - // else if(status == 2) { - // vad_clear(); - // printf("说话结束!!!!!!!!\n"); - // } - // #endif - // //printf("VAD_RUN2222\n"); - // //os_time_dly(1); - //printf("run_kws1 len :%d",len); - run_kws(data, len / 2); - int kws_status = kws_detect(); - //printf("run_kws2"); - if (kws_status == 1) { - kws_clear(); - printf("kws 你好小瑞 触发了!!!!!!!!!!!!!!!!!!!!!!"); - printf("kws 你好小瑞 触发了!!!!!!!!!!!!!!!!!!!!!!"); - printf("kws 你好小瑞 触发了!!!!!!!!!!!!!!!!!!!!!!"); - printf("kws 你好小瑞 触发了!!!!!!!!!!!!!!!!!!!!!!"); - printf("kws 你好小瑞 触发了!!!!!!!!!!!!!!!!!!!!!!"); - uart_send_kws(); - } - #endif - #if(USR_KWS_ALG == KWS_HZ) - //printf("wanson_algorithm_recog:len :%d",len); - // if(wanson_algorithm_recog(data,len)==1) - // { - // printf("华镇唤醒了!!!!!!!!!!!!!!"); - // printf("华镇唤醒了!!!!!!!!!!!!!!"); - // printf("华镇唤醒了!!!!!!!!!!!!!!"); - // } - #endif - break; - - default: - break; - } - if(data) - { - free(data); - } - } -} void bk_app_init(void) { //bk_ALG_task(NULL); @@ -478,47 +401,15 @@ void bk_app_init(void) gpio_write(IO_PORTA_06,1); // while(1) // ; - //启用VAD时初始化 - #if(USR_KWS_ALG == KWS_BK) - struct VadConfig conf; - conf.sil_threshold = 63; - conf.energy_threshold = 10000; - conf.min_speech_length = 240; - conf.silence_detect_length = 300; - conf.rule1_min_tailing_silence = 480; - conf.rule2_min_tailing_silence = 960; - conf.rule3_min_tailing_silence = 960; - conf.vad_log_level = 0; - init_vad(&conf); - - struct KwsConfig kws_conf; - kws_conf.min_activate_len = 10; - kws_conf.active_threshold = 32; - kws_conf.max_activate_gap = 160; - kws_conf.kws_log_level = 0; - - int kws_status = init_kws(&kws_conf); - - // struct AuthInfo auth_info; - // strcpy(auth_info.dmp_token, ""); - // auth_kws(&auth_info); - //err = os_task_create(bk_ALG_task, NULL, 31, 1024*8, 255, "bk_ALG_task"); - - #endif - #if(USR_KWS_ALG == KWS_HZ) - wanson_kws_algorithm_init(); - #endif - #if(USR_KWS_ALG != 0) - err = task_create(bk_ALG_task, NULL, "bk_ALG_task"); - #endif + err = os_task_create(bk_app_task, NULL, 3, 512, 512, "bk_app_task"); //int err = task_create(bk_app_task, NULL, "bk_app_task"); if (err != OS_ERR_NONE) { r_printf("creat fail %x\n", err); } //AI_VC_1S_id = sys_timer_add(NULL, AI_VC_1S_cb, 1000); + alg_init();//算法初始化 - } static u8 BK_AI_APP_idle_query() diff --git a/2.code/1.sdk/apps/BK_app/bk_app.h b/2.code/1.sdk/apps/BK_app/bk_app.h index d3ecaed..20ad82d 100644 --- a/2.code/1.sdk/apps/BK_app/bk_app.h +++ b/2.code/1.sdk/apps/BK_app/bk_app.h @@ -3,7 +3,9 @@ #define KWS_NO 0 #define KWS_HZ 1 //华镇算法 #define KWS_BK 2 //北科算法 -#define USR_KWS_ALG KWS_NO +#define USR_KWS_ALG KWS_BK + + typedef enum { AI_KEY_PRESS = 0, @@ -21,13 +23,9 @@ typedef enum BT_DISCONNEECT_EVENT, }bk_app_msg_event; -typedef enum -{ - ALG_VAD_EVENT = 0, -}bk_ALG_msg_event; void bk_app_send_smg(bk_app_msg_event event,char *data,int data_len); -void bk_ALG_send_smg(bk_ALG_msg_event event,char *data,int data_len); + void bk_app_init(void); int bk_key_switch(int key_event,int key_value); char get_ai_state(void); diff --git a/2.code/1.sdk/apps/BK_app/lib/HZ_kws/voice_app.c b/2.code/1.sdk/apps/BK_app/lib/HZ_kws/voice_app.c index 6063724..f6835f9 100644 --- a/2.code/1.sdk/apps/BK_app/lib/HZ_kws/voice_app.c +++ b/2.code/1.sdk/apps/BK_app/lib/HZ_kws/voice_app.c @@ -35,78 +35,78 @@ const asr_score_t cmd_score[] = { {-2400, "小艾退下"}, {-2400, "小艾再见"}, {-2400, "小爱同学"}, - {-2400, "打开助手"}, - {-2400, "你好助手"}, - {-2400, "增大音量"}, - {-2400, "减小音量"}, - {-2400, "上一首"}, - {-2400, "下一首"}, - {-2400, "播放音乐"}, - {-2400, "继续播放"}, - {-2400, "暂停播放"}, - {-2400, "停止播放"}, - {-2400, "切换到英文"}, - {-2400, "升级模式"}, - {-2400, "再见"}, - {-2400, "不聊了"}, - {-2400, "站起来"}, - {-2400, "站立"}, - {-2400, "坐下"}, - {-2400, "趴下"}, - {-2400, "转个圈"}, - {-2400, "打个滚"}, - {-2400, "去尿尿"}, - {-2400, "尿尿去"}, - {-2400, "去睡觉"}, - {-2400, "睡觉去"}, - {-2400, "装死"}, - {-2400, "秀一个"}, - {-2400, "跳个舞"}, - {-2400, "跳舞"}, - {-2400, "来个绝活"}, - {-2400, "倒立旋转"}, - {-2400, "前进"}, - {-2400, "后退"}, - {-2400, "左转"}, - {-2400, "向左转"}, - {-2400, "右转"}, - {-2400, "向右转"}, - {-2400, "过来"}, - {-2400, "走开"}, - {-2400, "滚开"}, - {-2400, "滚蛋"}, - {-2400, "匍匐前进"}, - {-2400, "滑步"}, - {-2400, "我讨厌你"}, - {-2400, "打开灯光"}, - {-2400, "关闭灯光"}, - {-2400, "调亮灯光"}, - {-2400, "调暗灯光"}, - {-2400, "七彩模式"}, - {-2400, "音乐模式"}, - {-2400, "白色灯光"}, - {-2400, "黄色灯光"}, - {-2400, "自然灯光"}, - {-2400, "红色灯光"}, - {-2400, "绿色灯光"}, - {-2400, "蓝色灯光"}, - {-2400, "橙色灯光"}, - {-2400, "青色灯光"}, - {-2400, "紫色灯光"}, - {-2400, "开始配网"}, - {-2400, "停止配网"}, - {-2400, "开开"}, - {-2400, "关关"}, - {-2400, "定时"}, - {-2400, "取消"}, - {-2400, "打开关闭"}, - {-2400, "关闭打开"}, - {-2400, "打开火焰"}, - {-2400, "关闭火焰"}, - {-2400, "打开电视"}, - {-2400, "关闭电视"}, - {-2400, "打开空调"}, - {-2400, "关闭空调"}, + {-20000, "打开助手"}, + // {-2400, "你好助手"}, + // {-2400, "增大音量"}, + // {-2400, "减小音量"}, + // {-2400, "上一首"}, + // {-2400, "下一首"}, + // {-2400, "播放音乐"}, + // {-2400, "继续播放"}, + // {-2400, "暂停播放"}, + // {-2400, "停止播放"}, + // {-2400, "切换到英文"}, + // {-2400, "升级模式"}, + // {-2400, "再见"}, + // {-2400, "不聊了"}, + // {-2400, "站起来"}, + // {-2400, "站立"}, + // {-2400, "坐下"}, + // {-2400, "趴下"}, + // {-2400, "转个圈"}, + // {-2400, "打个滚"}, + // {-2400, "去尿尿"}, + // {-2400, "尿尿去"}, + // {-2400, "去睡觉"}, + // {-2400, "睡觉去"}, + // {-2400, "装死"}, + // {-2400, "秀一个"}, + // {-2400, "跳个舞"}, + // {-2400, "跳舞"}, + // {-2400, "来个绝活"}, + // {-2400, "倒立旋转"}, + // {-2400, "前进"}, + // {-2400, "后退"}, + // {-2400, "左转"}, + // {-2400, "向左转"}, + // {-2400, "右转"}, + // {-2400, "向右转"}, + // {-2400, "过来"}, + // {-2400, "走开"}, + // {-2400, "滚开"}, + // {-2400, "滚蛋"}, + // {-2400, "匍匐前进"}, + // {-2400, "滑步"}, + // {-2400, "我讨厌你"}, + // {-2400, "打开灯光"}, + // {-2400, "关闭灯光"}, + // {-2400, "调亮灯光"}, + // {-2400, "调暗灯光"}, + // {-2400, "七彩模式"}, + // {-2400, "音乐模式"}, + // {-2400, "白色灯光"}, + // {-2400, "黄色灯光"}, + // {-2400, "自然灯光"}, + // {-2400, "红色灯光"}, + // {-2400, "绿色灯光"}, + // {-2400, "蓝色灯光"}, + // {-2400, "橙色灯光"}, + // {-2400, "青色灯光"}, + // {-2400, "紫色灯光"}, + // {-2400, "开始配网"}, + // {-2400, "停止配网"}, + // {-2400, "开开"}, + // {-2400, "关关"}, + // {-2400, "定时"}, + // {-2400, "取消"}, + // {-2400, "打开关闭"}, + // {-2400, "关闭打开"}, + // {-2400, "打开火焰"}, + // {-2400, "关闭火焰"}, + // {-2400, "打开电视"}, + // {-2400, "关闭电视"}, + // {-2400, "打开空调"}, + // {-2400, "关闭空调"}, }; @@ -211,6 +211,7 @@ int wanson_kws_algorithm_init() } wanson_score_display_set(1); + //wanson_audio_buf_init(4*1024); return 0; } @@ -229,15 +230,15 @@ int wanson_app_proc() int wanson_algorithm_recog(void* data, int len) { - const char* text; + char* text; float score; int rs = 0; - if (tone_get_status()) { // 正在播放提示音 - if (get_call_status() != BT_CALL_INCOMING) { - return -1; - } - } + // if (tone_get_status()) { // 正在播放提示音 + // if (get_call_status() != BT_CALL_INCOMING) { + // return -1; + // } + // } rs = Wanson_ASR_Recog(data, len, &text, &score); //识别计算函数,有识别结果rs返回1 if (rs == 1) { printf("ASR Result: %s\n", text); diff --git a/2.code/1.sdk/apps/BK_app/lib/vad/imsl_kws.h b/2.code/1.sdk/apps/BK_app/lib/vad/imsl_kws.h index 8228b93..334c94e 100644 --- a/2.code/1.sdk/apps/BK_app/lib/vad/imsl_kws.h +++ b/2.code/1.sdk/apps/BK_app/lib/vad/imsl_kws.h @@ -1,8 +1,8 @@ /* * Build Information - * Git Commit: 219b944f738c298dc3de319a1750ee3ba39f90c3 + * Git Commit: efc478e25cfbe524a8f65773b143ada42c67ec8a * Branch: master - * Build Date: 2025-08-07 16:18:55 + * Build Date: 2025-09-05 14:58:39 */ #ifndef _IMSL_KWS_DLL diff --git a/2.code/1.sdk/apps/BK_app/lib/vad/imsl_vad.h b/2.code/1.sdk/apps/BK_app/lib/vad/imsl_vad.h index a8c5b68..4ce3c54 100644 --- a/2.code/1.sdk/apps/BK_app/lib/vad/imsl_vad.h +++ b/2.code/1.sdk/apps/BK_app/lib/vad/imsl_vad.h @@ -1,8 +1,8 @@ /* * Build Information - * Git Commit: 219b944f738c298dc3de319a1750ee3ba39f90c3 + * Git Commit: efc478e25cfbe524a8f65773b143ada42c67ec8a * Branch: master - * Build Date: 2025-08-07 16:18:56 + * Build Date: 2025-09-05 14:58:40 */ #ifndef _IMSL_VAD_DLL diff --git a/2.code/1.sdk/apps/BK_app/lib/vad/libimslkws.a b/2.code/1.sdk/apps/BK_app/lib/vad/libimslkws.a index 3cc0faf..ed3b328 100644 Binary files a/2.code/1.sdk/apps/BK_app/lib/vad/libimslkws.a and b/2.code/1.sdk/apps/BK_app/lib/vad/libimslkws.a differ diff --git a/2.code/1.sdk/apps/BK_app/lib/vad/libimslnn.a b/2.code/1.sdk/apps/BK_app/lib/vad/libimslnn.a index c866f7e..bddfdc7 100644 Binary files a/2.code/1.sdk/apps/BK_app/lib/vad/libimslnn.a and b/2.code/1.sdk/apps/BK_app/lib/vad/libimslnn.a differ diff --git a/2.code/1.sdk/apps/BK_app/lib/vad/libimslvad.a b/2.code/1.sdk/apps/BK_app/lib/vad/libimslvad.a index 951369a..c6ebec2 100644 Binary files a/2.code/1.sdk/apps/BK_app/lib/vad/libimslvad.a and b/2.code/1.sdk/apps/BK_app/lib/vad/libimslvad.a differ diff --git a/2.code/1.sdk/apps/watch/app_main.c b/2.code/1.sdk/apps/watch/app_main.c index 68ca4b4..bf27ff3 100644 --- a/2.code/1.sdk/apps/watch/app_main.c +++ b/2.code/1.sdk/apps/watch/app_main.c @@ -124,11 +124,6 @@ extern void user_file_flash_file_download_init(void); void app_main() { - gpio_set_pull_up(IO_PORTG_07, 0); - gpio_set_pull_down(IO_PORTG_07, 0); - gpio_set_direction(IO_PORTG_07, 0); - gpio_set_die(IO_PORTG_07, 1); - gpio_write(IO_PORTG_07,1); #if TCFG_PSRAM_UI_EFFECT static struct effect_sca_alpha sal = {0}; #endif diff --git a/2.code/1.sdk/apps/watch/board/br28/board_701n_demo/board_701n_demo.c b/2.code/1.sdk/apps/watch/board/br28/board_701n_demo/board_701n_demo.c index dba575f..a89b12d 100644 --- a/2.code/1.sdk/apps/watch/board/br28/board_701n_demo/board_701n_demo.c +++ b/2.code/1.sdk/apps/watch/board/br28/board_701n_demo/board_701n_demo.c @@ -1372,12 +1372,6 @@ void board_init() } #endif -#if TCFG_SMART_VOICE_ENABLE - int audio_smart_voice_detect_init(struct vad_mic_platform_data *mic_data); - audio_smart_voice_detect_init((struct vad_mic_platform_data *)&vad_mic_data); -#endif /* #if TCFG_SMART_VOICE_ENABLE */ - - #ifdef AUDIO_PCM_DEBUG extern void uartSendInit(); uartSendInit(); @@ -1434,7 +1428,13 @@ void board_init() gpio_set_pull_up(IO_PORTB_01, 0); //展锐样机开机PB1上拉,影响功耗,此处修改为不上拉 #endif } - +void usr_smart_voice_init() +{ +#if TCFG_SMART_VOICE_ENABLE + int audio_smart_voice_detect_init(struct vad_mic_platform_data *mic_data); + audio_smart_voice_detect_init((struct vad_mic_platform_data *)&vad_mic_data); +#endif /* #if TCFG_SMART_VOICE_ENABLE */ +} /*进软关机之前默认将IO口都设置成高阻状态,需要保留原来状态的请修改该函数*/ extern void dac_power_off(void); void board_set_soft_poweroff(void) diff --git a/2.code/1.sdk/apps/watch/common/init.c b/2.code/1.sdk/apps/watch/common/init.c index 8ceed79..38f8f33 100644 --- a/2.code/1.sdk/apps/watch/common/init.c +++ b/2.code/1.sdk/apps/watch/common/init.c @@ -155,13 +155,9 @@ static void app_init() cur_por_flag = 0xA5; } #else /* #if defined(CONFIG_CPU_BR23) */ - // u32 reset_src = get_reset_source_value(); - // if (update || (reset_src & BIT(MSYS_POWER_RETURN)) || (reset_src & BIT(P33_PPINR_RST))) { - // //log_info("reset_flag:0x%x",reset_src); - // cur_por_flag = 0xA5; - // } - u32 reset_src = is_reset_source(BIT(MSYS_POWER_RETURN) | BIT(P33_PPINR_RST)); - if (update || reset_src) { + u32 reset_src = get_reset_source_value(); + if (update || (reset_src & BIT(MSYS_POWER_RETURN)) || (reset_src & BIT(P33_PPINR_RST))) { + //log_info("reset_flag:0x%x",reset_src); cur_por_flag = 0xA5; } #endif /* #if defined(CONFIG_CPU_BR23) */ diff --git a/2.code/1.sdk/apps/watch/common/smart_voice_user.c b/2.code/1.sdk/apps/watch/common/smart_voice_user.c index 1883409..d41b5b2 100644 --- a/2.code/1.sdk/apps/watch/common/smart_voice_user.c +++ b/2.code/1.sdk/apps/watch/common/smart_voice_user.c @@ -66,7 +66,7 @@ static u8 extern_kws_handler(u32 timeout) if (!status) { return 0; } -#endif +#endif msg[0] = (int)kws_poweroff; msg[1] = 1; msg[2] = (int)NULL; diff --git a/2.code/1.sdk/apps/watch/common/task_table.c b/2.code/1.sdk/apps/watch/common/task_table.c index 476b9d5..857ad6e 100644 --- a/2.code/1.sdk/apps/watch/common/task_table.c +++ b/2.code/1.sdk/apps/watch/common/task_table.c @@ -101,7 +101,7 @@ const struct task_info task_info_table[] = { #if TCFG_AUDIO_ASR_DEVELOP == ASR_CFG_IFLYTEK {"audio_vad", 3, 0, 768, 128 }, #else - {"audio_vad", 3, 0, 512, 128 }, + {"audio_vad", 3, 0, 1024, 512 }, #endif #endif #if PRODUCT_TEST_ENABLE @@ -119,14 +119,13 @@ const struct task_info task_info_table[] = { #else {"cat1_update", 1, 0, 256, 128 }, #endif - #endif // {"user_mic_record", 3, 0, 256 ,128 }, // {"user_mic_record_play", 2, 0, 512,256 }, // {"user_ble_protocol", 3, 0, 1024, 256 }, //{"bk_app_task", 3, 0, 1024*2, 256 }, - {"bk_ALG_task", 3, 1, 1024, 256 }, - {"bk_uart_task", 3, 0, 2*1024, 256 }, + {"ALG_task", 3, 0, 1*1024, 512 }, + {"bk_uart_task", 3, 0, 1*1024, 256 }, {0, 0}, }; diff --git a/2.code/1.sdk/apps/watch/log_config/lib_system_config.c b/2.code/1.sdk/apps/watch/log_config/lib_system_config.c index 9faf311..f4b35b7 100644 --- a/2.code/1.sdk/apps/watch/log_config/lib_system_config.c +++ b/2.code/1.sdk/apps/watch/log_config/lib_system_config.c @@ -21,7 +21,7 @@ const int config_printf_time = 1; ///异常中断,asser打印开启 #ifdef CONFIG_RELEASE_ENABLE -const int config_asser = 0; +const int config_asser = 1; #else const int config_asser = 1; #endif diff --git a/2.code/1.sdk/apps/watch/task_manager/power_on/power_on.c b/2.code/1.sdk/apps/watch/task_manager/power_on/power_on.c index ea63171..fe99ed1 100644 --- a/2.code/1.sdk/apps/watch/task_manager/power_on/power_on.c +++ b/2.code/1.sdk/apps/watch/task_manager/power_on/power_on.c @@ -211,6 +211,10 @@ void app_poweron_task() } +#if TCFG_SMART_VOICE_ENABLE + extern void usr_smart_voice_init(); + usr_smart_voice_init(); +#endif /* #if TCFG_SMART_VOICE_ENABLE */ while (1) { app_task_get_msg(msg, ARRAY_SIZE(msg), 1); switch (msg[0]) { diff --git a/2.code/1.sdk/cpu/br28/audio_dec/audio_dec_bt.c b/2.code/1.sdk/cpu/br28/audio_dec/audio_dec_bt.c index d9b09c6..15b129e 100644 --- a/2.code/1.sdk/cpu/br28/audio_dec/audio_dec_bt.c +++ b/2.code/1.sdk/cpu/br28/audio_dec/audio_dec_bt.c @@ -1629,7 +1629,7 @@ extern int audio_link_demo_post_mic(char *data, int len); */ /*----------------------------------------------------------------------------*/ -extern int write_iis_mic_data(char *data, int len); + extern int read_iis_play_data(char *data, int len); static int esco_dec_data_handler(struct audio_stream_entry *entry, struct audio_data_frame *in, @@ -1668,7 +1668,7 @@ static int esco_dec_data_handler(struct audio_stream_entry *entry, - //wlen = write_iis_mic_data((char*)out_frame.data,out_frame.data_len); + //printf("111out_frame:len:%d,wlen:%d,process_len:%d,read_err:%d\n",out_frame.data_len,wlen,decoder->process_len,decoder->read_err); @@ -1690,7 +1690,7 @@ static int esco_dec_data_handler(struct audio_stream_entry *entry, audio_link_demo_post_mic(tmp_buf,out_frame.data_len); //传进来的是单通道数据 else { - printf("没解码完,不入队!!!!!"); + //printf("没解码完,不入队!!!!!"); } free(tmp_buf); diff --git a/2.code/1.sdk/cpu/br28/clock_manager.c b/2.code/1.sdk/cpu/br28/clock_manager.c index cf38e48..3095783 100644 --- a/2.code/1.sdk/cpu/br28/clock_manager.c +++ b/2.code/1.sdk/cpu/br28/clock_manager.c @@ -36,14 +36,14 @@ void clock_remove_set(u32 type) *****/ #ifndef TCFG_UNISOUND_ENABLE -#define TCFG_UNISOUND_ENABLE 0 +#define TCFG_UNISOUND_ENABLE 1 #endif //// 如果clock_fix 为0 就按照配置设置时钟,如果有值就固定频率 #if (TCFG_MIC_EFFECT_ENABLE|| TCFG_UNISOUND_ENABLE) #define CLOCK_FIX (192) #else -#define CLOCK_FIX 0 +#define CLOCK_FIX 192 #endif #if (TCFG_AUDIO_DAC_CONNECT_MODE == DAC_OUTPUT_FRONT_LR_REAR_LR) && TCFG_EQ_DIVIDE_ENABLE diff --git a/2.code/1.sdk/cpu/br28/liba/cpu.a b/2.code/1.sdk/cpu/br28/liba/cpu.a index 791b3cc..307575d 100644 Binary files a/2.code/1.sdk/cpu/br28/liba/cpu.a and b/2.code/1.sdk/cpu/br28/liba/cpu.a differ diff --git a/2.code/1.sdk/cpu/br28/setup.c b/2.code/1.sdk/cpu/br28/setup.c index 806cde5..366816d 100644 --- a/2.code/1.sdk/cpu/br28/setup.c +++ b/2.code/1.sdk/cpu/br28/setup.c @@ -32,7 +32,7 @@ extern void tick_timer_init(void); extern void exception_irq_handler(void); int __crc16_mutex_init(); -extern int crc16_mutex_init(); +extern int __crc16_mutex_init(); extern const int CONFIG_CPU_CORE_NUM; @@ -266,7 +266,7 @@ void setup_arch() /* sys_timer_add(NULL, timer, 3 * 1000); */ /* usr_timer_add(NULL, timer, 5 * 1000, 0); */ - crc16_mutex_init(); + __crc16_mutex_init(); } /*-----------------------------------------------------------*/ diff --git a/2.code/1.sdk/cpu/br28/smart_voice/jl_kws_platform.c b/2.code/1.sdk/cpu/br28/smart_voice/jl_kws_platform.c index ec0c75d..674ef15 100644 --- a/2.code/1.sdk/cpu/br28/smart_voice/jl_kws_platform.c +++ b/2.code/1.sdk/cpu/br28/smart_voice/jl_kws_platform.c @@ -149,6 +149,7 @@ static void smart_voice_kws_open(struct smart_voice_context *sv, u8 model) } sv->kws_model = model; + printf("audio_kws_open:%d",model); sv->kws = audio_kws_open(model, NULL);//kws_model_files[model]); #endif } diff --git a/2.code/1.sdk/cpu/br28/smart_voice/smart_voice.h b/2.code/1.sdk/cpu/br28/smart_voice/smart_voice.h index 54efe4a..4cb66a3 100644 --- a/2.code/1.sdk/cpu/br28/smart_voice/smart_voice.h +++ b/2.code/1.sdk/cpu/br28/smart_voice/smart_voice.h @@ -18,6 +18,8 @@ #define ASR_CORE_WAKEUP 0 #define ASR_CORE_STANDBY 1 +#define WANSON_ASR_ENABLE 0 + /* ********************************************************************* * audio smart voice detect open diff --git a/2.code/1.sdk/cpu/br28/smart_voice/user_asr.c b/2.code/1.sdk/cpu/br28/smart_voice/user_asr.c index 4a7fcf9..740d878 100644 --- a/2.code/1.sdk/cpu/br28/smart_voice/user_asr.c +++ b/2.code/1.sdk/cpu/br28/smart_voice/user_asr.c @@ -10,7 +10,12 @@ #if ((TCFG_SMART_VOICE_ENABLE) && (TCFG_AUDIO_ASR_DEVELOP == ASR_CFG_USER_DEFINED)) -#define ASR_FRAME_SAMPLES 160 /*语音识别帧长(采样点)*/ +#define ASR_FRAME_SAMPLES 256 /*语音识别帧长(采样点)*/ +extern int wanson_algorithm_recog(void* data, int len); +extern int wanson_kws_algorithm_init(); +extern void wanson_kws_algorithm_deinit(); +extern int wanson_app_proc(); +extern void wasnon_app_asr_init(); struct user_platform_asr_context { void *mic; @@ -20,12 +25,20 @@ struct user_platform_asr_context { extern const int config_user_asr_enable; static struct user_platform_asr_context *__this = NULL; +unsigned char kws_result[256] = { 0 }; /* * 算法引擎打开函数 */ static void *user_asr_core_open(int sample_rate) { +#if !WANSON_ASR_ENABLE return NULL; +#endif + if (wanson_kws_algorithm_init() < 0) { + return NULL; + } else { + return (void*)kws_result; + } } /* @@ -33,7 +46,9 @@ static void *user_asr_core_open(int sample_rate) */ static void user_asr_core_close(void *core) { - +#if WANSON_ASR_ENABLE + wanson_kws_algorithm_deinit(); +#endif } /* @@ -41,7 +56,9 @@ static void user_asr_core_close(void *core) */ static int user_asr_core_data_handler(void *core, void *data, int len) { - return 0; +#if WANSON_ASR_ENABLE + wanson_algorithm_recog(data, len); +#endif } /* @@ -53,26 +70,27 @@ static int user_asr_core_data_handler(void *core, void *data, int len) * Note(s) : 该函数通过读取mic数据送入算法引擎完成语音帧. ********************************************************************* */ -static int user_asr_data_handler(struct user_platform_asr_context *asr) +static int user_asr_data_handler(struct user_platform_asr_context* asr) { int result = 0; if (!asr->mic) { return -EINVAL; } - printf("user_asr_data_handler\n"); - s16 data[ASR_FRAME_SAMPLES]; - int len = voice_mic_data_read(asr->mic, data, sizeof(data)); - if (len < sizeof(data)) { - return -EINVAL; - } + s16 data[ASR_FRAME_SAMPLES]; - if (asr->core) { - result = user_asr_core_data_handler(asr->core, data, sizeof(data)); +#if WANSON_ASR_ENABLE + wanson_app_proc(); +#endif + + while (voice_mic_data_read(asr->mic, data, sizeof(data))) { + if (asr->core) { + putchar('A'); + result = user_asr_core_data_handler(asr->core, data, sizeof(data)); + } } - - return 0; + return 0; } /* @@ -114,7 +132,7 @@ int audio_smart_voice_core_handler(void *priv, int taskq_type, int *msg) user_asr_core_close(asr->core); asr->core = NULL; asr->data_enable = 0; - os_sem_post((OS_SEM *)msg[1]); + os_sem_post((OS_SEM *)msg[1]); break; case SMART_VOICE_MSG_DMA: /*MIC通路数据DMA消息*/ err = ASR_CORE_WAKEUP; diff --git a/2.code/1.sdk/cpu/br28/tools/download/watch/download.bat b/2.code/1.sdk/cpu/br28/tools/download/watch/download.bat index 2ea4a8b..3f494cf 100644 --- a/2.code/1.sdk/cpu/br28/tools/download/watch/download.bat +++ b/2.code/1.sdk/cpu/br28/tools/download/watch/download.bat @@ -53,9 +53,10 @@ set /p "themd5=" < "md5.bin" @REM ..\..\packres.exe -keep-suffix-case F_ASCII.PIX F_GB2312.PIX F_GB2312.TAB ascii.res -n res -o font @REM ..\..\packres.exe -keep-suffix-case update_new.ufw -n res -o update_new ::echo %1 - -set CHIPKEY=default.key - +::汇杰芯 +set CHIPKEY=-key default.key +::华镇 +::set CHIPKEY= -key1 503_KEY03_AC69XX_8c59.key1 -mkey KEY03.mkey :: 8MBytes ::..\..\packres.exe -keep-suffix-case F_ASCII.PIX ascii.res -n res -o font ::..\..\fat_comm.exe -pad-backup2 -force-align-fat -out new_res.bin -image-size 8 -filelist JL sidebar watch3 watch4 font -remove-empty -remove-bpb -mark-bad-after 0x7e0000 -key %CHIPKEY% -address 0 @@ -75,7 +76,7 @@ move font res.ori\font ::..\..\packres.exe -n res -o res.bin new_res.bin 0 nor_up.ufw 0xb00000 -normal -..\..\isd_download.exe -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot uboot.boot -app app.bin cfg_tool.bin -res ui_upgrade p11_code.bin config.dat tone.cfg eq_cfg_hw.bin -flash-params flash_params.bin -uboot_compress -key %CHIPKEY% -ex_api_bin user_api.bin +..\..\isd_download.exe -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot uboot.boot -app app.bin cfg_tool.bin -res ui_upgrade p11_code.bin config.dat tone.cfg eq_cfg_hw.bin -flash-params flash_params.bin -uboot_compress %CHIPKEY% -ex_api_bin user_api.bin ::..\..\isd_download.exe -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot uboot.boot -app app.bin cfg_tool.bin -res p11_code.bin config.dat -uboot_compress -key %CHIPKEY% -ex_flash res.bin -ex_api_bin user_api.bin ::-format all ::-ex_flash res.bin