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

结束

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

相关推荐
A小辣椒2 天前
TShark:Wireshark CLI 功能
linux
A小辣椒2 天前
TShark:基础知识
linux
AlfredZhao2 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao3 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334663 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪3 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠3 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush44 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5204 天前
Linux 11 动态监控指令top
linux
不会C语言的男孩4 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言