hlrc / server / tools / hlrc_test_gui.py @ 62d50515
History | View | Annotate | Download (8.108 KB)
1 |
#!/usr/bin/python
|
---|---|
2 |
import sys |
3 |
import os.path |
4 |
from PyQt4 import QtGui, QtCore |
5 |
from PyQt4.QtCore import SIGNAL |
6 |
from hlrc_speak_utterance import hlrc_utterance |
7 |
from hlrc_play_animation import hlrc_animation |
8 |
from hlrc_set_emotion import hlrc_emotion |
9 |
|
10 |
class Example(QtGui.QWidget): |
11 |
|
12 |
def __init__(self, _scope): |
13 |
super(Example, self).__init__() |
14 |
self.scope = _scope
|
15 |
self.initUI()
|
16 |
scope = self.scope_lineedit.text()
|
17 |
self.hlrc_utterance = hlrc_utterance(scope)
|
18 |
self.hlrc_animation = hlrc_animation(scope)
|
19 |
self.hlrc_emotion = hlrc_emotion(scope)
|
20 |
|
21 |
def scopeChanged(self): |
22 |
self.scope = self.scope_lineedit.text() |
23 |
print "> changed scope to %s" % self.scope |
24 |
self.hlrc_utterance.set_scope(self.scope) |
25 |
self.hlrc_animation.set_scope(self.scope) |
26 |
self.hlrc_emotion.set_scope(self.scope) |
27 |
|
28 |
def initUtteranceUI(self): |
29 |
groupBox = QtGui.QGroupBox("utterances")
|
30 |
|
31 |
hello = QtGui.QPushButton("hello...")
|
32 |
hello.clicked.connect(self.utterance_button_clicked)
|
33 |
|
34 |
count = QtGui.QPushButton("12345...")
|
35 |
count.clicked.connect(self.utterance_button_clicked)
|
36 |
|
37 |
|
38 |
vbox = QtGui.QVBoxLayout() |
39 |
vbox.addWidget(hello) |
40 |
vbox.addWidget(count) |
41 |
vbox.addStretch(1)
|
42 |
groupBox.setLayout(vbox) |
43 |
|
44 |
return groupBox
|
45 |
|
46 |
def initSpinbox(self, _min, _max, _init, double): |
47 |
if (double):
|
48 |
s = QtGui.QDoubleSpinBox() |
49 |
else:
|
50 |
s = QtGui.QSpinBox() |
51 |
|
52 |
s.setMinimum(_min) |
53 |
s.setMaximum(_max) |
54 |
s.setValue(_init) |
55 |
return s
|
56 |
|
57 |
def initEmotionUI(self): |
58 |
groupBox = QtGui.QGroupBox("emotion")
|
59 |
neutral = QtGui.QPushButton("neutral")
|
60 |
neutral.clicked.connect(self.emotion_button_clicked)
|
61 |
surprised = QtGui.QPushButton("surprise")
|
62 |
surprised.clicked.connect(self.emotion_button_clicked)
|
63 |
angry = QtGui.QPushButton("angry")
|
64 |
angry.clicked.connect(self.emotion_button_clicked)
|
65 |
happy = QtGui.QPushButton("happy")
|
66 |
happy.clicked.connect(self.emotion_button_clicked)
|
67 |
sad = QtGui.QPushButton("sad")
|
68 |
sad.clicked.connect(self.emotion_button_clicked)
|
69 |
fear = QtGui.QPushButton("fear")
|
70 |
fear.clicked.connect(self.emotion_button_clicked)
|
71 |
|
72 |
self.duration_spinbox = self.initSpinbox(100, 10000, 1000, 0) |
73 |
|
74 |
vbox = QtGui.QVBoxLayout() |
75 |
vbox.addWidget(self.duration_spinbox)
|
76 |
vbox.addWidget(neutral) |
77 |
vbox.addWidget(surprised) |
78 |
vbox.addWidget(angry) |
79 |
vbox.addWidget(happy) |
80 |
vbox.addWidget(sad) |
81 |
vbox.addWidget(fear) |
82 |
vbox.addStretch(1)
|
83 |
groupBox.setLayout(vbox) |
84 |
return groupBox
|
85 |
|
86 |
|
87 |
def initAnimationButton(self, name): |
88 |
b = QtGui.QPushButton(name) |
89 |
b.clicked.connect(self.animation_button_clicked)
|
90 |
return b
|
91 |
|
92 |
def initAnimUI(self): |
93 |
groupBox = QtGui.QGroupBox("animations")
|
94 |
|
95 |
#options
|
96 |
options = QtGui.QHBoxLayout() |
97 |
vbox_r = QtGui.QVBoxLayout() |
98 |
vbox_r.addWidget(QtGui.QLabel("repetitions"))
|
99 |
self.repetitions_spinbox = self.initSpinbox(1,10,1,0) |
100 |
vbox_r.addWidget(self.repetitions_spinbox)
|
101 |
|
102 |
vbox_d = QtGui.QVBoxLayout() |
103 |
vbox_d.addWidget(QtGui.QLabel("duration/ms (each)"))
|
104 |
self.duration_each_spinbox = self.initSpinbox(100,10000,1000,0) |
105 |
vbox_d.addWidget(self.duration_each_spinbox)
|
106 |
|
107 |
vbox_s = QtGui.QVBoxLayout() |
108 |
vbox_s.addWidget(QtGui.QLabel("scale"))
|
109 |
self.scale_spinbox = self.initSpinbox(0.1, 5.0, 1.0, 1) |
110 |
vbox_s.addWidget(self.scale_spinbox)
|
111 |
|
112 |
|
113 |
options.addLayout(vbox_r) |
114 |
options.addLayout(vbox_d) |
115 |
options.addLayout(vbox_s) |
116 |
|
117 |
#buttons
|
118 |
vbox = QtGui.QVBoxLayout() |
119 |
vbox.addLayout(options) |
120 |
vbox.addWidget(self.initAnimationButton("head shake")) |
121 |
vbox.addWidget(self.initAnimationButton("head nod")) |
122 |
vbox.addWidget(self.initAnimationButton("eyeblink left")) |
123 |
vbox.addWidget(self.initAnimationButton("eyeblink right")) |
124 |
vbox.addWidget(self.initAnimationButton("eyeblink both")) |
125 |
vbox.addWidget(self.initAnimationButton("eyebrows raise")) |
126 |
vbox.addWidget(self.initAnimationButton("eyebrows lower")) |
127 |
vbox.addStretch(1)
|
128 |
groupBox.setLayout(vbox) |
129 |
|
130 |
return groupBox
|
131 |
|
132 |
def initUI(self): |
133 |
|
134 |
self.scope_lineedit = QtGui.QLineEdit(self.scope); |
135 |
self.connect(self.scope_lineedit, SIGNAL("editingFinished()"),self.scopeChanged) |
136 |
|
137 |
vbox = QtGui.QVBoxLayout(); |
138 |
|
139 |
hboxl = QtGui.QHBoxLayout(); |
140 |
hboxl.addWidget(QtGui.QLabel("base scope: "));
|
141 |
hboxl.addWidget(self.scope_lineedit);
|
142 |
vbox.addLayout(hboxl); |
143 |
|
144 |
hbox = QtGui.QHBoxLayout() |
145 |
vbox.addLayout(hbox); |
146 |
|
147 |
#emotion
|
148 |
hbox.addWidget(self.initEmotionUI())
|
149 |
|
150 |
#utterance:
|
151 |
hbox.addWidget(self.initUtteranceUI())
|
152 |
|
153 |
#animations:
|
154 |
hbox.addWidget(self.initAnimUI())
|
155 |
|
156 |
self.setLayout(vbox)
|
157 |
#sld.valueChanged.connect(lcd.display)
|
158 |
|
159 |
self.setGeometry(400, 100, 250, 150) |
160 |
self.setWindowTitle("HLC Server test GUI") |
161 |
self.show()
|
162 |
|
163 |
def utterance_button_clicked(self): |
164 |
button = self.sender().text()
|
165 |
|
166 |
fn_praat = "b.praat"
|
167 |
fn_wav = "b.wav"
|
168 |
|
169 |
if (button == "12345..."): |
170 |
print("123")
|
171 |
fn_praat = "1234.praat"
|
172 |
fn_wav = "1234.wav"
|
173 |
|
174 |
elif (button == "hello..."): |
175 |
print "hello" |
176 |
fn_praat = "hello_my_name.praat"
|
177 |
fn_wav = "hello_my_name.wav"
|
178 |
|
179 |
else:
|
180 |
print "invalid button '%s'" % (button) |
181 |
return
|
182 |
|
183 |
#try to find the wav/praat files:
|
184 |
path = os.path.dirname(os.path.realpath(__file__)) + "/../share/hlrc_server/examples/"
|
185 |
if (not os.path.isfile(path + fn_wav)): |
186 |
#try fallback solution for running from current folder:
|
187 |
path = "examples/"
|
188 |
|
189 |
self.hlrc_utterance.trigger_utterance(path + fn_praat, path + fn_wav, 0) |
190 |
|
191 |
def emotion_button_clicked(self): |
192 |
button = self.sender().text()
|
193 |
duration = self.duration_spinbox.value()
|
194 |
|
195 |
|
196 |
if (button == "angry"): |
197 |
self.hlrc_emotion.set_emotion(3, duration, 0) |
198 |
elif (button == "neutral"): |
199 |
self.hlrc_emotion.set_emotion(0, duration, 0) |
200 |
elif (button == "happy"): |
201 |
self.hlrc_emotion.set_emotion(1, duration, 0) |
202 |
elif (button == "sad"): |
203 |
self.hlrc_emotion.set_emotion(2, duration, 0) |
204 |
elif (button == "surprise"): |
205 |
self.hlrc_emotion.set_emotion(4, duration, 0) |
206 |
elif (button == "fear"): |
207 |
self.hlrc_emotion.set_emotion(5, duration, 0) |
208 |
else:
|
209 |
print "invalid emotion id '%s'" % (button) |
210 |
return
|
211 |
|
212 |
def animation_button_clicked(self): |
213 |
button = self.sender().text()
|
214 |
|
215 |
repetitions = self.repetitions_spinbox.value()
|
216 |
duration_each = self.duration_each_spinbox.value()
|
217 |
scale = self.scale_spinbox.value()
|
218 |
|
219 |
if (button == "head nod"): |
220 |
self.hlrc_animation.trigger_animation(1, repetitions, duration_each, scale, 0) |
221 |
elif (button == "head shake"): |
222 |
self.hlrc_animation.trigger_animation(2, repetitions, duration_each, scale, 0) |
223 |
elif (button == "eyeblink left"): |
224 |
self.hlrc_animation.trigger_animation(3, repetitions, duration_each, scale, 0) |
225 |
elif (button == "eyeblink right"): |
226 |
self.hlrc_animation.trigger_animation(4, repetitions, duration_each, scale, 0) |
227 |
elif (button == "eyeblink both"): |
228 |
self.hlrc_animation.trigger_animation(5, repetitions, duration_each, scale, 0) |
229 |
elif (button == "eyebrows raise"): |
230 |
self.hlrc_animation.trigger_animation(6, repetitions, duration_each, scale, 0) |
231 |
elif (button == "eyebrows lower"): |
232 |
self.hlrc_animation.trigger_animation(7, repetitions, duration_each, scale, 0) |
233 |
else:
|
234 |
print "invalid button '%s'" % (button) |
235 |
return
|
236 |
|
237 |
def main(): |
238 |
scope = "/home/wardrobe/flobi"
|
239 |
if (len(sys.argv) == 2): |
240 |
scope = sys.argv[1]
|
241 |
|
242 |
app = QtGui.QApplication(sys.argv) |
243 |
ex = Example(scope) |
244 |
sys.exit(app.exec_()) |
245 |
|
246 |
|
247 |
if __name__ == '__main__': |
248 |
main() |