树莓派和语音模块实现语音识别功能

树莓派与语音模块接线图

在这里插入图片描述

语音模块

修改LDchip.c

找到LD_AsrAddFixed函数
功能描述:向LD模块添加关键词
在这里插入图片描述

修改main.c

找到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 <stdio.h>
#include <unistd.h>
#include <string.h>
#include <wiringPi.h>
#include <wiringSerial.h>

int main()
{
        int fd;
        char cmd[128] = {'\0'};
        int nread;

        //使用wiringpi引脚就必须初始化设备
        if(wiringPiSetup() == -1)
        {
                printf("初始化失败!\n");
                return -1;
        }

        
        //打开串口设备文件
        fd = serialOpen("/dev/ttyAMA0",9600);

        //树莓派接收读取语音发来的数据
        while(1){
                //int serialGetchar (int fd)
                nread = read(fd,cmd,sizeof(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的字串,返回NULL
                {
                        printf("Open Light success\n");
                }
                if(strstr(cmd,"Close") != NULL)
                {
                        printf("Close Light success\n");
                }
                //清空数据
                memset(cmd,'\0',sizeof(cmd)/sizeof(char));
        }
        return 0;
}

测试结果

在这里插入图片描述

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值