linux语音刷抖音

一、手机连接linux

1.安装工具:输入指令

sudo apt-get install adb

2、手机连接开发板子。

3、用dmesg查看是否接入 

 4、输入adb device

出现这种情况是因为手机没有开启USB调试功能,要在手机里的开发者模式打开USB调试功能。

打开后结果为:

 5、这种情况还是有问题的,根据解决方法

重新拔插后可以看出你的设备ID为2717:ff08(不同设备ID不同)

 配置好后、重新拔插USB

 这样就代表连接成功

6.进入adb shell

 错误解决:在手机开发者选项里选择允许USB调试

 如果想退出就输入exit

 

 二、adb控制指令

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

adb shell input swipe 540 1300 540 500 100

//向下滑动,从坐标(540,1300)以100毫秒的速度滑到(540,500)

adb shell input swipe 540 500 540 1300 100

//向上滑动,从坐标(540,500)以100毫秒的速度滑到(540,1300)

adb shell "seq 2 | while read i;do input tap 540 1050 & input tap 540 1050 & sleep 0.1;done;"

//双击。在(540 1050)的坐标点击2次间隔0.1s.

adb shell input keyevent 26

 //锁屏

 三、语音模块设置

使用的语音模块为SU-03T。

配置链接如下:

智能公元 

 相关配置:

 mySerial.c

#include<stdio.h>
#include"serialTool.h"
#include<pthread.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
int fd;

void* read_t()
{
	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 540 1050 & input tap 540 1050 & sleep 0.1;done;\"");//2个双引号要加转意字符“\”
			break;
		case'Q':
			printf("quit\n");
			system("adb shell input keyevent 26");
			break;

	}
	}
}

int main(int argc,char **argv)
{
	char serial[32] = {'\0'};
	pthread_t readt;

	if(argc<2)
	{
		printf("set:/dev/ttys?");
		return -1;
	}
	strcpy(serial,argv[1]);

	if((fd = mySerialOpen(serial,115200)) == -1)
	{
		printf("打开失败\n");
		return -1;
	}

	pthread_create(&readt,NULL,read_t,NULL);
	while(1){
		sleep(10);
	}
}

 

serialTool.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"

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 serialPutString(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;

}
char myserialGetchar (const int fd)
{
  char x ;

  if (read (fd, &x, 1) != 1)
    return -1 ;

  return x;
}

serialTool.h

int mySerialOpen (const char *device, const int baud);
void serialPutString (const int fd, const char *s);
int serialGetString (const int fd);
char myserialGetchar (const int fd);

编译运行对语音模块说出相应命令词即可。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要有一个具备语音识别功能的设备,例如树莓派,然后将其连接到你要控制的电脑或手机上。 接下来,你需要安装一个串口通信程序,例如minicom或putty,在Linux系统上使用串口连接到你的设备。 然后,你需要编写一个Python脚本,使用串口通信来与你的设备进行通信,并将语音识别结果发送给电脑或手机上的抖音客户端。 具体实现方法可以参考以下步骤: 1. 首先,你需要安装Python的串口通信模块,例如pyserial,可以使用以下命令进行安装: ``` pip install pyserial ``` 2. 接着,你需要编写一个Python脚本,使用串口通信来与你的设备进行通信,例如: ```python import serial ser = serial.Serial('/dev/ttyUSB0', 9600) # 将串口号和波特率替换为你的设备对应的值 while True: if ser.in_waiting > 0: data = ser.readline().decode('utf-8').strip() print(data) # 输出从设备接收到的数据 ``` 这段代码将会不断地从串口接收数据,并输出到控制台中。 3. 接下来,你需要集成语音识别功能,例如使用百度语音识别API,可以使用以下命令进行安装: ``` pip install baidu-aip ``` 4. 然后,你需要编写一个函数,使用百度语音识别API来将语音转换为文本,例如: ```python from aip import AipSpeech APP_ID = 'your_app_id' API_KEY = 'your_api_key' SECRET_KEY = 'your_secret_key' client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) def speech_to_text(file_path): with open(file_path, 'rb') as f: speech_data = f.read() result = client.asr(speech_data, 'pcm', 16000, {'dev_pid': 1536}) if result['err_no'] == 0: text = result['result'][0] return text else: return None ``` 这个函数将会使用百度语音识别API将指定语音文件转换为文本。 5. 最后,你需要将语音识别结果发送给电脑或手机上的抖音客户端,例如: ```python import os import time def send_to_douyin(text): os.system('adb shell input tap 540 1700') # 替换为你的手机屏幕上打开抖音的位置 time.sleep(2) os.system('adb shell input tap 540 700') # 替换为你的手机屏幕上搜索按钮的位置 time.sleep(2) os.system('adb shell input text "{}"'.format(text)) # 输入搜索内容 time.sleep(2) os.system('adb shell input tap 540 1000') # 替换为你的手机屏幕上搜索结果的位置 time.sleep(2) os.system('adb shell input tap 540 1500') # 替换为你的手机屏幕上播放按钮的位置 ``` 这段代码将会使用ADB工具来模拟手机操作,实现在抖音客户端中搜索并播放指定的内容。 综上所述,你可以通过以上步骤基于Linux串口实现语音控制抖音的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值