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

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

记得也要去修改这个玩意儿

#include<wiringSerial.h>
#include<wiringPi.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>

int main()
{
        int fd;

        char cmd[128] = {'\0'};
        int nread;

        wiringPiSetup();

        fd = serialOpen("/dev/ttyAMA0",9600);

        while(1){
                nread = read(fd, cmd , sizeof(cmd));
                if(strlen(cmd) == 0){
                        printf("chaoshi\n");
                        continue;
                }
                if(strstr(cmd,"open") != NULL){
                        printf("open light\n");  //要找厂家拿语音模块的代码去更改  把相应的代码改成 字母或者数字  不能是中文  否则会树莓派乱码
                }
                if( strstr(cmd,"close") != NULL){
                        printf("close light\n");
                }
//              printf("getData: %dbyte,contex:%s\n",nread,cmd);
                memset(cmd,'\0',sizeof(cmd)/sizeof(char));
        }

        return 0;
}

要去注意 语音模块可能供电不足  就是因为这个原因让我忙活了一晚上加一上午的时间   可以让语音模块的5v 和gnd接到插电脑的串口上 让语音模块的rx tx继续接到树莓派  这样供电就上去了

同时要注意 波特率 语音模块要和树莓派相同

猜你喜欢

转载自blog.csdn.net/weixin_46016743/article/details/112863066