-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer.py
More file actions
120 lines (89 loc) · 2.84 KB
/
answer.py
File metadata and controls
120 lines (89 loc) · 2.84 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
# -*- encoding: UTF-8 -*-
""" Say 'hello, you' each time a human face is detected
"""
import sys
import time
from naoqi import ALProxy
from naoqi import ALBroker
from naoqi import ALModule
from optparse import OptionParser
NAO_IP = "localhost"
# Global variable to store the HumanGreeter module instance
HumanGreeter = None
memory = None
class HumanGreeterModule(ALModule):
""" A simple module able to react
to facedetection events
"""
def __init__(self, name):
ALModule.__init__(self, name)
# No need for IP and port here because
# we have our Python broker connected to NAOqi broker
self.tts = ALProxy("ALTextToSpeech")
print ("SONO NATOOOOOOO")
print "th:",self.tts.getASRConfidenceThreshold()
# Subscribe to the FaceDetected event:
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("Dialog/LastInput",
"HumanGreeter",
"onInput")
print("yeah!")
def onInput(self, *_args):
""" This will be called each time a face is
detected.
"""
print("Eccomi!!")
# Unsubscribe to the event when talking,
# to avoid repetitions
memory.unsubscribeToEvent("Dialog/LastInput",
"HumanGreeter")
self.tts.say("Hello, you")
for arg in _args:
print(arg)
value = memory.getData(arg)
print(value)
# Subscribe again to the event
memory.subscribeToEvent("Dialog/LastInput",
"HumanGreeter",
"onInput")
def main():
""" Main entry point
"""
parser = OptionParser()
parser.add_option("--pip",
help="Parent broker port. The IP address or your robot",
dest="pip")
parser.add_option("--pport",
help="Parent broker port. The port NAOqi is listening to",
dest="pport",
type="int")
parser.set_defaults(
pip=NAO_IP,
pport=10531)
(opts, args_) = parser.parse_args()
pip = opts.pip
pport = opts.pport
# We need this broker to be able to construct
# NAOqi modules and subscribe to other modules
# The broker must stay alive until the program exists
myBroker = ALBroker("myBroker",
"0.0.0.0", # listen to anyone
0, # find a free port and use it
pip, # parent broker IP
pport) # parent broker port
# Warning: HumanGreeter must be a global variable
# The name given to the constructor must be the name of the
# variable
global HumanGreeter
HumanGreeter = HumanGreeterModule("HumanGreeter")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print
print "Interrupted by user, shutting down"
myBroker.shutdown()
sys.exit(0)
if __name__ == "__main__":
main()