-
Notifications
You must be signed in to change notification settings - Fork 360
/
VoicePrintClient.cpp
158 lines (141 loc) · 3.43 KB
/
VoicePrintClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "VoicePrintClient.h"
#include <QDebug>
VoicePrintClient::VoicePrintClient(QObject *parent)
: LocalNode(parent)
{
}
void VoicePrintClient::appendFile(const QStringList &filelist)
{
QByteArray data;
QDataStream stream(&data, QIODevice::ReadWrite);
stream<<filelist;
sendData(LMEType::Feature, LMEFeature::AppendFile, data);
}
void VoicePrintClient::editFile(const QString &filepath)
{
QByteArray data;
QDataStream stream(&data, QIODevice::ReadWrite);
stream<<filepath;
sendData(LMEType::Feature, LMEFeature::EditFile, data);
}
void VoicePrintClient::removeFile(const QStringList &filelist)
{
QByteArray data;
QDataStream stream(&data, QIODevice::ReadWrite);
stream<<filelist;
sendData(LMEType::Feature, LMEFeature::RemoveFile, data);
}
void VoicePrintClient::requestExtractProgress()
{
sendData(LMEType::Feature, LMEFeature::RequestProgress, QByteArray());
}
void VoicePrintClient::compareRun(const QStringList &materials, const QStringList &samples, int algorithm)
{
QByteArray data;
QDataStream stream(&data, QIODevice::ReadWrite);
stream<<materials<<samples<<algorithm;
//比对请求
if(!sendData(LMEType::Compare, LMETask::Request, data)){
emit errorChanged();
}
}
void VoicePrintClient::compareStop()
{
qDebug()<<"compare stop";
//断开连接
nodeAbort();
}
void VoicePrintClient::clusterRun(const QStringList &filelist, int taskId)
{
QByteArray data;
QDataStream stream(&data, QIODevice::ReadWrite);
stream<<filelist<<taskId;
//聚类请求
if(!sendData(LMEType::Cluster, LMETask::Request, data)){
emit errorChanged();
}
}
void VoicePrintClient::clusterStop()
{
qDebug()<<"cluster stop";
//断开连接
nodeAbort();
}
void VoicePrintClient::init()
{
nodeInit(VoicePrint_Server);
}
void VoicePrintClient::free()
{
nodeFree();
}
void VoicePrintClient::netConnected()
{
LocalNode::netConnected();
qDebug()<<"voice print socket connected.";
}
void VoicePrintClient::netDisconnected()
{
LocalNode::netDisconnected();
emit errorChanged();
qDebug()<<"voice print socket disconnected.";
}
void VoicePrintClient::recvData(quint8 major, quint8 minor, const QByteArray &data)
{
QDataStream stream(data);
switch(major) {
case LMEType::Feature: //特征提取
{
switch (minor) {
case LMEFeature::ExtractProgress:
{
int extract,unextract;
stream>>extract>>unextract;
emit extractProgressChanged(extract,unextract);
}
break;
}
}
break;
case LMEType::Compare: //比对
{
switch (minor) {
case LMETask::Response:
{
bool ret;
stream>>ret;
emit compareFinished(ret);
}
break;
case LMETask::Progress:
{
int progress;
stream>>progress;
emit compareProgressChanged(progress);
}
break;
}
}
break;
case LMEType::Cluster: //聚类
{
switch (minor) {
case LMETask::Response:
{
bool ret;
stream>>ret;
emit clusterFinished(ret);
}
break;
case LMETask::Progress:
{
int progress;
stream>>progress;
emit clusterProgressChanged(progress);
}
break;
}
}
break;
}
}