【ARM-Linux】项目,语音刷抖音项目

文章目录

所需器材

可以百度了解以下器材

orangepi-zero2全志开发板

su-03T语音识别模块

USB-TTL模块

一个安卓手机

一根可以传输的数据线

装备操作

安卓手机开启,开发者模式,并开启USB调试功能。

插入开发板,跳出什么就点允许就行(否则可能没有权限开发板无权访问手机系统)

SU-03T语音模块配置

进入网站:http://www.smartpi.cn/

这个模块其实进入网站点点点就可以完成,非常方便,但是没有什么技术含量

配置SU-03T模块
设置串口通信

设置唤醒词

设置命令触发

设置触发之后发送的命令

到此点击身材sdk,安静等待就可以了,搞好之后需要,将sdk上传至语音模块

将USB-TTL模块插入电脑,并将TX,RX与模块的TX,RX交叉相接。
将下载的sdk文件,打开,上传即可(图就不放了,较简单)

可以使用串口工具测试一下~

测试没问题将语音模块RX和TX接入开发板的RX,TX端口

代码(没有用wiring库,自己实现串口通信)

由于没有用wiring库所以多出俩个工具文件。当然也是用source insight分析源码cv编写,没写注释,将就看吧,这俩个文件,比较难啃,都是和linux内核打交道struct termios options;

uartTools.c

c 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

int myserialOpen (const char *device, const int baud)
{
	speed_t myBaud ;
	int     status, fd ;	
	struct termios options;
	switch (baud){
		case    9600:	myBaud =    B9600 ; break ;
		case  115200:	myBaud =  B115200 ; break ;
	}
	if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1)
		return -1 ;
	fcntl (fd, F_SETFL, O_RDWR) ;
	// Get and modify current options:

	tcgetattr (fd, &options) ;

	cfmakeraw   (&options) ;
	cfsetispeed (&options, myBaud) ;
	cfsetospeed (&options, myBaud) ;

	options.c_cflag |= (CLOCAL | CREAD) ;
	options.c_cflag &= ~PARENB ;
	options.c_cflag &= ~CSTOPB ;
	options.c_cflag &= ~CSIZE ;			
	options.c_cflag |= CS8 ;			//数据位8个
	options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
	options.c_oflag &= ~OPOST ;

	options.c_cc [VMIN]  =   0 ;
	options.c_cc [VTIME] = 100 ;	// Ten seconds (100 deciseconds)

	tcsetattr (fd, TCSANOW, &options) ;

	ioctl (fd, TIOCMGET, &status);

	status |= TIOCM_DTR ;
	status |= TIOCM_RTS ;

	ioctl (fd, TIOCMSET, &status);

	usleep (10000) ;	// 10mS

	return fd ;
}

void myserialPutchar (const int fd, const unsigned char c)
{
	int ret;
	ret = write (fd, &c, 1) ;
	if (ret < 0)
		printf("Serial Putchar Error\n");
}

void mySerialSendString(const int fd,const unsigned char *str)
{
	if(write(fd,str,strlen(str)) < 0){
		printf("Serial sendString Error\n");
	}
}

int mySerialGetchar(const int fd, unsigned char *c)
{
	if(read(fd,c,1) !=1){
		return -1 ;
	}
	
}

int mySerialGetString(const int fd, unsigned char *str)
{
	if(read(fd,str,32) != 32){
		return -1;
	}
}

uartTools.h

c 复制代码
#ifndef _UART_TOOLS_H_
#define _UART_TOOLS_H_
int myserialOpen (const char *device, const int baud);
void myserialPutchar (const int fd, const unsigned char c);
void mySerialSendString(const int fd,const unsigned char *str);
int mySerialGetchar(const int fd, unsigned char *c);
int mySerialGetString(const int fd, unsigned char *str);

#endif

uart.c

到这里就是简单的处理语音模块发来的命令了

c 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>

#include "uartTools.h"

int fd;

void *recvHandler()
{
	char *recvBuf;
	
	recvBuf = (char *)malloc(sizeof(char)*32);
	if(recvBuf == NULL){
		printf("recvHandler malloc fail\n");
	}
	while(1){
		memset(recvBuf,'\0',strlen(recvBuf));
		mySerialGetchar(fd,recvBuf);
		switch(*recvBuf){
			case 'N':
				printf("next\n");
				system("adb shell input swipe 540 1300 540 500 100");		//adb 命令,模拟手机滑动屏幕
				break;
			case 'P':
				printf("pre\n");
				system("adb shell input swipe 540 500 540 1300 100");
				break;
			case 'Z':
				system("adb shell \"seq 2 | while read i;do input tap 350 1050 & input tap 350 1050 &sleep 0.2;done;\"");
				printf("zan\n");
				break;
			case 'Q':
				printf("quit\n");
				system("adb shell input keyevent 26");
				break;
		}
	}

}

int main(char argc, char **argv)
{

	char filename[32] = {'\0'};
	pthread_t recvPthread;

	if(argc < 2){
		printf("uage:%s /dev/ttyS?\n",argv[0]);
		return -1;
	}

	strcpy(filename,argv[1]);

	if((fd = myserialOpen(filename,115200)) == -1){
		printf("open %s error\n",filename);
		return -1;
	}

	pthread_create(&recvPthread,NULL,recvHandler,NULL);

	while(1){sleep(10);}

	return 0;
}

结束

如有问题,欢迎提出,共同进步

相关推荐
轻松Ai享生活10 小时前
5 节课深入学习Linux Cgroups
linux
christine-rr10 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神55511 小时前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆11 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
乌萨奇也要立志学C++11 小时前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
獭.獭.13 小时前
Linux -- 信号【上】
linux·运维·服务器
hashiqimiya13 小时前
centos配置环境变量jdk
linux·运维·centos
hashiqimiya13 小时前
权限更改centos中系统文件无法创建文件夹,使用命令让普通用户具备操作文件夹
linux
逆小舟17 小时前
【Linux】人事档案——用户及组管理
linux·c++
青草地溪水旁17 小时前
pthread_mutex_lock函数深度解析
linux·多线程·pthread