然后其他与LDV7模块相连的MCU只要解析接收到的串口数据即可。 喜欢请扫码关注微信公众号:程序员小哈
/************************************************************************ 功能描述: 向LD模块添加关键词 入口参数: none 返 回 值: flag:1->添加成功 其他说明: 用户修改. 1、根据如下格式添加拼音关键词,同时注意修改sRecog 和pCode 数组的长度 和对应变了k的循环次数设置。拼音串和识别码是一一对应的。 2、开发者可以学习"语音识别芯片LD3320高阶秘籍.pdf"中 关于垃圾词语吸收错误的用法,来提供识别效果。 3、”duo gong neng bao shi“ 为口令,故在每次识别时,必须先发一级口令“多功能报时” **************************************************************************/ uint8 LD_AsrAddFixed() { uint8 k, flag; uint8 nAsrAddLength; #define DATE_A 8 /*数组二维数值*/ #define DATE_B 21 /*数组一维数值*/ uint8 code sRecog[DATE_A][DATE_B] = { "duo gong neng bao shi", "xian zai ji dian le", "dang qian shi jian", "xian zai shi ke", "bao shi", "dang qian wen du", "dang qian shi du", "wen shi du duo shao" }; /*添加关键词,用户修改*/ uint8 code pCode[DATE_A] = { CODE_CMD, CODE_XZJDL, CODE_DQSJ, CODE_XZSK, CODE_BS, CODE_DQWD, CODE_DQSD, CODE_WSDDS }; /*添加识别码,用户修改*/ flag = 1; for (k=0; k<DATE_A; k++) { if(LD_Check_ASRBusyFlag_b2() == 0) { flag = 0; break; } LD_WriteReg(0xc1, pCode[k] ); LD_WriteReg(0xc3, 0 ); LD_WriteReg(0x08, 0x04); delay(1); LD_WriteReg(0x08, 0x00); delay(1); for (nAsrAddLength=0; nAsrAddLength<DATE_B; nAsrAddLength++) { if (sRecog[k][nAsrAddLength] == 0) break; LD_WriteReg(0x5, sRecog[k][nAsrAddLength]); } LD_WriteReg(0xb9, nAsrAddLength); LD_WriteReg(0xb2, 0xff); LD_WriteReg(0x37, 0x04); } return flag; }
void main(void) { uint8 idata nAsrRes; uint8 i=0; Led_test(); MCU_init(); LD_Reset(); UartIni(); /*串口初始化*/ nAsrStatus = LD_ASR_NONE; // 初始状态:没有在作ASR #ifdef TEST PrintCom("一级口令:多功能报时rn"); /*text.....*/ PrintCom("二级口令:1、现在几点了rn"); /*text.....*/ PrintCom(" 2、当前时间rn"); /*text.....*/ PrintCom(" 3、现在时刻rn"); /*text.....*/ PrintCom(" 4、报时rn"); /*text.....*/ PrintCom(" 5、当前温度rn"); /*text.....*/ PrintCom(" 6、当前湿度rn"); /*text.....*/ PrintCom(" 7、温湿度多少rn"); /*text.....*/ #endif while(1) { switch(nAsrStatus) { case LD_ASR_RUNING: case LD_ASR_ERROR: break; case LD_ASR_NONE: { nAsrStatus=LD_ASR_RUNING; if (RunASR()==0) /* 启动一次ASR识别流程:ASR初始化,ASR添加关键词语,启动ASR运算*/ { nAsrStatus = LD_ASR_ERROR; } break; } case LD_ASR_FOUNDOK: /* 一次ASR识别流程结束,去取ASR识别结果*/ { nAsrRes = LD_GetResult(); /*获取结果*/ User_handle(nAsrRes); //用户执行函数 nAsrStatus = LD_ASR_NONE; break; } case LD_ASR_FOUNDZERO: default: { nAsrStatus = LD_ASR_NONE; break; } }// switch }// while }
PrintCom("{"VoiceCommandCode":1}");
/*********************************************************** * 名 称:用户执行函数 * 功 能:识别成功后,执行动作可在此进行修改 * 入口参数: 无 * 出口参数:无 * 说 明: **********************************************************/ void User_handle(uint8 dat) { //UARTSendByte(dat);//串口识别码(十六进制) if(0==dat) { G0_flag=ENABLE; LED=0; PrintCom("{"VoiceCommandCode":0}"); PrintCom("收到rn"); /*text.....*/ } else if(ENABLE==G0_flag) { G0_flag=DISABLE; LED=1; switch(dat) /*对结果执行相关操作,客户可删除Printcom 串口输出语句替换为其他需要控制的代码*/ { case CODE_XZJDL: /*命令“测试”*/ PrintCom("{"VoiceCommandCode":1}"); PrintCom("“现在几点了”命令识别成功rn"); /*text.....*/ break; case CODE_DQSJ: PrintCom("{"VoiceCommandCode":2}"); PrintCom("“当前时间”命令识别成功rn"); /*text.....*/ break; case CODE_XZSK: PrintCom("{"VoiceCommandCode":3}"); PrintCom("“现在时刻”命令识别成功rn"); /*text.....*/ break; case CODE_BS: PrintCom("{"VoiceCommandCode":4}"); PrintCom("“报时”命令识别成功rn"); /*text.....*/ break; case CODE_DQWD: PrintCom("{"VoiceCommandCode":5}"); PrintCom("“当前温度”命令识别成功rn"); /*text.....*/ break; case CODE_DQSD: PrintCom("{"VoiceCommandCode":6}"); PrintCom("“当前湿度”命令识别成功rn"); /*text.....*/ break; case CODE_WSDDS: PrintCom("{"VoiceCommandCode":7}"); PrintCom("“温湿度多少”命令识别成功rn"); /*text.....*/ break; default: PrintCom("{"VoiceCommandCode":-1}"); PrintCom("请重新识别发口令rn"); /*text.....*/ break; } } else { PrintCom("{"VoiceCommandCode":-2}"); PrintCom("请说出一级口令rn"); /*text.....*/ } }
//LD3320 if(USART5_RX_STA&0x8000) { uart5Len=USART5_RX_STA&0x3f; //得到此次接收到的数据长度 //发送测试数据至串口1 for(i=0;i<uart5Len;i++) { USART_SendData(USART1, USART5_RX_BUF[i]); //向串口 1 发送数据 while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET); //等待发送结束 } receive_json = cJSON_Parse(USART5_RX_BUF); //创建JSON解析对象,返回JSON格式是否正确 if (!receive_json) { printf("JSON格式错误:%s rn", cJSON_GetErrorPtr()); //输出json格式错误信息 } else { printf("JSON格式正确:%s rn",cJSON_Print(receive_json) ); item_obj = receive_json->child; //获取name键对应的值的信息 while(item_obj) { char * string = item_obj->string; if(!strcmp(string,"VoiceCommandCode")) { if(item_obj->valueint==0) { printf("收到一级口令 智能报时 ... rn"); } else if(item_obj->valueint==1) { printf("“现在几点了”命令识别成功 rn"); m_nCurrentVoicePlayTimes++; while(U5152_BSY){} if(m_nCurrentVoicePlayTimes%2==0) { sprintf((char*)dtbuf,"[v5][s5][m3]当前时间为%02d时%02d分%02d秒 rn",NowHour,NowMinute,NowSecond); } else { sprintf((char*)dtbuf,"[v5][s5][m51]当前时间为%02d时%02d分%02d秒 rn",NowHour,NowMinute,NowSecond); } printf((char*)dtbuf); XFS_FrameInfo((char*)dtbuf) ; delay_ms(10);while(U5152_BSY){delay_ms(500);printf("while(U5152_BSY) rn");} } else if(item_obj->valueint==2) { printf("“当前时间”命令识别成功rn"); m_nCurrentVoicePlayTimes++; while(U5152_BSY){} if(m_nCurrentVoicePlayTimes%2==0) { sprintf((char*)dtbuf,"[v5][s5][m3]当前时间为%02d时%02d分%02d秒 rn",NowHour,NowMinute,NowSecond); } else { sprintf((char*)dtbuf,"[v5][s5][m51]当前时间为%02d时%02d分%02d秒 rn",NowHour,NowMinute,NowSecond); } printf((char*)dtbuf); XFS_FrameInfo((char*)dtbuf) ; delay_ms(10);while(U5152_BSY){delay_ms(500);printf("while(U5152_BSY) rn");} } else if(item_obj->valueint==3) { printf("“现在时刻”命令识别成功rn"); m_nCurrentVoicePlayTimes++; while(U5152_BSY){} if(m_nCurrentVoicePlayTimes%2==0) { sprintf((char*)dtbuf,"[v5][s5][m3]当前时间为%02d时%02d分%02d秒 rn",NowHour,NowMinute,NowSecond); } else { sprintf((char*)dtbuf,"[v5][s5][m51]当前时间为%02d时%02d分%02d秒 rn",NowHour,NowMinute,NowSecond); } printf((char*)dtbuf); XFS_FrameInfo((char*)dtbuf) ; delay_ms(10);while(U5152_BSY){delay_ms(500);printf("while(U5152_BSY) rn");} } else if(item_obj->valueint==4) { printf("“关灯”命令识别成功rn"); } else if(item_obj->valueint==5) { printf("“当前温度”命令识别成功rn"); m_nCurrentVoicePlayTimes++; while(U5152_BSY){} if(m_nCurrentVoicePlayTimes%2==0) { sprintf((char*)dtbuf,"[v5][s5][m3]当前温度为%.1f摄氏度 rn",DHT11Temp); } else { sprintf((char*)dtbuf,"[v5][s5][m51]当前温度为%.1f摄氏度 rn",DHT11Temp); } printf((char*)dtbuf); XFS_FrameInfo((char*)dtbuf) ; delay_ms(10);while(U5152_BSY){delay_ms(500);printf("while(U5152_BSY) rn");} } else if(item_obj->valueint==6) { printf("“当前湿度”命令识别成功rn"); m_nCurrentVoicePlayTimes++; while(U5152_BSY){} if(m_nCurrentVoicePlayTimes%2==0) { sprintf((char*)dtbuf,"[v5][s5][m3]当前湿度为百分之%.1f rn",DHT11Hum); } else { sprintf((char*)dtbuf,"[v5][s5][m51]当前湿度为百分之%.1f rn",DHT11Hum); } printf((char*)dtbuf); XFS_FrameInfo((char*)dtbuf) ; delay_ms(10);while(U5152_BSY){delay_ms(500);printf("while(U5152_BSY) rn");} } else if(item_obj->valueint==7) { printf("“温湿度多少”命令识别成功rn"); m_nCurrentVoicePlayTimes++; while(U5152_BSY){} if(m_nCurrentVoicePlayTimes%2==0) { sprintf((char*)dtbuf,"[v5][s5][m3]温度为%.1f度,湿度为%.1f rn",DHT11Temp,DHT11Hum); } else { sprintf((char*)dtbuf,"[v5][s5][m51]温度为%.1f度,湿度为%.1f rn",DHT11Temp,DHT11Hum); } printf((char*)dtbuf); XFS_FrameInfo((char*)dtbuf) ; delay_ms(10);while(U5152_BSY){delay_ms(500);printf("while(U5152_BSY) rn");} } } item_obj = item_obj->next; printf("while(item_obj) rn"); } } cJSON_Delete(receive_json); USART5_RX_STA=0; memset(USART5_RX_BUF, 0, sizeof(USART5_RX_BUF)); //清空数组 }
{"VoiceCommandCode":0}收到 {"VoiceCommandCode":1}“现在几点了”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":2}“当前时间”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":3}“现在时刻”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":4}“报时”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":5}“当前温度”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":6}“当前湿度”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":7}“温湿度多少”命令识别成功 {"VoiceCommandCode":0}收到 {"VoiceCommandCode":7}“温湿度多少”命令识别成功
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算