-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeechRecognition.py
48 lines (43 loc) · 1.4 KB
/
SpeechRecognition.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
from naoqi import ALProxy
from naoqi import ALBroker
from naoqi import ALModule
import pdb
import time
"""
SpeechRecognition module, uses speech from naoqi
See main part for detailed instructions.
"""
class SpeechRecognition(ALModule):
"""To make it easier to use NaoQI proxies.
"""
def __init__(self, name):
ALModule.__init__(self, name);
self.response = False
self.value = []
global memory
memory = ALProxy("ALMemory")
self.name = name
self.spr = ALProxy("ALSpeechRecognition")
def getSpeech(self, wordlist, wordspotting):
"""
Starts speech recording
"""
self.response = False
self.value = []
self.spr.setVocabulary(wordlist, wordspotting)
memory.subscribeToEvent("WordRecognized", self.name, "onDetect")
def onDetect(self, eventname, value, subscriber):
"""
Called when a word is spotted, resets values so it can be used again.
"""
self.response = True
self.value = value
memory.unsubscribeToEvent("WordRecognized", self.name)
self.spr.pause(True)
if __name__ == "__main__":
IP = "131.174.106.197"
PORT = 9559
pythonBroker = ALBroker("pythonBroker", "0.0.0.0", 9600, IP, PORT)
Speecher = SpeechRecognition("Speecher", ["breakfast", "pay", "checkin"], True)
while Speecher.response is False:
time.sleep(1)