-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (54 loc) · 1.67 KB
/
main.py
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
# coding: utf-8
from gui import *
import thread
import color
import time
import os
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import YaoSpeech
from dialogue import *
class dialogue_thread(QThread):
def __init__(self):
QThread.__init__(self)
self.voiceface = VoiceInterface()
self.voiceface.hear_display = self.display
self.voiceface.hear_voice = self.talk
self.dialogue = DialogueManager(self.voiceface, DialogueModelTagging())
def run(self):
self.dialogue.run()
return None
def listen(self):
YaoSpeech.listen()
print "YaoSpeech: listening..."
def recognize(self):
result = YaoSpeech.recognize()
if result == None or result == '':
return
result = result.decode('utf-8')
print "speech recognized: ", result
self.emit(QtCore.SIGNAL('display(QString, QString)'), u'Human: '+result, '#bb2244')
self.voiceface.addMessage(result)
print "YaoSpeech: recognizing..."
def display(self, msg):
self.emit(QtCore.SIGNAL('display(QString, QString)'), u'Machine: '+msg, '#00aa00')
def talk(self, msg):
msg = msg.replace(u'\'', u'\\\'')
msg = msg.replace(u'\n', u'\\\n')
msg = msg.replace(u'\t', u'\n')
print msg
YaoSpeech.speak((u'\"'+msg+u'\"').encode('utf-8'))
def main():
app = QtGui.QApplication(sys.argv)
gui = GUI()
thread = QThread()
dialogue = dialogue_thread()
gui.connect(dialogue, QtCore.SIGNAL("display(QString, QString)"), gui.display)
dialogue.connect(gui, QtCore.SIGNAL('listen()'), dialogue.listen)
dialogue.connect(gui, QtCore.SIGNAL('recognize()'), dialogue.recognize)
dialogue.start()
sys.exit(app.exec_())
if __name__ == '__main__':
main()