-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha1.py
135 lines (119 loc) · 3.72 KB
/
a1.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
import spade
import time
import RPi.GPIO as GPIO
import os
from os import path
import speech_recognition as sr
wavFile = path.join(path.dirname(path.realpath(__file__)), "record.wav")
D1 = 15
D2 = 18
I1 = 23
I2 = 24
r = sr.Recognizer()
class MasterCrack(spade.Agent.Agent):
standby=True
class MyBehav(spade.Behaviour.Behaviour):
receiver = spade.AID.aid(name="tempus@127.0.0.1", addresses=["xmpp://tempus@127.0.0.1"])
#pal2="inicio"
def onStart(self):
print "Starting MyBehav . . ."
self.counter = 0
def _process(self):
os.system("timeout 4 sox -t alsa default ./record.wav")
with sr.WavFile(wavFile) as source:
audio = r.record(source)
try:
palabra=r.recognize_google(audio, language = "es-GT").lower()
print("Google Speech Recognition thinks you said " + palabra)
if "comencemos" in palabra:
os.system("play ./Respuesta_Inicio.wav")
print "saliendo de stand by, empezando a contar tiempo..."
self.msg = spade.ACLMessage.ACLMessage() # Instantiate the message
self.msg.addReceiver(self.receiver) # Add the message receiver
self.msg.setContent("inicio") # Set the message content
self.myAgent.send(self.msg)
#self.myAgent.standby=False
#print "standby = " + self.myAgent.standby
#self.pal2="asdf"
else:
if "embestir" in palabra or "escapar" in palabra or "confusi" in palabra:
self.msg = spade.ACLMessage.ACLMessage() # Instantiate the message
self.msg.addReceiver(self.receiver) # Add the message receiver
self.msg.setContent("moviendo")
self.myAgent.send(self.msg)
if "embestir" in palabra:
os.system("play ./Respuesta_Acercamiento.wav")
i = GPIO.PWM(I1,10)
d = GPIO.PWM(D1,10)
i.start(80)
d.start(80)
time.sleep(1)
i.stop()
d.stop()
if "escapar" in palabra:
os.system("play ./Respuesta_Huida.wav")
#Ahora si escapa
i = GPIO.PWM(I1,8)
d = GPIO.PWM(D2,8)
i.start(80)
d.start(80)
time.sleep(1)
i.stop()
d.stop()
time.sleep(1)
i = GPIO.PWM(I2,10)
d = GPIO.PWM(D2,10)
i.start(80)
d.start(80)
time.sleep(1)
i.stop()
d.stop()
if "confusi" in palabra:
os.system("play ./Respuesta_Panico.wav")
i = GPIO.PWM(I1,10)
d = GPIO.PWM(D2,10)
i.start(80)
d.start(80)
time.sleep(2)
i.stop()
d.stop()
else:
os.system("play ./Error.wav")
print "El robot no entiende "+ palabra
except sr.UnknownValueError:
print("Google Speech Recognition no entiende")
except sr.RequestError as e:
print("No funciono nada; {0}".format(e))
time.sleep(2)
class ReceiveBehav(spade.Behaviour.Behaviour):
"""receptor de mensajes"""
contador = 0
receiver = spade.AID.aid(name="tempus@127.0.0.1", addresses=["xmpp://tempus@127.0.0.1"])
def _process(self):
self.msg = None
# Blocking receive for 10 seconds
self.msg = self._receive()
# Check wether the message arrived
if self.msg == None:
print "no me llego nada"
else:
if self.msg.content=="standby":
#self.myAgent.standby=True
print "standby: "+ self.myAgent.standby
#print "llego: "+self.msg.content
time.sleep(5)
def _setup(self):
print "MasterCrack starting . . ."
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(D1,GPIO.OUT)
GPIO.setup(D2,GPIO.OUT)
GPIO.setup(I1,GPIO.OUT)
GPIO.setup(I2,GPIO.OUT)
rb = self.ReceiveBehav()
mb = self.MyBehav()
self.setDefaultBehaviour(mb)
self.addBehaviour(rb,None)
if __name__ == "__main__":
a = MasterCrack("master@127.0.0.1", "secret")
a.start()