装逼小项目语音刷抖音

语言控制刷抖音小项目

1.装逼小项目:语言控制刷抖音

image-20240509162826639

1.1.语音模块配置

  1. 进入语音模块官网 http://www.smartpi.cn/#/,进行配置词条和识别后的串口输出指令

image-20240509162906712

  1. 记录下相关指令以及上图的识别词条,方便固件烧写后的调试

image-20240509162949859

  1. 固件烧写

    串口接线:官方手册是VCC接串口VCC

    ​ B7 引脚 接 串口RXD

    ​ B6 引脚 接 串口 TXD

    ​ GND 接 串口 GND

    • 下载SDK将解压文件放到没有中文路径下,打开烧写软件

    烧写

    • 烧写文件

    烧写2

    • 烧写前先把固件电源拨到OFF,选择固件以后拨到ON开始烧入

  1. 固件先和电脑调试助手配合,验证数据

    语音串口验证

1.2.编程实现语音和开发板通信

开发板接线:

​ VCC接5V

​ B7 引脚 RXD //负责把接收到的结果发送给全志H616 Linux

​ GND 接 GND

  1. 将语音模块插入开发板并编程实现基础逻辑代码,添加串口读取一个字符的接口

头文件程序:

int myserialOpen (const char *device, const int baud);
void serialSendstring (const int fd, const char *s);
int serialGetstring (const int fd,char *buffer);
char myserialGetchar (const int fd);

函数程序

#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 "wiringSerial.h"

char myserialGetchar (const int fd)
{
    char x ;
 
    if (read (fd, &x, 1) != 1)
      return -1 ;

    return ((int)x) & 0xFF ;
}
 

int myserialOpen (const char *device, const int baud)
{
	struct termios options ;
  	speed_t myBaud ;
  	int     status, fd ;

	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 ;

	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 ;//数据位
    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 serialSendstring (const int fd, const char *s)//发送字符串
{	
	int ret;
	ret = write (fd, s, strlen (s));
	if (ret < 0)
		printf("Serial Puts Error\n");
}

int serialGetstring (const int fd,char *buffer)//获得字符串
{
	int n_read;
	n_read = read(fd,buffer,32);
	return n_read;


}


myserialGetchar();

串口语音测试主程序

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include "uartTool.h"
int fd;
void* readSerial()
{
    char cmd;
    while(1){
        cmd = myserialGetchar(fd);
        switch(cmd){
            case 'N':
                printf("next\n");
                break;
            case 'P':
                printf("pre\n");
                break;
            case 'Z':
                printf("zan\n");
                break;
            case 'Q':
                printf("qu\n");
                break;
       }
   }
}
int main(int argc, char **argv)
{
    char deviceName[32] = {'\0'};
    pthread_t readt;
    if(argc < 2){
        printf("uage:%s /dev/ttyS?\n",argv[0]);
        return -1;
   }
    strcpy(deviceName, argv[1]);
    if( (fd = myserialOpen(deviceName, 115200)) == -1){
        printf("open %s error\n",deviceName);
        return -1;
   }
pthread_create(&readt, NULL, readSerial,NULL);
    while(1){sleep(10);}
}

1.3.手机接入Linux热拔插相关

a. 把手机接入开发板
b. 安装adb工具,在终端输入adb安装指令: sudo apt-get install adb
c. dmesg能查看到手机接入的信息,但是输入adb devices会出现提醒
dinsufficient permissions for device: user in plugdev group; are your udev 
rules wrong?
d. 配置文件,以支持USB设备的热拔插,支持UDEV的机制
在/etc/udev/rules.d 文件夹下创建规则文件
cd /etc/udev/rules.d/
sudo vim 51-android.rules
在文件中添加内容 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666"
e. 在手机开发者选项中,打开USB调试,重新拔插手机
f. 手机弹出调试提醒,点确认手机调试模式

1.3.1.常见问题及解决方法

工作中要是遇到问题先不要着急去问别人和问主管,这样会显得你很NO,先去问一下度娘,你遇到的这些问题别人曾经遇到过,写的博文

我遇到的问题1:设备未被识别
有时,执行adb devices后,设备列表为空,无法识别连接的Android设备。

解决方法:

  • 确保USB调试已开启:在设备的开发者选项中,启用USB调试。
  • 安装正确的驱动程序:确保在计算机上安装了正确的USB驱动程序,使其能够识别Android设备。
  • 重新连接设备:尝试重新连接USB并执行adb devices。

1.4.用shell指令来操作手机屏幕,模拟手动滑屏幕

adb shell input swipe 540 1300 540 500 100 向下滑动540是水平的,1300是竖直方向,下 是
500
adb shell input swipe 540 500 540 1300 100 向上滑动
adb shell "seq 3 | while read i;do input tap 350 1050 & input tap 350 1050 & 
sleep 0.01;done;" 点赞
adb shell input keyevent 26 锁屏

1.5.最后主程序

#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 <unistd.h>
#include <pthread.h>
#include "uartTool.h"
int fd;
void* readSerial()
{
    char cmd;
 while(1){
        cmd = myserialGetchar(fd);
        switch(cmd){
            case 'N':
                printf("next\n");
                system("adb shell input swipe 540 1300 540 500 100");
                break;
            case 'P':
                printf("pre\n");
                system("adb shell input swipe 540 500 540 1300 100");
                break;
            case 'Z':
                printf("zan\n");
                system("adb shell \"seq 3 | while read i;do input tap 350 1050 & 
input tap 350 1050 & sleep 0.01;done;\"");
                break;
            case 'Q':
                printf("qu\n");
                system("adb shell input keyevent 26");
                break;
       }
   }
}
int main(int argc, char **argv)
{
    char deviceName[32] = {'\0'};
    pthread_t readt;
    if(argc < 2){
        printf("uage:%s /dev/ttyS?\n",argv[0]);
        return -1;
   }
    strcpy(deviceName, argv[1]);
    if( (fd = myserialOpen(deviceName, 115200)) == -1){
        printf("open %s error\n",deviceName);
        return -1;
   }
    pthread_create(&readt, NULL, readSerial,NULL);
    while(1){sleep(10);}
}




  • 31
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值