-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
198 lines (166 loc) · 5.66 KB
/
mainwindow.cpp
File metadata and controls
198 lines (166 loc) · 5.66 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright 2014 Gwennael Gate.
//
// Author: Gwennael Gate (gwennaelgate@gmail.com)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
// Simplistic QT user interface to select the 2 utterances features files and
// to trigger the computation of the match (dtw) and the corresponding displays.
#include "mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget * parent) : QWidget(parent)
{
fLayout = new QGridLayout;
fUtt1Selection = new QPushButton("Select Utt1", this);
fUtt2Selection = new QPushButton("Select Utt2", this);
fUtt1Line = new QLineEdit();
fUtt2Line = new QLineEdit();
fDtwWindow = new QPushButton("Display Dtw", this);
fMfccWindow = new QPushButton("Display Mfccs", this);
fLayout->addWidget(fUtt1Selection, 0, 0);
fLayout->addWidget(fUtt1Line, 0, 1);
fLayout->addWidget(fUtt2Selection, 1, 0);
fLayout->addWidget(fUtt2Line, 1, 1);
fLayout->addWidget(fDtwWindow, 2, 0);
fLayout->addWidget(fMfccWindow, 2, 1);
connect(fDtwWindow,
SIGNAL(clicked()),
this,
SLOT(displayDtwPlotWindow()));
connect(fMfccWindow,
SIGNAL(clicked()),
this,
SLOT(displayMfccPlotWindow()));
connect(fUtt1Selection,
SIGNAL(clicked()),
this,
SLOT(getPathUtt1()));
connect(fUtt2Selection,
SIGNAL(clicked()),
this,
SLOT(getPathUtt2()));
connect(fUtt1Line,
SIGNAL(textChanged(QString)),
this,
SLOT(dtwToBeRecomputed()));
connect(fUtt2Line,
SIGNAL(textChanged(QString)),
this,
SLOT(dtwToBeRecomputed()));
setLayout(fLayout);
resize(800,800);
fIsDtwComputed = false;
show();
}
MainWindow::~MainWindow()
{
delete fPlotDTW;
delete fMfccWin;
delete fMfccPlot;
delete fUtt1Line;
delete fUtt2Line;
delete fLayout;
delete fUtt1Selection;
delete fUtt2Selection;
delete fDtwWindow;
delete fMfccWindow;
delete fLayout2;
delete fLabel;
delete fLabelSuccess;
delete fCombo;
}
void MainWindow::getPathUtt1()
{
QString path;
path = QFileDialog::getOpenFileName(this,
tr("Please choose utt1 features file"),
QDir::homePath());
fUtt1Line->setText(path);
fIsDtwComputed = false;
}
void MainWindow::getPathUtt2()
{
QString path;
path = QFileDialog::getOpenFileName(this,
tr("Please choose utt2 features file"),
QDir::homePath());
fUtt2Line->setText(path);
fIsDtwComputed = false;
}
void MainWindow::dtwToBeRecomputed()
{
fIsDtwComputed = false;
}
void MainWindow::displayDtwPlotWindow()
{
if(!fIsDtwComputed)
{
float score;
fComparator.compareUtterances(fUtt1Line->text().toStdString(),
fUtt2Line->text().toStdString(),
fUtt1,
fUtt2,
fPath,
fDtw,
score);
std::cout << "Similarity = " << score/fPath.size() << std::endl;
fIsDtwComputed = true;
}
fPlotDTW = new DtwPlot(&fDtw, &fPath);
fPlotDTW->resize(800,800);
fPlotDTW->show();
}
void MainWindow::displayMfccPlotWindow()
{
if(!fIsDtwComputed)
{
float score;
fComparator.compareUtterances(fUtt1Line->text().toStdString(),
fUtt2Line->text().toStdString(),
fUtt1,
fUtt2,
fPath,
fDtw,
score);
fResult = score/fPath.size();
std::cout << "Similarity = " << fResult << std::endl;
fIsDtwComputed = true;
}
std::cout << "value " << fUtt1.size1() << std::endl;
fMfccPlot = new MfccPlot(&fUtt1, &fUtt2, &fPath, &fDtw);
fMfccWin = new QWidget;
fLayout2 = new QGridLayout;
QString value = QString::number(fResult);
fLabel = new QLabel("Similarity Score = " + value);
fLabelSuccess = new QLabel();
fCombo = new QComboBox();
if(fResult < 1500)
fLabelSuccess->setText("Utterances are similar");
else
fLabelSuccess->setText("Utterances are different");
for(unsigned int k = 0 ; k < fUtt1.size2() ; k++)
{
fCombo->addItem(QString("Mfcc ") + QString::number(k));
}
QObject::connect(fCombo,
SIGNAL(activated(int)),
fMfccPlot,
SLOT(setIndex(int)));
fLayout2->addWidget(fLabel, 0, 0);
fLayout2->addWidget(fLabelSuccess, 0, 1);
fLayout2->addWidget(fCombo, 0, 2);
fLayout2->addWidget(fMfccPlot, 1, 0, 1, 3);
fMfccWin->setLayout(fLayout2);
fMfccWin->resize(1500,800);
fMfccWin->show();
}