目录
开发平台/开发环境:
windows 10、Linux、arm cortex A9(Exynos 4412)、ubuntu20.04、zigebee通信、摄像头外设、cortex-M0;
项目模块:
摄像头模块;qt界面及语音识别模块;qt客户端模块;服务器模块;
项目描述:
qt客户端可以通过连接服务器后,通过语音识别,确定想要的功能,可以通过服务器显示摄像头内的视频内容,也可以通过服务器的串口通信去操控cortex M0的LED灯,风扇,蜂鸣器,服务器可以通过串口通信实时地获得cortex M0上的温度,湿度,光照信息,并发送给客户端,qt客户端还可以获取天气预报信息或者打开某一个应用。
具体代码:
1.串口模块:
serial.h:
serial.c:
摄像头:
camera.h:
camera.c
摄像头服务器:
camera_server.h:
camera_server.c:
服务器:
server.h
server.c
主函数
main.c
下面是QT的模块:使用的模式是:QT widgets applicantion;使用的基类是:widget
录音和设置语音文件:对应下面audio.c
audio.h
http请求百度api获取请求数据:
http.h
处理http请求数据并再次请求百度api再次返回的json:
speech.h
通过http协议获取天气 :
weather.h
界面操作:
widget.h
audio.cpp
http.cpp
main.cpp
speech.cpp
weather.cpp
widget.cpp
ui界面:
演示:
开发平台/开发环境:
windows 10、Linux、arm cortex A9(Exynos 4412)、ubuntu20.04、zigebee通信、摄像头外设、cortex-M0;
arm cortex A9(Exynos 4412):内部使用裁剪后的Linux系统来搭建服务器。
ubuntu20.04:使用arm-linux-gcc工具编译成可以在arm架构芯片上执行的程序。
zigbee协调节点板块与A9板使用串口通信,ZigBee 模块主要实现的是数据的透传的工作,一个 ZigBee 节点接收服务器的消息无线转到ZigBee 的另外一个节点,另外一个节点把数据发送给终端设备,完成操作。同时也可以反过来,是终端设备的环境信息。我使用的CC2530 的单片机。它是一款完全兼容 8051 的内核,同时支持 IEEE 802.15.4协议的无线射频的单片机。这个项目主要是使用 ZigBee 提供的协议栈来进行开发。使用了其中的函数接口来完成项目需求的应用程序。
数据终端采集:
数据采集模块使用的是 ARM 系列的 Cortex-M0 芯片,在这个芯片的基础之上。分别外接了以下几个设备。有温湿度、光照、三轴传感器与 RFID 射频模块。还是风扇、LED、蜂鸣器、OLED 硬件。同时集成第 94 页了 RS485、CAN 总线。在这个项目中,使用到了温湿度、光照、三轴传感器获取当前的环境信息,发送到ZigBee 的节点。从 ZigBee 的节点接收命令通过风扇、LED、蜂鸣器来模拟家中的电器设备。在这个模块中使用了 ARM 开发的一些流程,如配置寄存器让硬件工作。一些总线设备的使用,如 SPI、I2C。还有中断的机制和定时器的使用,如本项目中启用了一个 32 位的定时器来做延时操作。
项目模块:
摄像头模块;qt界面及语音识别模块;qt客户端模块;服务器模块;
项目描述:
qt客户端可以通过连接服务器后,通过语音识别,确定想要的功能,可以通过服务器显示摄像头内的视频内容,也可以通过服务器的串口通信去操控cortex M0的LED灯,风扇,蜂鸣器,服务器可以通过串口通信实时地获得cortex M0上的温度,湿度,光照信息,并发送给客户端,qt客户端还可以获取天气预报信息或者打开某一个应用。
具体代码:
1.串口模块:
serial.h:
#ifndef SERIAL_H
#define SERIAL_H#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <termios.h>
#include <error.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
int serial_set(char *path);
int serial_write(int fd);
int serial_close(int fd);
int serial_ctrl(int fd,char *p);
int serial_getdata(int fd);#endif
serial.c:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <termios.h>
#include <sys/types.h>
#include <string.h>#define N 36
int serial_set(char *path)
{struct termios options;/*struct termios {tcflag_t c_iflag;//输入标志tcflag_t c_oflag;//输出标志tcflag_t c_lflag;// 本地标志tcflag_t c_cc[NCCS];//控制字符}; */int fd = open(path,O_RDWR | O_NOCTTY | O_NDELAY);//打开串口if(-1 == fd){perror("open error");return -1;}if(-1 == fcntl(fd,F_SETFL,0)){printf("fcntl error");return -1;}cfsetispeed(&options,B115200);cfsetospeed(&options,B115200);options.c_cflag |= CLOCAL; //修改控制模式,使得能够从串口中读取输入数据 options.c_cflag |= CREAD; options.c_oflag &= ~(ONLCR | OCRNL);options.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);options.c_iflag &= ~(ICRNL | INLCR);options.c_iflag &= ~(IXON | IXOFF | IXANY);//不使用流控制options.c_cflag &= ~CRTSCTS;options.c_cflag |= CS8;options.c_cflag &= ~CSTOPB;options.c_cflag &= ~PARENB;options.c_iflag &= ~INPCK;tcsetattr(fd, TCSANOW, &options); //TCSANOW更改立即发生return fd;
}
int serial_close(int fd) //关闭串口
{if (close(fd)) {perror("serial close error");return -1;}return 0;
}
int serial_ctrl(int fd,char *p)
{ unsigned char envbuf[36]={0,0x08,0x24,0x00};if(strncmp(p,"light_on",8)==0){//envbuf[] = {0xdd,id,24,00,命令}//发送命令开灯envbuf[0]=0xdd;envbuf[4]=0x00; //开灯命令if(write(fd,envbuf,36)<0){perror("write");return -1;}printf("控制:%x %x %x %x %x\n",envbuf[0],envbuf[1],envbuf[2],envbuf[3],envbuf[4]);}else if(strncmp(p,"light_off",9)==0){//发送命令关灯envbuf[0]=0xdd;envbuf[4]=0x01; //关灯if(write(fd,envbuf,36)<0){perror("write");return -1;}printf("控制:%x %x %x %x %x\n",envbuf[0],envbuf[1],envbuf[2],envbuf[3],envbuf[4]);}else if(strncmp(p,"dshi_on",9)==0){//发送命令打开蜂鸣器envbuf[0]=0xdd;envbuf[4]=0x02; if(write(fd,envbuf,36)<0){perror("write");return -1;}printf("控制:%x %x %x %x %x\n",envbuf[0],envbuf[1],envbuf[2],envbuf[3],envbuf[4]);}else if(strncmp(p,"dshi_off",10)==0){//发送命令关闭蜂鸣器envbuf[0]=0xdd;envbuf[4]=0x03;if(write(fd,envbuf,36)<0){perror("write");return -1;}printf("控制:%x %x %x %x %x\n",envbuf[0],envbuf[1],envbuf[2],envbuf[3],envbuf[4]);}else if(strncmp(p,"feng_on",7)==0){printf("feng_on\n");//发送命令打开风扇envbuf[0]=0xdd;envbuf[4]=0x04;printf("控制:%x %x %x %x %x\n",envbuf[0],envbuf[1],envbuf[2],envbuf[3],envbuf[4]);if(write(fd,envbuf,36)<0){perror("write");return -1;}}else if(strncmp(p,"feng_off",8)==0){//发送命令关闭风扇envbuf[0]=0xdd;envbuf[4]=0x08;if(write(fd,envbuf,36)<0){perror("write");return -1;}printf("控制:%x %x %x %x %x\n",envbuf[0],envbuf[1],envbuf[2],envbuf[3],envbuf[4]);}// memset(p, 0, 32); //清空bufreturn 0;
}
摄像头:
camera.h:
#ifndef _CAMERA_H
#define _CAMERA_H#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/videodev2.h>
#include <string.h>
#include <sys/mman.h>#define pwd "/dev/video0"
#define pwd2 "/dev/video1"
#define c_count 4unsigned char *mmps[c_count];
unsigned long mmpsize[c_count];int camera_init();
int camera_star(int fd);
//出队,采集数据
int dqbuf(int fd,int index);
//入队,归还数据
int qbuf(int fd,int index);
int camera_stop(int fd);#endif
camera.c
#include "camera.h"int camera_init()
{int ret;//v4l2_std_id std;//struct v4l2_format fmt;//使用非阻塞方式打开摄像头设备int camera_fd = open(pwd,O_RDWR,0);if(camera_fd < 0){camera_fd = open(pwd2,O_RDWR | O_NONBLOCK,0);} if(camera_fd < 0){printf("摄像头打开失败\n");return -1;} printf("成功打开摄像头\n");//使用ioctl函数对设备的io通道进行管理//检查当前视频设备支持的标准,使用VIDIOC_QUERYSTD
/* do{ret = ioctl(camera_fd,VIDIOC_QUERYSTD,&std); }while(-1 == ret && errno == EAGAIN);switch (std){case V4L2_STD_NTSC:printf("视频标准为NTSC\n"); break; case V4L2_STD_PAL:printf("视频标准为PAL\n");break;}*///设置视频捕获格式bzero(&fmt,sizeof(fmt));//摄像头的数据流类型,必须为V4L2_BUF_TYPE_VIDEO_CAPTUREfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;fmt.fmt.pix.width = 640; //必须为16的倍数fmt.fmt.pix.height = 480; //必须为16的倍数//视频数据存储类型YUYV 或者 RGBfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;if(-1 == ioctl(camera_fd,VIDIOC_S_FMT,&fmt)){printf("设置视频捕获格式失败\n");return -2;}//为视频捕获分配内存struct v4l2_requestbuffers req;bzero(&req,sizeof(req));req.count = c_count;req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;req.memory = V4L2_MEMORY_MMAP;if(-1 == ioctl(camera_fd,VIDIOC_REQBUFS,&req)){printf("分配内存出错\n");return -3;}printf("分配内存成功\n");int i;struct v4l2_buffer buffer;for(i=0;i<c_count;i++){buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buffer.memory = V4L2_MEMORY_MMAP;buffer.index = i;if(0 > ioctl(camera_fd,VIDIOC_QUERYBUF,&buffer)){printf("取出映射地址出错\n");return -1;}//映射mmps[i] = mmap(NULL,buffer.length,PROT_READ|PROT_WRITE,MAP_SHARED,camera_fd,buffer.m.offset);mmpsize[i] = buffer.length;if((void *)-1 == mmps[i]){printf("映射地址时出错\n");return -2;}//入队操作if(0 > ioctl(camera_fd,VIDIOC_QBUF,&buffer)){printf("入队失败\n");return -3;} }printf("摄像头初始化成功...\n");return camera_fd;
}
int camera_star(int fd)
{//开始采集enum v4l2_buf_type type=V4L2_BUF_TYPE_VIDEO_CAPTURE;if(0 > ioctl(fd,VIDIOC_STREAMON,&type)){perror("采集失败:");return -1;} printf("开始采集...\n");return 0;
}
//出队,采集数据
int dqbuf(int fd,int index)
{struct v4l2_buffer buffer;bzero(&buffer,sizeof(buffer));buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buffer.memory=V4L2_MEMORY_MMAP;buffer.index = index;if(0 > ioctl(fd,VIDIOC_DQBUF,&buffer)){printf("读取视频内容失败\n");perror("read");return -1;}return 0;
}//入队,归还数据
int qbuf(int fd,int index)
{struct v4l2_buffer buffer;bzero(&buffer,sizeof(buffer));buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buffer.memory=V4L2_MEMORY_MMAP;buffer.index = index;if(0 > ioctl(fd,VIDIOC_QBUF,&buffer)){printf("入队失败\n");return -1;}return 0;
}
/*
int getpic(int fd)
{//映射队列空间到用户空间VIDIOC_QUERYBUF,VIDIOC_QBUFstruct v4l2_buffer buffer;int i=0;while(1){//出对,获得采集数据bzero(&buffer,sizeof(buffer));buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buffer.memory=V4L2_MEMORY_MMAP;buffer.index = i;if(0 > ioctl(fd,VIDIOC_DQBUF,&buffer)){printf("读取视频内容失败\n");perror("read");return -4;}//测试图片FILE *file = fopen("1.jpg","w+");fwrite(mmps[buffer.index],buffer.length,1,file);fclose(file);//入对if(0 > ioctl(fd,VIDIOC_QBUF,&buffer)){printf("入队失败\n");return -5;}i++;i=i%4;}return 0;
}
*/
int camera_stop(int fd)
{//停止采集int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if(0 > ioctl(fd,VIDIOC_STREAMOFF,&type)){printf("停止摄像头错误\n");return -1;}printf("停止摄像头\n");return 0;
}
/*
int main()
{int camera_fd = camera_init();if(0 > camera_fd){return -1;}if(0 > camera_star(camera_fd)){return -1;}int i=0;while(1){if(0 > dqbuf(camera_fd,i))//出队,从mmps映射的地址读取数据{return -1;}FILE *file = fopen("1.jpg","w+");fwrite(mmps[i],mmpsize[i],1,file);fclose(file);if(0 > qbuf(camera_fd,i))//入队{return -1;}i++;i%=4;}//getpic(camera_fd);camera_stop(camera_fd);return 0;
}
*/
摄像头服务器:
camera_server.h:
#ifndef _CAMERA__SERVER_H
#define _CAMERA__SERVER_H#include "camera.h"
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <pthread.h>int camera_all();
void * camera_close_thread(void * fd);
void * camera_send_thread(void * fd);
void * camera_thread(void * fd);#endif
camera_server.c:
#include "camera_server.h"int camera_fd = -1;
int socket_fd = -1;
char * pic_buf [4] = {NULL,NULL,NULL,NULL};
long unsigned int pic_len = 0;
int camera_i=0;void * camera_thread(void * fd)
{printf("开始摄像头线程\n");if(0 > camera_star(camera_fd)){pthread_exit(NULL);}while(1){if(0 > dqbuf(camera_fd,camera_i))//出队,从mmps映射的地址读取数据{pthread_exit(NULL);}if(NULL == pic_buf[0]){pic_len= mmpsize[camera_i];pic_buf[0] = (char *)malloc(pic_len);pic_buf[1] = (char *)malloc(pic_len);pic_buf[2] = (char *)malloc(pic_len);pic_buf[3] = (char *)malloc(pic_len);}bzero(pic_buf[camera_i],pic_len);memcpy(pic_buf[camera_i],mmps[camera_i],pic_len);if(0 > qbuf(camera_fd,camera_i))//入队{pthread_exit(NULL);}camera_i++;camera_i%=4;}pthread_exit(NULL);
}
void * camera_send_thread(void * fd)
{int connfd = *(int *)fd;int j=0;char len[10]={0};char buf[10]={0};while(1){if(0>=read(connfd,buf,sizeof(buf))){printf("客户端退出\n");break;}else{sprintf(len,"%ld",pic_len);send(connfd,len,sizeof(len),0);j=camera_i-1;if(-1 == j){j = 3;}send(connfd,pic_buf[j],pic_len,0);}}printf("发送结束\n");pthread_exit(NULL);}void * camera_close_thread(void * fd)
{while(1){char cmd[16];bzero(cmd,sizeof(cmd));scanf("%s",cmd);getchar();if(0 == strcmp(cmd,"quit")){printf("摄像头服务器关闭。。。\n");break;}}camera_stop(camera_fd);exit(0);
}
int camera_all()
//int main()
{//创建套接字socket_fd = socket(AF_INET,SOCK_STREAM,0);if(-1 == socket_fd){perror("socket");return -1;}printf("摄像头网络套接字创建成功\n");//优化2:解决地址冲突int opt = 1; setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));//填充ip,端口,协议等struct sockaddr_in ser_addr = {.sin_family = AF_INET,.sin_port = htons(8888),//端口号1024-49151.sin_addr.s_addr = inet_addr("0.0.0.0")};//绑定ip和端口等信息int ret = bind(socket_fd,(struct sockaddr *) &ser_addr,sizeof(ser_addr));if(-1 == ret){perror("bind");return -1;}printf("绑定成功\n"); //建立监听ret = listen(socket_fd,4);if(-1 == ret){perror("listen");return -1;}printf("建立监听。。。\n");struct sockaddr_in accept_addr;bzero(&accept_addr,sizeof(accept_addr));socklen_t addrlen = sizeof(accept_addr);//初始化摄像头camera_fd = camera_init();if(0 > camera_fd){pthread_exit(NULL);}pthread_t tid1,tid2,tid3; if(-1 == pthread_create(&tid1,NULL,camera_thread,NULL)){printf("摄像头线程启动失败\n");return -1;}pthread_detach(tid1);while(1){ int connfd = accept(socket_fd,(struct sockaddr *)&accept_addr,&addrlen);if(-1 == pthread_create(&tid2,NULL,camera_close_thread,NULL)){printf("关闭摄像头线程启动失败\n");return -1;}pthread_detach(tid2); printf("客户端连接成功\n");printf("IP:%s,port:%d,addrlen:%d\n",inet_ntoa(accept_addr.sin_addr),accept_addr.sin_port,addrlen);printf("启动摄像头发送线程\n");if(-1 == pthread_create(&tid3,NULL,camera_send_thread,(void *)&connfd)){printf("摄像头线程启动失败\n");return -1;}pthread_detach(tid3); }
}
服务器:
server.h
#ifndef SER_H
#define SER_H#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/ip.h>
#include<netinet/in.h>
#include<stdio.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<pthread.h>
#include<string.h>
#include<unistd.h>
#include<semaphore.h>
#define N 16
#define SIZE 36typedef struct sockaddr_in SA_in;typedef struct sockaddr SA;typedef unsigned short uint_16_t;
typedef unsigned int uint_32_t;int tcp_init(const char *ip,const int port ,const int backlog);int getorder(const int connfd);
void *sendvideo(void *arg);
void *serial_cntl(void *arg);
void *senddata_cli(void *arg);#endif
server.c
#include "camera_server.h"int camera_fd = -1;
int socket_fd = -1;
char * pic_buf [4] = {NULL,NULL,NULL,NULL};
long unsigned int pic_len = 0;
int camera_i=0;void * camera_thread(void * fd)
{printf("开始摄像头线程\n");if(0 > camera_star(camera_fd)){pthread_exit(NULL);}while(1){if(0 > dqbuf(camera_fd,camera_i))//出队,从mmps映射的地址读取数据{pthread_exit(NULL);}if(NULL == pic_buf[0]){pic_len= mmpsize[camera_i];pic_buf[0] = (char *)malloc(pic_len);pic_buf[1] = (char *)malloc(pic_len);pic_buf[2] = (char *)malloc(pic_len);pic_buf[3] = (char *)malloc(pic_len);}bzero(pic_buf[camera_i],pic_len);memcpy(pic_buf[camera_i],mmps[camera_i],pic_len);if(0 > qbuf(camera_fd,camera_i))//入队{pthread_exit(NULL);}camera_i++;camera_i%=4;}pthread_exit(NULL);
}
void * camera_send_thread(void * fd)
{int connfd = *(int *)fd;int j=0;char len[10]={0};char buf[10]={0};while(1){if(0>=read(connfd,buf,sizeof(buf))){printf("客户端退出\n");break;}else{sprintf(len,"%ld",pic_len);send(connfd,len,sizeof(len),0);j=camera_i-1;if(-1 == j){j = 3;}send(connfd,pic_buf[j],pic_len,0);}}printf("发送结束\n");pthread_exit(NULL);}void * camera_close_thread(void * fd)
{while(1){char cmd[16];bzero(cmd,sizeof(cmd));scanf("%s",cmd);getchar();if(0 == strcmp(cmd,"quit")){printf("摄像头服务器关闭。。。\n");break;}}camera_stop(camera_fd);exit(0);
}
int camera_all()
//int main()
{//创建套接字socket_fd = socket(AF_INET,SOCK_STREAM,0);if(-1 == socket_fd){perror("socket");return -1;}printf("摄像头网络套接字创建成功\n");//优化2:解决地址冲突int opt = 1; setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));//填充ip,端口,协议等struct sockaddr_in ser_addr = {.sin_family = AF_INET,.sin_port = htons(8888),//端口号1024-49151.sin_addr.s_addr = inet_addr("0.0.0.0")};//绑定ip和端口等信息int ret = bind(socket_fd,(struct sockaddr *) &ser_addr,sizeof(ser_addr));if(-1 == ret){perror("bind");return -1;}printf("绑定成功\n"); //建立监听ret = listen(socket_fd,4);if(-1 == ret){perror("listen");return -1;}printf("建立监听。。。\n");struct sockaddr_in accept_addr;bzero(&accept_addr,sizeof(accept_addr));socklen_t addrlen = sizeof(accept_addr);//初始化摄像头camera_fd = camera_init();if(0 > camera_fd){pthread_exit(NULL);}pthread_t tid1,tid2,tid3; if(-1 == pthread_create(&tid1,NULL,camera_thread,NULL)){printf("摄像头线程启动失败\n");return -1;}pthread_detach(tid1);while(1){ int connfd = accept(socket_fd,(struct sockaddr *)&accept_addr,&addrlen);if(-1 == pthread_create(&tid2,NULL,camera_close_thread,NULL)){printf("关闭摄像头线程启动失败\n");return -1;}pthread_detach(tid2); printf("客户端连接成功\n");printf("IP:%s,port:%d,addrlen:%d\n",inet_ntoa(accept_addr.sin_addr),accept_addr.sin_port,addrlen);printf("启动摄像头发送线程\n");if(-1 == pthread_create(&tid3,NULL,camera_send_thread,(void *)&connfd)){printf("摄像头线程启动失败\n");return -1;}pthread_detach(tid3); }
}
主函数
main.c
#include "ser.h"
const char *ip="0";
const int port=7777;
const int backlog=5;int main(int argc, char *argv[])
{SA_in cli_addr;socklen_t cli_addr_len=sizeof(cli_addr);int sfd=tcp_init(ip,port,backlog);pthread_t camera_thread;pthread_create(&camera_thread,NULL,sendvideo,NULL); pthread_detach(camera_thread);while(1){int connfd=accept(sfd,(SA*)&cli_addr,&cli_addr_len);if(-1==connfd){perror("connect");return -1;}printf("客户端已连接\n");int ret=getorder(connfd);}
}
下面是QT的模块:使用的模式是:QT widgets applicantion;使用的基类是:widget
在.pro文件下要添加这几个模块 :
QT += core gui network multimedia texttospeech
录音和设置语音文件:对应下面audio.c
audio.h
#ifndef AUDIO_H
#define AUDIO_H#include <QObject>
#include <QAudioInput>
#include <QFile>
#include <QAudioDeviceInfo>
#include <QMessageBox>class audio : public QObject
{Q_OBJECT
public:explicit audio(QObject *parent = nullptr);void startRecord(QString filename); //开始录音void stopRecord(); //停止录音~audio();
signals:
public slots:private:QAudioInput *m_audioInput; //录音对象QFile *m_file; //
};
#endif // AUDIO_H
http请求百度api获取请求数据:
http.h
#ifndef HTTP_H
#define HTTP_H#include <QObject>
#include <QMap>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QEventLoop>
class http : public QObject
{Q_OBJECT
public:explicit http(QObject *parent = nullptr);bool postSyn(QString url, QMap<QString, QString> headerdata, QByteArray requestData, QByteArray &replydata);
signals:public slots:
};
#endif // HTTP_H
处理http请求数据并再次请求百度api再次返回的json:
speech.h
#ifndef SPEECH_H
#define SPEECH_H#include <QObject>
#include "http.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QHostInfo>
#include <QFile>
#include <QMessageBox>
#include <QIODevice>
//获取access_token相关
const QString baiduTokenUrl = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=(填写语音ai的id)&client_secret=(语音ai的秘钥)&";
const QString client_id = "(填写语音ai的id)";
const QString client_secret = "(语音ai的秘钥)";//语音识别相关
const QString baiduSpeechurl = "http://vop.baidu.com/server_api?dev_pid=1537&cuid=%1&token=%2"; //普通话测试class speech : public QObject
{Q_OBJECT
public:explicit speech(QObject *parent = nullptr);QString speechIdentify(QString filename); //开始识别QString getJsonvalue(QByteArray ba,QString key);
signals:public slots:
private:QString accessToken;
};
#endif // SPEECH_H
通过http协议获取天气 :
weather.h
#ifndef WEATHER_H
#define WEATHER_H#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QtTextToSpeech>class weather : QObject
{Q_OBJECT
public:explicit weather(QObject *parent = nullptr);QString processing_data(const int);void getweather(const QString);
private slots:void reply(QNetworkReply*);
private:QNetworkAccessManager *manager;QJsonObject obj;QTextToSpeech speak;};#endif // WEATHER_H
界面操作:
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>#include <QMessageBox>#include <QMovie>#include <QLabel>#include <QBitmap>#include <QTcpSocket>#include <QDebug>#include <QUdpSocket>#include <QHostAddress>#include "audio.h"#include "speech.h"#include "weather.h"#include <QTimer>#include <string.h>#include <QTextToSpeech>#include <QVoice>#include <QProcess>namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();private slots:void on_pushButton_4_clicked();void on_pushButton_clicked();void on_pushButton_3_clicked();void netConnected();void netConnected1();void disconnectcam();void disconnectserver();void read1();void sav1();void on_pushButton_2_clicked();void on_pushButton_6_clicked();void on_pushButton_5_clicked();void on_pushButton_7_clicked();void on_pushButton_8_clicked();void on_pushButton_9_clicked();void on_pushButton_10_clicked();void on_btn_speekin_pressed();void on_btn_speekin_released();void on_wtobtn_clicked();void on_wyesbtn_clicked();private:Ui::Widget *ui;QTcpSocket *socket;//QTcpSocket *camsocket;QTcpSocket *camsocket;QByteArray pbuf;QString ip;int port;int port1;QPixmap pixmap;QHostAddress saddr;quint16 sport;int state =1;int plen;audio Audiodevice; //创建录音设备对象speech m_speech;QTimer *time;weather *wt;int day=0;QString addr;int flaglight = 1;int flagfeng = 1;int flagcurtain = 1;int flagdshi = 1;bool flagserver = false;QTextToSpeech speak;QProcess *p1,*p2;};#endif // WIDGET_H
audio.cpp
#include "audio.h"audio::audio(QObject *parent) : QObject(parent)
{}
void audio::startRecord(QString filename)
{// 判断本地设备是否支持该格式QAudioDeviceInfo audioDeviceInfo = QAudioDeviceInfo::defaultInputDevice();// 判断本地是否有录音设备;if (!audioDeviceInfo.isNull()){m_file = new QFile;m_file->setFileName(filename);m_file->open(QIODevice::WriteOnly | QIODevice::Truncate);// 设置音频文件格式;QAudioFormat format;// 设置采样频率;format.setSampleRate(16000);// 设置通道数;format.setChannelCount(1);// 设置每次采样得到的样本数据位值;format.setSampleSize(16);// 设置编码方法;format.setCodec("audio/pcm");// 设置采样字节存储顺序;//format.setByteOrder(QAudioFormat::LittleEndian);// 设置采样类型;//format.setSampleType(QAudioFormat::UnSignedInt);// 判断当前设备设置是否支持该音频格式(重点);if (!audioDeviceInfo.isFormatSupported(format)){format = audioDeviceInfo.nearestFormat(format);}// 创建录音对象;m_audioInput = new QAudioInput(format, this);//开始录音m_audioInput->start(m_file);}else{// 没有录音设备;QMessageBox::information(NULL, tr("Record"), tr("Current No Record Device"));}}void audio::stopRecord()
{//停止录音m_audioInput->stop();//关闭文件m_file->close();//删除文件对象delete m_file; //删除只是删除了指针指向的内存空间,没有删除指针,需要将指针指为NULLm_file = NULL;}
audio::~audio()
{delete m_audioInput;delete m_file;
}
http.cpp
#include "http.h"http::http(QObject *parent) : QObject(parent)
{}bool http::postSyn( QString url, QMap<QString, QString> headerdata, QByteArray requestData, QByteArray &replydata)
{
//发送请求的对象QNetworkAccessManager manager;
//请求对象QNetworkRequest request;request.setUrl(url);QMapIterator<QString, QString> it(headerdata); //迭代器while (it.hasNext()) //遍历Map{it.next();request.setRawHeader(it.key().toLatin1(),it.value().toLatin1());}QNetworkReply *reply = manager.post(request, requestData) ;QEventLoop l;//一旦服务器返回,reply会发出信号connect(reply, &QNetworkReply::finished, &l, &QEventLoop::quit);l.exec();//死循环,reply发出信号, 结束循环if (reply != nullptr && reply->error() == QNetworkReply::NoError){replydata = reply->readAll(); //读取服务 器返回的数据qDebug() << replydata;return true;}else{qDebug() << "请求失败";return false;}
}
main.cpp
#include "widget.h"
#include <QApplication>
#include <QMessageBox>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}
speech.cpp
#include "speech.h"//构造函数
speech::speech(QObject *parent) : QObject(parent)
{}QString speech::speechIdentify(QString filename)
{//获取tokenQString tokenUrl = QString(baiduTokenUrl).arg(client_id).arg(client_secret);QMap<QString, QString> headers;headers.insert(QString("Content-Type"), QString("audio/pcm;rate=16000"));QByteArray requestdata; //发送的内容QByteArray replydata; //服务器返回的内容http httputil;bool success = httputil.postSyn(tokenUrl, headers, requestdata, replydata);if (success){QString key = "access_token";accessToken = getJsonvalue(replydata, key); //获取到access_token(通过json数据格式解析)}elsereturn "";//语言识别QString baiduSpeech = QString(baiduSpeechurl).arg(QHostInfo::localHostName()).arg(accessToken);//把文件 转化为QByteArrayQFile file;file.setFileName(filename);file.open(QIODevice::ReadOnly);requestdata =file.readAll();file.close();replydata.clear();//再次发起http请求bool result = httputil.postSyn(baiduSpeech, headers, requestdata, replydata);if (result){QString key = "result" ;QString text = getJsonvalue (replydata, key) ;return text;}else{QMessageBox::warning(NULL,"识别提示","识别失败");}return "";}QString speech::getJsonvalue(QByteArray ba, QString key)
{QJsonParseError parseError;QJsonDocument jsonDocument = QJsonDocument::fromJson(ba, &parseError);if(parseError.error == QJsonParseError::NoError){if(jsonDocument.isObject()){//jsonDocument转换成json对象QJsonObject jsonObj = jsonDocument.object() ;if (jsonObj.contains (key)){QJsonValue jsonVal = jsonObj.value(key);if (jsonVal.isString())//字符串{return jsonVal.toString();}else if (jsonVal.isArray()) //数组{QJsonArray arr = jsonVal.toArray(); //转换成JsonArrayQJsonValue jv = arr.at(0); //获取第1个元素return jv. toString();}}}}return "";
}
weather.cpp
#include "weather.h"weather::weather(QObject *parent) : QObject(parent)
{manager = new QNetworkAccessManager(this);connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(reply(QNetworkReply*)));speak.setVolume(200);
}void weather::reply(QNetworkReply *rep)
{QByteArray data = rep->readAll();data = data.mid(29,data.length()-31);QJsonObject obj = QJsonDocument::fromJson(data).object();this->obj = obj;
}QString weather::processing_data(int day)
{QString data,date,weath,temp,wind;//fl,fx,high,low,type,data;if(!obj.contains("weather")){data = "未查询到天气";return data;}/*QJsonObject objp= obj.value("weather").toObject();if(!objp.contains("weather")){data = "未查询到昨天的天气";return data;}QJsonObject objp1= objp.value("weather").toObject();*//*if(-1 == day){if(!objp.contains("yesterday")){data = "未查询到昨天的天气";return data;}QJsonObject obj1 = objp.value("yesterday").toObject();date = obj1.value("date").toString();fl = obj1.value("fl").toString();fx = obj1.value("fx").toString();high = obj1.value("high").toString();low = obj1.value("low").toString();type = obj1.value("type").toString();data = date + "\n"+ "风力 :" + fl + "\n"+ "风向 :" + fx + "\n"+ high + "\n"+ low + "\n"+ "天气 :" + type;speak.say(data);}*/if(day>=0 && day<=6){/*if(!objp1.contains("weather")){data = "未查询到今天及未来几天天气情况。";return data;}*/QJsonArray arr = obj.value("weather").toArray();QJsonObject today = arr.at(day).toObject();date = today.value("date").toString();weath = today.value("weather").toString();temp = today.value("temp").toString();wind = today.value("wind").toString();data = date + "\n"+ "天气:" + weath + "\n"+ "温度:" + temp + "\n"+ "风向:" + wind;/*date = today.value("date").toString();fl = today.value("weather").toString();fx = today.value("temp").toString();high = today.value("wind").toString();low = today.value("low").toString();type = today.value("type").toString();data = date + "\n"+ "风力 :" + fl + "\n"+ "风向 :" + fx + "\n"+ high + "\n"+ low + "\n"+ "天气 :" + type;*/speak.say(data);}else{data = "超出范围";}return data;
}
void weather::getweather(const QString addr)
{//QString url ="http://wthrcdn.etouch.cn/weather_mini?city=" + addr;QString url ="https://query.asilu.com/weather/baidu/?city=${" + addr + "}&callback=weather";QNetworkRequest request;request.setUrl(QUrl(url));manager->get(request);
}
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);p1 = new QProcess(this);p2 = new QProcess(this);this->setMinimumSize(QSize(1000, 600));this->setFixedSize( this->width (),this->height ());//固定窗口大小//设置按键的失能false 使能trueui->pushButton->setEnabled(false);ui->pushButton_3->setEnabled(false);ui->pushButton_2->setEnabled(false);ui->pushButton_6->setEnabled(false);ui->pushButton_7->setEnabled(false);ui->pushButton_8->setEnabled(false);ui->pushButton_10->setEnabled(false);//time = new QTimer;wt = new weather;addr = ui->lineaddr->text();wt->getweather(ui->lineaddr->text());ui->weathertext->setText(wt->processing_data(day));connect(ui->lineaddr,&QLineEdit::textChanged,this,[&](){wt->getweather(ui->lineaddr->text());day=0;ui->weathertext->setText(wt->processing_data(day));});//speak.setVoice(myvoice.at(1));speak.setVolume(200);//connect(time,&QTimer::timeout,this,[&](){});//time->start(2000);/*QMovie *mv = new QMovie(":/new/prefix1/bj2.gif");ui->label_5->setScaledContents(true);ui->label_5->setMovie(mv);mv->start();//label动图*/}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_4_clicked()//连接服务器
{ip=ui->lineEdit->text();port =ui->lineEdit_2->text().toInt();socket=new QTcpSocket;connect(socket,&QTcpSocket::connected,this,&Widget::netConnected);connect(socket,&QTcpSocket::readyRead,this,&Widget::read1);connect(socket,&QTcpSocket::disconnected,this,&Widget::disconnectserver);socket->connectToHost(ip,port);//服务器端口套接字}void Widget::disconnectserver()
{socket->close();ui->label_12->setText("服务器已断开!");ui->lineEdit_gq->setText("0");ui->lineEdit_sd->setText("0");ui->lineEdit_wd->setText("0");ui->pushButton->setDisabled(true);ui->pushButton_8->setDisabled(true);ui->pushButton_10->setDisabled(true);ui->pushButton_2->setDisabled(true);ui->pushButton_6->setDisabled(true);ui->pushButton_4->setEnabled(true);flagserver = false;
}void Widget::on_pushButton_9_clicked()//udp连接摄像头
{//QString data = "connect";saddr=ui->lineEdit->text().toLatin1();//摄像头用的套接字sport =ui->lineEdit_3->text().toInt();camsocket=new QTcpSocket(this);//camsocket->writeDatagram(data.toLatin1(),saddr,sport);connect(camsocket,&QTcpSocket::readyRead,this,&Widget::sav1);connect(camsocket,&QTcpSocket::connected,this,&Widget::netConnected1);connect(camsocket,&QTcpSocket::disconnected,this,&Widget::disconnectcam);camsocket->connectToHost(saddr,sport);camsocket->write("ok");
}void Widget::disconnectcam()
{camsocket->close();ui->label_11->setText("摄像头已断开!");ui->label_4->setText("摄像头已经断开");ui->pushButton_7->setDisabled(true);ui->pushButton_9->setEnabled(true);
}//用户自定义的槽,服务器连接成功过后使能和失能按键
void Widget::netConnected()
{ui->label_12->setText("服务器连接成功");flagserver = true;qDebug()<<"ip:"<<ip<<"port:"<<port;ui->pushButton->setEnabled(true);ui->pushButton_3->setEnabled(true);ui->pushButton_2->setEnabled(true);ui->pushButton_6->setEnabled(true);ui->pushButton_8->setEnabled(true);ui->pushButton_4->setEnabled(false);ui->pushButton_10->setEnabled(true);}void Widget::netConnected1()
{ //ui->label_11->setText("摄像头连接成功");ui->pushButton_7->setEnabled(true);qDebug()<<"ip:"<<ip<<"port1:"<<port1;ui->pushButton_9->setEnabled(false);
}void Widget::read1()
{char buf[36]={0};socket->read(buf,36);/*char *i = nullptr;i=(char *)&data;evnir.temperature =*(unsigned short *)i;evnir.humidity =*(unsigned short *)(i+sizeof(unsigned short));evnir.illuminance = *(unsigned int *)(i+2*sizeof(unsigned short));*///sprintf(buf,"t:%d h:%d i:%d",&evnir.temperature,&evnir.humidity,&evnir.illuminance);int guang=0,wen=0,shi=0;sscanf(buf,"t:%d h:%d i:%d",&wen,&shi,&guang);//qDebug()<<data.toStdString().data()<<":"<<wen<<":"<<shi<<":"<<guang;qDebug()<<buf<<":"<<wen<<":"<<shi<<":"<<guang;/*if(guang>180){socket->write("chuang_on");ui->label_5->setStyleSheet("border-image: url(:/di1.2.jpg);");ui->pushButton_8->setText("目前\n 窗帘 关闭");}if(guang<=180){socket->write("chuang_off");ui->label_5->setStyleSheet("border-image: url(:/new/prefix1/di1.JPG);");ui->pushButton_8->setText("目前\n 窗帘 打开");}*/ui->lineEdit_gq->setText(QString::number(guang));ui->lineEdit_sd->setText(QString::number(shi));ui->lineEdit_wd->setText(QString::number(wen));
}
void Widget::sav1()
{//接收图片switch (state){case 1:plen=camsocket->read(10).toInt();camsocket->write("ok");state=2;break;case 2:if(camsocket->bytesAvailable()<plen)return;pbuf = camsocket->read(plen);pixmap.loadFromData(pbuf);ui->label_4->setPixmap(pixmap);state=1;camsocket->write("ok");break;}}void Widget::on_pushButton_clicked()
{socket->disconnectFromHost();socket->close();ui->label_12->setText("服务器已断开!");ui->pushButton->setEnabled(false);ui->pushButton_3->setEnabled(false);ui->pushButton_2->setEnabled(false);ui->pushButton_6->setEnabled(false);ui->pushButton_4->setEnabled(true);}void Widget::on_pushButton_3_clicked()
{QString data=ui->textEdit->toPlainText();// socket->write(data.toStdString().data());socket->write(data.toLatin1());ui->textEdit->clear();
}void Widget::on_pushButton_2_clicked()
{//开关灯指令if(flaglight==1){ui->pushButton_2->setStyleSheet("border-image: url(:/new/prefix1/deng1.png);");socket->write("light_on");ui->pushButton_2->setText("目前\n 灯 开");flaglight=2;}else{ui->pushButton_2->setStyleSheet("border:none;");socket->write("light_off");ui->pushButton_2->setText("目前\n 灯 关");flaglight=1;}
}void Widget::on_pushButton_6_clicked()
{//开风扇指令if(flagfeng==1){ui->pushButton_6->setStyleSheet("border-image: url(:/new/prefix1/feng0.2.png);");socket->write("feng_on");ui->pushButton_6->setText("目前\n 风扇 开");flagfeng=2;}else{ui->pushButton_6->setStyleSheet("border-image: url(:/new/prefix1/feng0.1.png);");socket->write("feng_off");ui->pushButton_6->setText("目前\n 风扇 关");flagfeng=1;}}void Widget::on_pushButton_5_clicked()
{//缩放视频画面static int flag = 1;if(flag==1){//ui->textEdit_2->setGeometry(300,150,700,500);//ui->textEdit_2->setGeometry(440,240,520,322);//ui->label_4->setGeometry(450,250,500,300);ui->textEdit_2->setGeometry(this->width()/1000*440,this->height()/600*240,this->width()/1000*520,this->height()/600*322);ui->label_4->setGeometry(this->width()/1000*450,this->height()/600*250,this->width()/1000*500,this->height()/600*300);flag=2;}else{ui->textEdit_2->setGeometry(600,240,171,201);ui->label_4->setGeometry(610,250,151,181);flag=1;}}void Widget::on_pushButton_7_clicked()
{camsocket->disconnectFromHost();camsocket->close();ui->label_11->setText("摄像头已断开!");ui->pushButton_7->setEnabled(false);ui->pushButton_9->setEnabled(true);ui->label_4->clear();}void Widget::on_pushButton_8_clicked()
{//窗帘开关if(flagcurtain==1){socket->write("chuang_on");ui->label_5->setStyleSheet("border-image: url(:/di1.2.jpg);");ui->pushButton_8->setText("目前\n 窗帘 关闭");flagcurtain=2;}else{socket->write("chuang_off");ui->label_5->setStyleSheet("border-image: url(:/new/prefix1/di1.JPG);");ui->pushButton_8->setText("目前\n 窗帘 打开");flagcurtain=1;}
}void Widget::on_pushButton_10_clicked()
{//电视开关if(flagdshi==1){socket->write("dshi_on");ui->label_6->setStyleSheet("border-image: url(:/ds.png);");flagdshi=2;}else{socket->write("dshi_off");ui->label_6->setStyleSheet("border-image: url(:/ds2.png);");flagdshi=1;}
}void Widget::on_btn_speekin_pressed()
{ui->btn_speekin->setText("松开识别");Audiodevice.startRecord("D:\\crs\\qtday1\\qtxm\\yysb\\1.pcm");
}void Widget::on_btn_speekin_released()
{//停止录音Audiodevice.stopRecord();//修改按钮文件ui->btn_speekin->setText("开始识别");//开始识别QString text = m_speech.speechIdentify("D:\\crs\\qtday1\\qtxm\\yysb\\1.pcm");QString text1 = text.mid(4,text.length()-5);qDebug()<<text1;text1 = text.left(4);qDebug()<<text1;if(text != ""){ui->textEdit->setText(text);ui->btn_speekin->setText("按住说话");if(text == "开灯。"){if(1 == flaglight && flagserver == true){speak.say("好的,正在为你开灯。");ui->pushButton_2->setStyleSheet("border-image: url(:/new/prefix1/deng1.png);");socket->write("light_on");ui->pushButton_2->setText("目前\n 灯 开");flaglight=2;return;}speak.say("主人,灯已经是打开状态!");}else if(text == "关灯。"){if(2 == flaglight && flagserver == true){speak.say("好的,正在为你关灯。");ui->pushButton_2->setStyleSheet("border:none;");socket->write("light_off");ui->pushButton_2->setText("目前\n 灯 关");flaglight=1;return;}speak.say("主人,灯已经是关闭状态!");}else if(text == "打开风扇。"){if(flagfeng==1 && flagserver == true){speak.say("好的,正在为你打开风扇。");ui->pushButton_6->setStyleSheet("border-image: url(:/new/prefix1/feng0.2.png);");socket->write("feng_on");ui->pushButton_6->setText("目前\n 风扇 开");flagfeng=2;return;}speak.say("亲爱的主人啊,风扇已经是打开状态哟。");}else if(text == "关闭风扇。"){if(flagfeng == 2 && flagserver == true){speak.say("好的,正在为你关闭风扇。");ui->pushButton_6->setStyleSheet("border-image: url(:/new/prefix1/feng0.1.png);");socket->write("feng_off");ui->pushButton_6->setText("目前\n 风扇 关");flagfeng=1;return;}speak.say("非常抱歉,风扇已经是关闭状态哟。");}else if(text == "打开电视。"){if(flagdshi==1 && flagserver == true){speak.say("好的,正在为你打开电视。");socket->write("dshi_on");ui->label_6->setStyleSheet("border-image: url(:/ds.png);");flagdshi=2;return;}speak.say("稍等我看一下,电视已经是打开状态哟。");}else if(text == "关闭电视。"){if(flagdshi == 2 && flagserver == true){speak.say("好的,正在为你关闭电视。");socket->write("dshi_off");ui->label_6->setStyleSheet("border-image: url(:/ds2.png);");flagdshi=1;return;}speak.say("正在检查状态,电视已经是关闭状态哟。");}else if(text == "打开窗帘。"){if(flagcurtain==1 && flagserver == true){speak.say("好的,正在为你打开窗帘。");socket->write("chuang_on");ui->label_5->setStyleSheet("border-image: url(:/di1.2.jpg);");ui->pushButton_8->setText("目前\n 窗帘 关闭");flagcurtain=2;return;}speak.say("检查窗帘状态,窗帘已经是打开状态哟。");}else if(text == "关闭窗帘。"){if(flagcurtain == 2 && flagserver == true){speak.say("好的,正在为你关闭窗帘。");socket->write("chuang_off");ui->label_5->setStyleSheet("border-image: url(:/new/prefix1/di1.JPG);");ui->pushButton_8->setText("目前\n 窗帘 打开");flagcurtain=1;return;}speak.say("抱歉,窗帘已经是关闭状态。");}else if(text == "打开QQ。"){speak.say("正在打开QQ。");p1->start("D:/tencent/QQ/Bin/QQScLauncher.exe");}else if(text == "打开QQ音乐。"){speak.say("正在打开QQ音乐。");p2->start("D:/tencent/qqmusic/QQMusic1869.21.17.39/QQMusic.exe");}else if(text.left(4)== "查询天气"){speak.say("正在查询。");ui->lineaddr->setText(text.mid(4,text.length()-5));}}else{ui->textEdit->setText("识别失败请重新按住说话!!!");}ui->btn_speekin->setText("按住说话");
}void Widget::on_wtobtn_clicked()
{if(6 == day){day = 0;ui->weathertext->setText(wt->processing_data(day));return;}day++;ui->weathertext->setText(wt->processing_data(day));
}void Widget::on_wyesbtn_clicked()
{if(0 == day){day = 6;ui->weathertext->setText(wt->processing_data(day));return;}day--;ui->weathertext->setText(wt->processing_data(day));
}
ui界面:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>Widget</class><widget class="QWidget" name="Widget"><property name="enabled"><bool>true</bool></property><property name="geometry"><rect><x>0</x><y>0</y><width>1000</width><height>600</height></rect></property><property name="acceptDrops"><bool>false</bool></property><property name="windowTitle"><string>语音智能家居系统</string></property><property name="windowIcon"><iconset resource="11.qrc"><normaloff>:/new/prefix1/feng0.1.png</normaloff>:/new/prefix1/feng0.1.png</iconset></property><property name="layoutDirection"><enum>Qt::LeftToRight</enum></property><property name="autoFillBackground"><bool>false</bool></property><property name="styleSheet"><string notr="true"/></property><widget class="QPushButton" name="pushButton"><property name="geometry"><rect><x>80</x><y>570</y><width>71</width><height>30</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{border:none;background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(139, 17, 161, 96), stop:1 rgba(85, 255, 255, 255));border-bottom-right-radius: 15px;color:rgb(246, 217, 255);
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);color: rgb(255, 255, 255);font: 12pt "楷体";
}</string></property><property name="text"><string>断开服务器</string></property></widget><widget class="QPushButton" name="pushButton_2"><property name="geometry"><rect><x>601</x><y>159</y><width>60</width><height>40</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="layoutDirection"><enum>Qt::LeftToRight</enum></property><property name="styleSheet"><string notr="true">QPushButton{
border:none;
border-radius: 25px;
color: rgb(255, 231, 254);
}
QPushButton:hover{
border:none;font: 25 11pt "微软雅黑 Light";text-decoration: underline;}</string></property><property name="text"><string>
灯关</string></property></widget><widget class="QPushButton" name="pushButton_3"><property name="geometry"><rect><x>360</x><y>540</y><width>75</width><height>61</height></rect></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{
border-style:none;
background-color: rgb(185, 255, 184);
border-top-right-radius:15px;
}
QPushButton:hover{
border-style:none;
background-color: rgb(0, 255, 184);
border-top-right-radius:30px;
}
QPushButton:pressed{
border-style:none;background-color: rgb(111, 255, 246);
border-top-right-radius:30px;
}
</string></property><property name="text"><string>发送</string></property><property name="autoDefault"><bool>false</bool></property><property name="default"><bool>false</bool></property><property name="flat"><bool>true</bool></property></widget><widget class="QPushButton" name="pushButton_4"><property name="geometry"><rect><x>9</x><y>570</y><width>71</width><height>31</height></rect></property><property name="sizePolicy"><sizepolicy hsizetype="Fixed" vsizetype="Fixed"><horstretch>0</horstretch><verstretch>0</verstretch></sizepolicy></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{border:none;background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(229, 221, 191, 255), stop:1 rgba(85, 229, 232, 107));border-bottom-left-radius: 15px;color: rgb(131, 74, 18);
}
QPushButton:hover
{border:none;border-radius:15px;
background-color: rgb(226, 119, 105);font: 14pt "楷体";
}</string></property><property name="text"><string>连接服务器</string></property></widget><widget class="QTextEdit" name="textEdit"><property name="geometry"><rect><x>160</x><y>540</y><width>201</width><height>61</height></rect></property><property name="font"><font><family>华文仿宋</family><pointsize>20</pointsize><weight>50</weight><italic>false</italic><bold>false</bold></font></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.5);
font: 20pt "隶书";
font: 20pt "华文仿宋";
color: rgb(255, 0, 0);</string></property><property name="html"><string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'华文仿宋'; font-size:20pt; font-weight:400; font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string></property></widget><widget class="QWidget" name="horizontalLayoutWidget"><property name="geometry"><rect><x>0</x><y>430</y><width>211</width><height>30</height></rect></property><layout class="QHBoxLayout" name="horizontalLayout"><property name="topMargin"><number>0</number></property><property name="rightMargin"><number>6</number></property><item><widget class="QLineEdit" name="lineEdit"><property name="font"><font><family>微软雅黑 Light</family><pointsize>10</pointsize><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.11);
color: rgb(0, 255, 127);</string></property><property name="text"><string>192.168.2.45</string></property></widget></item><item><widget class="QLabel" name="label"><property name="styleSheet"><string notr="true">font: 11pt "黑体";
color: rgb(0, 255, 238);</string></property><property name="text"><string>ip地址</string></property></widget></item></layout></widget><widget class="QWidget" name="horizontalLayoutWidget_3"><property name="geometry"><rect><x>0</x><y>490</y><width>211</width><height>27</height></rect></property><layout class="QHBoxLayout" name="horizontalLayout_3"><item><widget class="QLineEdit" name="lineEdit_2"><property name="font"><font><pointsize>11</pointsize><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.11);
color: rgb(0, 255, 127);</string></property><property name="text"><string>7777</string></property></widget></item><item><widget class="QLabel" name="label_2"><property name="styleSheet"><string notr="true">font: 11pt "黑体";color: rgb(0, 255, 238);</string></property><property name="text"><string>服务器端口</string></property></widget></item></layout></widget><widget class="QWidget" name="horizontalLayoutWidget_4"><property name="geometry"><rect><x>0</x><y>460</y><width>211</width><height>25</height></rect></property><layout class="QHBoxLayout" name="horizontalLayout_4"><property name="topMargin"><number>0</number></property><item><widget class="QLineEdit" name="lineEdit_3"><property name="font"><font><pointsize>11</pointsize><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.11);
color: rgb(0, 255, 127);</string></property><property name="text"><string>8888</string></property></widget></item><item><widget class="QLabel" name="label_3"><property name="styleSheet"><string notr="true">font: 11pt "黑体";
color: rgb(0, 255, 238);</string></property><property name="text"><string>摄像头端口</string></property></widget></item></layout></widget><widget class="QLineEdit" name="lineEdit_wd"><property name="geometry"><rect><x>0</x><y>0</y><width>31</width><height>20</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><pointsize>12</pointsize><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.11);
color: rgb(170, 85, 255);</string></property><property name="text"><string/></property><property name="readOnly"><bool>true</bool></property></widget><widget class="QLineEdit" name="lineEdit_sd"><property name="geometry"><rect><x>0</x><y>20</y><width>31</width><height>20</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><pointsize>12</pointsize><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.11);
color: rgb(170, 85, 255);</string></property><property name="text"><string/></property><property name="readOnly"><bool>true</bool></property></widget><widget class="QLineEdit" name="lineEdit_gq"><property name="geometry"><rect><x>0</x><y>40</y><width>51</width><height>20</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><pointsize>10</pointsize><weight>75</weight><italic>false</italic><bold>true</bold><underline>false</underline><strikeout>false</strikeout><kerning>true</kerning></font></property><property name="cursor"><cursorShape>UpArrowCursor</cursorShape></property><property name="layoutDirection"><enum>Qt::RightToLeft</enum></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.11);
color: rgb(170, 85, 255);</string></property><property name="text"><string/></property><property name="readOnly"><bool>true</bool></property></widget><widget class="QLabel" name="label_4"><property name="geometry"><rect><x>610</x><y>250</y><width>151</width><height>181</height></rect></property><property name="maximumSize"><size><width>16777211</width><height>16777215</height></size></property><property name="layoutDirection"><enum>Qt::LeftToRight</enum></property><property name="styleSheet"><string notr="true">background-color: rgba(170, 75, 6,0.3);
color: rgb(252, 234, 255);
border-radius: 15px;</string></property><property name="text"><string><html><head/><body><p align="center"><span style=" font-weight:600;">摄像头画面</span></p><p align="center"><br/></p><p align="center"><br/></p><p align="center"><br/></p><p align="center"><br/></p><p align="center"><br/></p></body></html></string></property><property name="scaledContents"><bool>true</bool></property></widget><widget class="QLabel" name="label_5"><property name="geometry"><rect><x>0</x><y>0</y><width>1001</width><height>601</height></rect></property><property name="font"><font><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>ArrowCursor</cursorShape></property><property name="layoutDirection"><enum>Qt::RightToLeft</enum></property><property name="autoFillBackground"><bool>false</bool></property><property name="styleSheet"><string notr="true">border-image: url(:/new/prefix1/di1.JPG);</string></property><property name="text"><string/></property><property name="scaledContents"><bool>true</bool></property></widget><widget class="QPushButton" name="pushButton_6"><property name="geometry"><rect><x>330</x><y>370</y><width>111</width><height>171</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><pointsize>8</pointsize><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="layoutDirection"><enum>Qt::LeftToRight</enum></property><property name="styleSheet"><string notr="true">QPushButton{
border-image: url(:/new/prefix1/feng0.1.png);
border:none;
color: rgb(255, 231, 254);
}
QPushButton:hover{
border-image: url(:/new/prefix1/feng0.2.png);
border:none;font: 25 11pt "微软雅黑 Light";text-decoration: underline;}</string></property><property name="text"><string>风扇 关</string></property></widget><widget class="QLabel" name="label_7"><property name="geometry"><rect><x>32</x><y>6</y><width>54</width><height>12</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">color: rgb(170, 255, 127);
color: rgb(0, 255, 127);</string></property><property name="text"><string>℃ 温度</string></property></widget><widget class="QLabel" name="label_8"><property name="geometry"><rect><x>36</x><y>24</y><width>54</width><height>12</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">color: rgb(0, 255, 127);</string></property><property name="text"><string>%rh 湿度</string></property></widget><widget class="QLabel" name="label_9"><property name="geometry"><rect><x>53</x><y>43</y><width>54</width><height>12</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">color: rgb(0, 255, 127);</string></property><property name="text"><string>lux 亮度</string></property></widget><widget class="QLabel" name="label_10"><property name="geometry"><rect><x>5</x><y>58</y><width>101</width><height>21</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><pointsize>10</pointsize><weight>75</weight><bold>true</bold></font></property><property name="styleSheet"><string notr="true">color: rgb(189, 92, 35);</string></property><property name="text"><string>室内环境属性</string></property></widget><widget class="QTextEdit" name="textEdit_2"><property name="geometry"><rect><x>600</x><y>240</y><width>171</width><height>201</height></rect></property><property name="maximumSize"><size><width>16777215</width><height>16777215</height></size></property><property name="styleSheet"><string notr="true">border-radius: 10px;
background-color: rgba(255, 255, 255,0.5);
div{
box-shaow:20px 20px #2600ff;
}</string></property><property name="readOnly"><bool>true</bool></property></widget><widget class="QPushButton" name="pushButton_5"><property name="geometry"><rect><x>650</x><y>220</y><width>75</width><height>23</height></rect></property><property name="font"><font><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton{
border:none;
border-radius: 25px;
color: rgb(223, 204, 223);
}
QPushButton:hover{
border:none;font: 25 11pt "微软雅黑 Light";text-decoration: underline;}</string></property><property name="text"><string>摄像缩放</string></property></widget><widget class="QPushButton" name="pushButton_7"><property name="geometry"><rect><x>80</x><y>540</y><width>71</width><height>30</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{border:none;background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(130, 198, 213, 62), stop:1 rgba(109, 202, 171, 255));border-top-right-radius: 15px;color: rgb(131, 74, 18);
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);font: 12pt "楷体";
}</string></property><property name="text"><string>断开摄像头</string></property></widget><widget class="QLabel" name="label_11"><property name="geometry"><rect><x>0</x><y>180</y><width>111</width><height>21</height></rect></property><property name="font"><font><family>华文琥珀</family></font></property><property name="styleSheet"><string notr="true">color: rgb(254, 122, 35);</string></property><property name="text"><string>摄像头信息</string></property></widget><widget class="QLabel" name="label_12"><property name="geometry"><rect><x>0</x><y>160</y><width>111</width><height>20</height></rect></property><property name="font"><font><family>华文琥珀</family></font></property><property name="styleSheet"><string notr="true">color: rgb(174, 42, 255);
</string></property><property name="text"><string>服务器信息</string></property></widget><widget class="QPushButton" name="pushButton_8"><property name="geometry"><rect><x>150</x><y>0</y><width>75</width><height>31</height></rect></property><property name="font"><font><family>华文琥珀</family></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{border:none; background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.489, fy:0.523, stop:0 rgba(205, 162, 255, 255), stop:1 rgba(255, 159, 187, 53));border-radius: 15px;;color: rgb(170, 0, 0);
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);font: 12pt "楷体";
}</string></property><property name="text"><string>窗帘 关闭</string></property></widget><widget class="QPushButton" name="pushButton_9"><property name="geometry"><rect><x>9</x><y>540</y><width>71</width><height>31</height></rect></property><property name="font"><font><family>微软雅黑 Light</family><weight>75</weight><bold>true</bold></font></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{border:none;color:rgb(246, 217, 255);background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(216, 134, 137, 161), stop:1 rgba(214, 213, 255, 125));border-top-left-radius: 15px;;
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);color: rgb(255, 255, 255);font: 12pt "楷体";
}</string></property><property name="text"><string>连接摄像头</string></property></widget><widget class="QLabel" name="label_6"><property name="geometry"><rect><x>857</x><y>224</y><width>100</width><height>211</height></rect></property><property name="font"><font><family>Arial Narrow</family><pointsize>13</pointsize></font></property><property name="styleSheet"><string notr="true">border-image: url(:/ds2.png);</string></property><property name="text"><string/></property></widget><widget class="QPushButton" name="pushButton_10"><property name="geometry"><rect><x>800</x><y>570</y><width>75</width><height>31</height></rect></property><property name="cursor"><cursorShape>PointingHandCursor</cursorShape></property><property name="styleSheet"><string notr="true">QPushButton
{border:none; background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.489, fy:0.523, stop:0 rgba(255, 209, 162, 255), stop:1 rgba(255, 159, 187, 53));border-radius: 15px;;color: rgb(170, 0, 0);font: 75 9pt "Agency FB";
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);font: 12pt "楷体";
}</string></property><property name="text"><string>电视开关</string></property></widget><widget class="QWidget" name="verticalLayoutWidget"><property name="geometry"><rect><x>0</x><y>280</y><width>311</width><height>151</height></rect></property><layout class="QVBoxLayout" name="verticalLayout"><item><layout class="QHBoxLayout" name="horizontalLayout_5"><item><widget class="QPushButton" name="wyesbtn"><property name="font"><font><family>华文琥珀</family><pointsize>9</pointsize><weight>50</weight><italic>false</italic><bold>false</bold></font></property><property name="styleSheet"><string notr="true">QPushButton
{border:none;font: 9pt "华文琥珀";background-color: rgb(0, 255, 226);border-radius: 30px;color: rgb(131, 74, 18);
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);font: 12pt "楷体";
}</string></property><property name="text"><string>前一天</string></property></widget></item><item><widget class="QLineEdit" name="lineaddr"><property name="sizePolicy"><sizepolicy hsizetype="Preferred" vsizetype="Fixed"><horstretch>0</horstretch><verstretch>0</verstretch></sizepolicy></property><property name="layoutDirection"><enum>Qt::LeftToRight</enum></property><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.60);
font: 75 12pt "Agency FB";
color: rgb(222, 125, 93);</string></property><property name="text"><string>成都</string></property><property name="alignment"><set>Qt::AlignCenter</set></property></widget></item><item><widget class="QPushButton" name="wtobtn"><property name="styleSheet"><string notr="true">QPushButton
{border:none;font: 9pt "华文琥珀";background-color: rgb(0, 255, 226);border-radius: 30px;color: rgb(131, 74, 18);
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);font: 12pt "楷体";
}</string></property><property name="text"><string>下一天</string></property></widget></item></layout></item><item><widget class="QTextEdit" name="weathertext"><property name="styleSheet"><string notr="true">background-color: rgba(255, 255, 255,0.60);
color: rgb(0, 153, 255);
font: 75 10pt "Agency FB";</string></property><property name="html"><string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Agency FB'; font-size:10pt; font-weight:72; font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;"><br /></p></body></html></string></property></widget></item></layout></widget><widget class="QPushButton" name="btn_speekin"><property name="geometry"><rect><x>570</x><y>540</y><width>60</width><height>60</height></rect></property><property name="styleSheet"><string notr="true">QPushButton
{border:none;font: 9pt "华文琥珀";background-color: rgb(0, 255, 226);border-radius: 30px;color: rgb(131, 74, 18);
}
QPushButton:hover
{border:none;border-radius:15px; background-color: rgb(226, 119, 105);font: 12pt "楷体";
}</string></property><property name="text"><string>按下说话</string></property></widget><zorder>label_5</zorder><zorder>label_6</zorder><zorder>pushButton</zorder><zorder>pushButton_2</zorder><zorder>pushButton_3</zorder><zorder>pushButton_4</zorder><zorder>textEdit</zorder><zorder>horizontalLayoutWidget</zorder><zorder>horizontalLayoutWidget_3</zorder><zorder>horizontalLayoutWidget_4</zorder><zorder>lineEdit_wd</zorder><zorder>lineEdit_sd</zorder><zorder>lineEdit_gq</zorder><zorder>pushButton_6</zorder><zorder>label_7</zorder><zorder>label_8</zorder><zorder>label_9</zorder><zorder>label_10</zorder><zorder>textEdit_2</zorder><zorder>label_4</zorder><zorder>pushButton_5</zorder><zorder>pushButton_7</zorder><zorder>label_11</zorder><zorder>label_12</zorder><zorder>pushButton_8</zorder><zorder>pushButton_9</zorder><zorder>pushButton_10</zorder><zorder>verticalLayoutWidget</zorder><zorder>btn_speekin</zorder></widget><layoutdefault spacing="6" margin="11"/><resources><include location="11.qrc"/></resources><connections/>
</ui>
演示:
语音控制系统