-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubtitlegui.cpp
More file actions
171 lines (159 loc) · 6.89 KB
/
subtitlegui.cpp
File metadata and controls
171 lines (159 loc) · 6.89 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
#include "stdafx.h"
#include "subtitlegui.h"
#include "AzureSpeechAPI.h"
SubtitleGUI::SubtitleGUI(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
this->setWindowTitle("SubGen");
/*
ui.historyButton->setIcon(QIcon("icon/speech-to-text-icon.png"));
ui.historyButton->setToolTip("History");*/
ui.settingButton->setIcon(QIcon("icon/setting-icon.png"));
ui.settingButton->setToolTip("Setting");
ui.startButton->setText("");
ui.startButton->setIcon(QIcon("icon/shutdown-icon.png"));
QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
effect->setColor(QColor(0, 0, 0, 255 * 0.3));
effect->setBlurRadius(5);
effect->setOffset(0);
ui.startButton->setGraphicsEffect(effect);
AzureSpeechAPI* speech = AzureSpeechAPI::getInstance();
bool engineMode;
if (speech->getEngineMode() == 1) {
ui.modeSwitch->setText("Translation Mode");
engineMode = true;
}
else {
ui.modeSwitch->setText("Recognition Mode");
engineMode = false;
}
ui.modeSwitch->setChecked(engineMode);
}
SubtitleGUI::~SubtitleGUI()
{}
void SubtitleGUI::on_historyButton_clicked() {
recordPage = new historyPage();
recordPage->show();
}
void SubtitleGUI::on_settingButton_clicked() {
if (settingPage == nullptr) {
settingPage = new SettingClass();
connect(settingPage, SIGNAL(updateAPIConfig(std::string, std::string, std::string, std::string, bool, int, bool))
, this, SLOT(saveNewAPIConfig(std::string, std::string, std::string, std::string, bool, int, bool)));
}
settingPage->show();
}
void SubtitleGUI::stop_recognition() {
textUpdater->close();
}
void SubtitleGUI::saveNewAPIConfig(std::string key, std::string region, std::string recognitionLanguage, std::string translationLanguage, bool recordState, int engineMode, bool showSingleLanguage) {
bool mode;
if (engineMode == 1) {
ui.modeSwitch->setText("Translation Mode");
mode = true;
}
else {
ui.modeSwitch->setText("Recognition Mode");
mode = false;
}
ui.modeSwitch->setChecked(mode);
textUpdater->saveConfig(key, region, recognitionLanguage, translationLanguage, recordState, engineMode, showSingleLanguage);
if (recognitionIsRunning) {
int rowNo = (engineMode == 0) ? 1 : 2;
if (rowNo == 2)rowNo = (showSingleLanguage) ? 1 : 2;
textOutput->updateLabel(rowNo);
textUpdater->close();
QThread* thread = new QThread;
textUpdater = new subtitleUpdater();
textUpdater->moveToThread(thread);
connect(textUpdater, SIGNAL(updateRecognition(QString)), textOutput, SLOT(setRecognition(QString)));
connect(textUpdater, SIGNAL(updateTranslation(QString)), textOutput, SLOT(setTranslation(QString)));
connect(thread, SIGNAL(started()), textUpdater, SLOT(process()));
connect(textUpdater, SIGNAL(finished()), thread, SLOT(quit()));
connect(textUpdater, SIGNAL(finished()), textUpdater, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
}
void SubtitleGUI::on_startButton_clicked() {
AzureSpeechAPI* speech = AzureSpeechAPI::getInstance();
if (speech->getKey() == "" || speech->getRegion()== "") {
QMessageBox::warning(this, "Speech Engine Error!", "Please set the azure speech services information in setting to continue.");
ui.startButton->setChecked(false);
return;
}
if (recognitionIsRunning) {
ui.startButton->setIcon(QIcon("icon/shutdown-icon.png"));
QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
effect->setColor(QColor(0, 0, 0, 255 * 0.3));
effect->setBlurRadius(5);
effect->setOffset(0);
ui.startButton->setGraphicsEffect(effect);
emit stop_recognition();
delete textOutput;
recognitionIsRunning = !recognitionIsRunning;
ui.languageInfoLabel->setText("Click the button to start recognition.");
return;
}
recognitionIsRunning = !recognitionIsRunning;
ui.startButton->setIcon(QIcon("icon/on-green.png"));
QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
effect->setColor(QColor(0, 0, 0, 255 * 0.4));
effect->setBlurRadius(20);
effect->setOffset(0);
ui.startButton->setGraphicsEffect(effect);
ui.languageInfoLabel->setText("Click the button to stop recognition.");
QSize size = qApp->screens()[0]->size();
int x = size.width() * 0.05;
int y = size.height() * 0.85;
int width = size.width() * 0.9;
int height = size.height() * 0.5;
int rowNo = (speech->getEngineMode() == 0) ? 1 : 2;
if (rowNo == 2)rowNo = (speech->getShowSingleLanguage()) ? 1 : 2;
textOutput = new displayText(rowNo);
textOutput->setGeometry(x, y, width, height);
textOutput->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
textOutput->setAttribute(Qt::WA_TranslucentBackground, true);
textOutput->show();
QThread* thread = new QThread;
textUpdater = new subtitleUpdater();
textUpdater->moveToThread(thread);
connect(textUpdater, SIGNAL(updateRecognition(QString)), textOutput, SLOT(setRecognition(QString)));
connect(textUpdater, SIGNAL(updateTranslation(QString)), textOutput, SLOT(setTranslation(QString)));
connect(thread, SIGNAL(started()), textUpdater, SLOT(process()));
connect(textUpdater, SIGNAL(finished()), thread, SLOT(quit()));
connect(textUpdater, SIGNAL(finished()), textUpdater, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
void SubtitleGUI::on_modeSwitch_clicked(bool state) {
int mode;
if (state) {
ui.modeSwitch->setText("Translation Mode");
mode = 1;
}
else {
ui.modeSwitch->setText("Recognition Mode");
mode = 0;
}
textUpdater->updateEngineMode(mode);
if (settingPage != nullptr)settingPage->updateEngineMode(mode);
if (recognitionIsRunning) {
AzureSpeechAPI* speech = AzureSpeechAPI::getInstance();
int rowNo = (mode == 0) ? 1 : 2;
if (rowNo == 2)rowNo = (speech->getShowSingleLanguage()) ? 1 : 2;
textOutput->updateLabel(rowNo);
textUpdater->close();
QThread* thread = new QThread;
textUpdater = new subtitleUpdater();
textUpdater->moveToThread(thread);
connect(textUpdater, SIGNAL(updateRecognition(QString)), textOutput, SLOT(setRecognition(QString)));
connect(textUpdater, SIGNAL(updateTranslation(QString)), textOutput, SLOT(setTranslation(QString)));
connect(thread, SIGNAL(started()), textUpdater, SLOT(process()));
connect(textUpdater, SIGNAL(finished()), thread, SLOT(quit()));
connect(textUpdater, SIGNAL(finished()), textUpdater, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
}