服务端(传说话的声音)
server.h
class Server:public QObject
{
Q_OBJECT
public:
Server();
~Server(){
delete input;
delete inputDevice;
}
private:
QTcpServer *server;
QTcpSocket *m_socket;
QAudioSource *input;
QIODevice *inputDevice;
public slots:
void readySend();
};
server.cpp
Server::Server()
:server(new QTcpServer)
,m_socket(new QTcpSocket)
{
server->listen(QHostAddress::Any,8888);
connect(server,&QTcpServer::newConnection,m_socket,
[=](){m_socket = server->nextPendingConnection();qDebug()<<"lianle";});
QAudioFormat format;
format.setSampleRate(44100);//采样率
format.setChannelCount(2);//声道
format.setSampleFormat(QAudioFormat::Int16);//采样精度
input = new QAudioSource(format,this);//采用格式
inputDevice=input->start();//采集声音
QObject::connect(inputDevice,&QIODevice::readyRead,this,&Server::readySe

最低0.47元/天 解锁文章
2406





