
- 树莓派与语音模块接线图
- 语音模块
- 修改LDchip.c
- 修改main.c
- 树莓派串口配置
- 语音识别功能实现代码
- 测试结果
找到LD_AsrAddFixed函数
功能描述:向LD模块添加关键词
找到User_handle函数
识别出结果后,把数据从语音模块发出来
初次使用树莓派串口编程,需要对串口进行配置
/* 修改 cmdline.txt文件 */
>cd /boot/
>sudo vim cmdline.txt
删除【】之间的部分
dwc_otg.lpm_enable=0 【console=ttyAMA0,115200】 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
语音识别功能实现代码
#include
#include
#include
#include
#include
int main()
{
int fd;
char cmd[128] = {'}';int
; nread//使用wiringpi引脚就必须初始化设备
if
(wiringPiSetup()== - 1)printf
{
("初始化失败!\n");return
- 1;}
//打开串口设备文件
=
fd serialOpen ("/dev/ttyAMA0",9600);//树莓派接收读取语音发来的数据
while
(1)//int serialGetchar (int fd){
=
nread read (,fd,cmdsizeof()cmd);//cmd为树莓派接收到的指令printf
("getdata=%dbyte over,please say\n",)nread;if
(strlen()cmd== 0 )printf
{
("overtime\n");continue
;}
if
(strstr(,cmd"Open")!= NULL )//strstr:若str2不是str1的字串,返回NULLprintf
{
("Open Light success\n");}
if
(strstr(,cmd"Close")!= NULL )printf
{
("Close Light success\n");}
//清空数据
memset
(,cmd','sizeof()/cmdsizeof(char));}return
0
; }
测试结果
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)