forked from CHRI-Lab/NAO_concierge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speechReco.py
65 lines (44 loc) · 2.02 KB
/
speechReco.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
from naoqi import ALModule
from naoqi import ALProxy
import time
memory = None
# this file enables the speech recognition ability by NAOQi
class SpeechRecoModule(ALModule):
ENABLE_WORD_SPOTTING = False
CONFIDENCE_THRESHOLD = 20 #Confidence threshold (%)
def __init__(self, name, vocabulary):
ALModule.__init__(self, name)
self.name = name
self.tts = ALProxy("ALTextToSpeech")
self.asr = ALProxy("ALSpeechRecognition")
self.asr.pause(True)
self.asr.setVocabulary(vocabulary.split(';'), self.ENABLE_WORD_SPOTTING)
self.asr.pause(False)
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("WordRecognized", self.name, "onWordRecognized")
# callback. value -> [phrase_1, confidence_1, phrase_2, confidence_2, ...] (ranked by condifence)
def onWordRecognized(self, eventName, value, subscriberIdentifier):
memory.unsubscribeToEvent("WordRecognized", self.name)
if value[1] >= self.CONFIDENCE_THRESHOLD / 100. :
self.Dialog(value[0])
else:
print("nothing recognized")
time.sleep(1)
memory.subscribeToEvent("WordRecognized", self.name, "onWordRecognized")
# robot reaction to recognised word
def Dialog(self, word):
print("this is recoqnized: " + word)
global say_id
if ("hello" in word or "hi" in word):
say_id = self.tts.post.say("Oh hello!")
elif "how are you" in word:
say_id = self.tts.post.say("I'm good!")
elif "good morning" in word:
say_id = self.tts.post.say("Good morning!")
elif "nao" in word:
say_id = self.tts.post.say("Hi, I'm here!")
elif "where am I" in word:
say_id = self.tts.post.say("We are in the I X T lab!")
self.tts.wait(say_id, 0)
#https://github.com/salaxy/NaoSimpleSpeechRecognition/blob/master/src/speech_test_improve.py