【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;
}

结束

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

相关推荐
Johny_Zhao38 分钟前
Docker + CentOS 部署 Zookeeper 集群 + Kubernetes Operator 自动化运维方案
linux·网络安全·docker·信息安全·zookeeper·kubernetes·云计算·系统运维
小毛驴8501 小时前
Linux 后台启动java jar 程序 nohup java -jar
java·linux·jar
好好学习啊天天向上2 小时前
世上最全:ubuntu 上及天河超算上源码编译llvm遇到的坑,cmake,ninja完整过程
linux·运维·ubuntu·自动性能优化
tan180°3 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
学不动CV了4 小时前
ARM单片机启动流程(二)(详细解析)
c语言·arm开发·stm32·单片机·51单片机
典学长编程4 小时前
Linux操作系统从入门到精通!第二天(命令行)
linux·运维·chrome
wuk9984 小时前
基于MATLAB编制的锂离子电池伪二维模型
linux·windows·github
独行soc7 小时前
#渗透测试#批量漏洞挖掘#HSC Mailinspector 任意文件读取漏洞(CVE-2024-34470)
linux·科技·安全·网络安全·面试·渗透测试
BD_Marathon7 小时前
Ubuntu下Tomcat的配置
linux·ubuntu·tomcat
饥饿的半导体7 小时前
Linux快速入门
linux·运维