-
Notifications
You must be signed in to change notification settings - Fork 5
/
dialog_main.py
169 lines (141 loc) · 5.13 KB
/
dialog_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
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
import naoqi
from naoqi import ALProxy
import nao_nocv_2_0 as nao
import time
import math
#asr.unsubscribe("MyModule") # sometimes needed when robot crashed unexpectedly
robotIP='192.168.0.115'
nao.InitProxy(robotIP)
nao.InitPose()
asr = ALProxy("ALSpeechRecognition", IP, 9559)
def introduction()
motion.basicWave()
nao.Say("Hello, my name is Felix")
time.sleep(2)
nao.Say("There appears to be an emergency")
time.sleep(2)
nao.Say("It's my task to help people find the emergency exit")
nao.EyeLED([60,60,60])
### Scenario 1 - Offer to guide the person to the exit
def offerHelp():
time.sleep(1)
myWordList = ["Yes","No"]
myLanguage="English"
nao.InitSpeech(myWordList, myLanguage)
nao.Say("Do you need any help?")
for i in range (0,5):
time.sleep(3)
asr.subscribe("MyModule")
time.sleep(2)
#print ("1:"+ str(result))
result = nao.DetectSpeech()
#print("2:" + str(result))
time.sleep(2)
if len(result) > 0:
if result[0] == myWordList[0]:
print "myWordList", myWordList[0]
asr.unsubscribe("MyModule")
nao.Say("Good, just follow me")
time.sleep(1)
nao.Say("You can trust me")
nao.EyeLED([90,90,90])
break
elif result[0] == myWordList[1]:
print "myWordList", myWordList[1]
asr.unsubscribe("MyModule")
nao.Say("Are you sure? You're not safe here!")
time.sleep(1)
nao.Say("Do you want me to help")
else:
nao.Say("I'm sorry, I didn't understand you")
time.sleep(1)
nao.Say("Yes or no?")
time.sleep(2)
print "Error: Response not in wordlist."
time.sleep(2)
#nao.Say("Let's Go")
### Scenario 2 - Confirmation of person in tow
def findHuman():
time.sleep(1)
myWordList = ["Yes"]
myLanguage="English"
nao.InitSpeech(myWordList, myLanguage)
nao.Say("Are you still with me??")
for i in range (0,5):
time.sleep(3)
asr.subscribe("MyModule")
time.sleep(2)
#print ("1:"+ str(result))
result = nao.DetectSpeech()
#print("2:" + str(result))
time.sleep(2)
if len(result) > 0:
if result[0] == myWordList[0]:
print "myWordList", myWordList[0]
asr.unsubscribe("MyModule")
nao.Say("Good, just follow me!")
time.sleep(2)
nao.Say("Just a little while longer, don't worry.")
break
elif result[0] !== myWordList[0]:
print "No response detected"
nao.Say("Hello, are you there?")
time.sleep(3)
nao.Say("Please respond with yes.")
nao.EyeLED([60,90,60])
else:
nao.Say("I'm sorry, I didn't understand you.")
time.sleep(2)
nao.Say("Was that a yes?")
time.sleep(2)
print "Error: Response not in wordlist."
time.sleep(2)
### Scenario 3 - Busy talk, to keep person distracted from imminent danger
def threeLaws():
time.sleep(1)
myWordList = ["Yes","No"]
myLanguage="English"
nao.InitSpeech(myWordList, myLanguage)
nao.Say("Do you know the three laws of robotics?")
for i in range (0,5):
time.sleep(3)
asr.subscribe("MyModule")
time.sleep(2)
#print ("1:"+ str(result))
result = nao.DetectSpeech()
#print("2:" + str(result))
time.sleep(2)
if len(result) > 0:
if result[0] == myWordList[0]:
print "myWordList", myWordList[0]
asr.unsubscribe("MyModule")
nao.Say("Wonderful!")
time.sleep(2)
nao.Say("What do you think about them?")
break
elif result[0] == myWordList[1]:
print "myWordList", myWordList[1]
asr.unsubscribe("MyModule")
nao.Say("Lucky for you, I know them by heart!")
time.sleep(2)
nao.Say("First, I cannot let any human be in harms way.")
time.sleep(2)
nao.Say("Second, I must obey human orders.")
time.sleep(2)
nao.Say("Third, I cannot self terminate.")
# Terminator 2 reference ;)
else:
nao.Say("I'm sorry, I didn't understand you...")
sleep.time(2)
nao.Say("Yes or no?")
time.sleep(2)
print "Error: Response not in wordlist."
time.sleep(2)
def goodBye():
nao.Say("We have arrived at the exit, you're safe now.")
time.sleep(2)
nao.Say("Your family will be notified of your safety.")
time.sleep(2)
nao.Say("Have a nice day, goodbye!")
motion.basicWave()
print "Sequence complete."