基于linux串口实现语音刷抖音

简介: 基于linux串口实现语音刷抖音

1.开发逻辑图及模块

逻辑图:

模块

(1)语音模块: SU-03T

(2)开发板全志H616

(3)一部手机

接线语音模块TX(B7)接RX,VCC接VCC,GND接GND

配置好语音模块


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

通配符编译

代码示例:

vi uartTool.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 "wiringSerial.h"
 
char myserialGetchar (const int fd)
{
        char x;
 
        if(read (fd,&x,1) != 1)
                return -1;
 
        return x;
}
 
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 ;
  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 ;
  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;
}

vi uartTool.h

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);

vi uartTest.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 <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);}
}

3.手机接入Linux热拔插相关,打开手机开发者模式允许USB调试

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. 手机弹出调试提醒,点确认手机调试模式


重新拔插一下输入命令 adb devices显示SerialNumber

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.05;done;" 双击屏幕(实现点赞功能)


adb shell input keyevent 26 锁屏

5.最终主程序代码

vi uartTest.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 <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.05;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);}
}

编译:

相关文章
|
20天前
|
监控 Shell Linux
【Shell 命令集合 网络通讯 】Linux 分析串口的状态 statserial命令 使用指南
【Shell 命令集合 网络通讯 】Linux 分析串口的状态 statserial命令 使用指南
38 0
|
8月前
|
Linux
linux系统中串口驱动的基本实现原理
linux系统中串口驱动的基本实现原理
78 1
|
8月前
|
Linux 人机交互 C语言
Linux系统中如何实现串口的格式化功能方法
Linux系统中如何实现串口的格式化功能方法
43 0
|
20天前
|
机器学习/深度学习 自然语言处理 Linux
【专栏】Linux 中的机器学习:Whisper适用于语音助手、翻译等领域,随着技术发展,其应用前景广阔
【4月更文挑战第28天】本文探讨了在Linux环境下,先进自动语音识别系统Whisper的运用与实现高效ASR。Whisper基于PyTorch,支持多语言识别,具有高准确性和实时性。文中介绍了安装配置Whisper的步骤,包括安装依赖、下载代码、配置环境变量及编译安装。通过数据准备、模型训练和识别,可实现语音识别功能。Whisper适用于语音助手、翻译等领域,随着技术发展,其应用前景广阔。
|
15天前
|
运维 Ubuntu 安全
运维最全linux 命令行操作串口_linux串口命令(2),2024年最新Linux运维源码的Binder权限是如何控制
运维最全linux 命令行操作串口_linux串口命令(2),2024年最新Linux运维源码的Binder权限是如何控制
运维最全linux 命令行操作串口_linux串口命令(2),2024年最新Linux运维源码的Binder权限是如何控制
|
15天前
|
运维 Linux Perl
运维最全linux 命令行操作串口_linux串口命令(1),21年Linux运维面经分享
运维最全linux 命令行操作串口_linux串口命令(1),21年Linux运维面经分享
运维最全linux 命令行操作串口_linux串口命令(1),21年Linux运维面经分享
|
20天前
|
数据采集 Linux Go
Linux系统是如何控制串口收发数据的?
Linux系统是如何控制串口收发数据的?
20 0
|
20天前
|
安全 Linux
嵌入式Linux系统关闭串口调试信息的输出
嵌入式Linux系统关闭串口调试信息的输出
66 1
|
20天前
|
传感器 Linux API
嵌入式Linux串口编程简介
嵌入式Linux串口编程简介
21 1