本文整理汇总了Python中naoqi.ALProxy.setVocabulary方法的典型用法代码示例。如果您正苦于以下问题:Python ALProxy.setVocabulary方法的具体用法?Python ALProxy.setVocabulary怎么用?Python ALProxy.setVocabulary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类naoqi.ALProxy
的用法示例。
在下文中一共展示了ALProxy.setVocabulary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpeechDetectionModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
class SpeechDetectionModule(ALModule):
""" A module that handles NAO recognition app commands. """
def __init__(self, name):
ALModule.__init__(self, name)
self.name = name
self.memory = ALProxy("ALMemory")
self.asr = ALProxy("ALSpeechRecognition")
self.asr.setLanguage("English")
vocabulary = ["color", "text", "gesture", "phone"]
self.asr.setVocabulary(vocabulary, False)
self.asr.subscribe(self.getName())
self.memory.subscribeToEvent("WordRecognized", self.getName(), "onWordRecognized")
def onWordRecognized(self, key, value, message):
""" A method that handles command recognition. """
global NaoWorkingMode
if(len(value) > 1 and value[1] >= 0.5):
print 'recognized the word :', value[0]
NaoWorkingMode = value[0]
else:
print 'unsifficient threshold'
NaoWorkingMode = None
def disconnect(self):
try:
self.memory.unsubscribeToEvent("WordRecognized", self.getName())
self.asr.unsubscribe(self.getName())
except BaseException, err:
print "Error while disconnecting from speech module: " + str(err)
示例2: NAOVoiceRec
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
class NAOVoiceRec(ALModule):
def __init__(self, id, ip, port, wordList, callBack, wordSpotting=True, visualExpression=True, audioExpression=False):
super(NAOVoiceRec, self).__init__(id)
self.id = id
self.wordCallBack = callBack;
#create the speech recognition proxy
self.speechRec = ALProxy("ALSpeechRecognition", ip, port)
#set the language
self.speechRec.setLanguage("English")
#load the vocabulary
self.speechRec.setVocabulary(wordList, wordSpotting)
self.speechRec.subscribe(id)
# configure expressions
self.speechRec.setVisualExpression(visualExpression)
self.speechRec.setAudioExpression(audioExpression)
#get the ALMemory Proxy and subscribe to the events
self.memProx = ALProxy("ALMemory")
self.memProx.subscribeToEvent("WordRecognized", self.id, "wordRecognized")
def __del__(self):
self.speechRec.unsubscribe(self.id)
self.memProx.unsubscribeToEvent("WordRecognized", self.id)
def wordRecognized(self, event, words, id):
self.wordCallBack(words)
示例3: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
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
# HUE service
self._hue = None
self._teller = None
# Create a proxy to ALTextToSpeech for later use
global tts
tts = ALProxy("ALTextToSpeech", NAO_IP, 9559)
# Subscribe to the FaceDetected event:
global memory
self.leds = ALProxy("ALLeds", NAO_IP, 9559)
memory = ALProxy("ALMemory")
memory.subscribeToEvent("MiddleTactilTouched",
"HumanGreeter",
"onMiddleTouchSensed")
# memory.unsubscribeToEvent("WordRecognized",
# "HumanGreeter")
speechrecog = ALProxy("ALSpeechRecognition")
speechrecog.setLanguage("French")
wordList = ["bleu", "rouge", "vert", "jaune",
"porte", "température", "meteo"]
try:
speechrecog.setVocabulary(wordList, True)
except Exception as ex:
_logger.warning("Got exception: %s", ex)
tts.say("Je suis prêt à recevoir des ordres")
示例4: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
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="10.0.1.3",
pport=9559)
(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
asr = ALProxy("ALSpeechRecognition", "10.0.1.3", 9559)
asr.setLanguage("English")
# Example: Adds "yes", "no" and "please" to the vocabulary (without wordspotting)
vocabulary = ["yes", "no", "please"]
asr.setVocabulary(vocabulary, False)
# Start the speech recognition engine with user Test_ASR
asr.subscribe("Test_ASR")
# Warning: HumanGreeter must be a global variable
# The name given to the constructor must be the name of the
# variable
global SpeechDetector
SpeechDetector = SpeechDetectorModule("SpeechDetector")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print
print "Interrupted by user, shutting down"
asr.unsubscribe("Test_ASR")
myBroker.shutdown()
sys.exit(0)
示例5: Reward
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
class Reward(ALModule):
value = 0
event_received = False
def __init__(self, _name):
self.name = _name
ALModule.__init__(self, _name)
self.memory = ALProxy("ALMemory")
self.speechRecognizer = ALProxy("ALSpeechRecognition")
for subscriber in self.speechRecognizer.getSubscribersInfo():
self.speechRecognizer.unsubscribe(subscriber[0])
vocabulary=["bravo"]
self.speechRecognizer.setVocabulary(vocabulary, False)
def subscribe_to_events(self):
self.memory.subscribeToEvent( "FrontTactilTouched", self.name, "onFrontTactilTouched" )
self.memory.subscribeToEvent( "RearTactilTouched", self.name, "onRearTactilTouched" )
self.speechRecognizer.subscribe("success_event")
def unsubscribe_to_events(self):
self.memory.unsubscribeToEvent("FrontTactilTouched", self.name)
self.memory.unsubscribeToEvent("RearTactilTouched", self.name)
self.speechRecognizer.unsubscribe("success_event")
def reset(self):
self.value = 0
self.event_received = False
self.unsubscribe_to_events()
def positiveReward(self):
self.value = 1
self.event_received = True
def negativeReward(self):
self.value = -1
self.event_received = True
def successReward(self):
self.value = 10
self.event_received = True
def onFrontTactilTouched(self, *_args):
"""
Callback method for FrontTactilTouched event
"""
if not(self.event_received):
self.positiveReward()
def onRearTactilTouched(self, *_args):
"""
Callback method for RearTactilTouched event
"""
if not(self.event_received):
self.negativeReward()
示例6: createSpeechRecogProxy
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
def createSpeechRecogProxy(robot_ip, robot_port):
# creates the speech recognition proxy
global asr
asr = ALProxy("ALSpeechRecognition", robot_ip, robot_port)
asr.setLanguage("English")
asr.pause(True)
# adds vocabulary, sets it, and enables word spotting
vocabulary = ["what is the slope of the line from"]
asr.setVocabulary(vocabulary, True)
asr.pause(False)
asr.subscribe("Test_ASR")
示例7: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
def __init__(self, name):
ALModule.__init__(self, name)
global asr
asr = ALProxy("ALSpeechRecognition", NAO_IP, 9559)
asr.setLanguage("English")
vocabulary = ["h", "e", "l", "o", "i", "t", "r", "b", "yes", "hey"]
asr.setVocabulary(vocabulary, False)
global memory
memory = ALProxy('ALMemory', NAO_IP, 9559)
memory.subscribeToEvent("WordRecognized", name, "onWordRecognized")
示例8: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
def __init__(self, name):
ALModule.__init__(self, name)
self.tts = ALProxy("ALTextToSpeech", "138.110.234.37", 9559)
asr = ALProxy("ALSpeechRecognition", "138.110.234.37", 9559)
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("WordRecognized", "Test", "onWordRecognized")
asr.pause(True)
asr.setVocabulary(["cabbage", "hello", "punch"], True)
asr.setAudioExpression(True)
asr.setVisualExpression(True)
asr.pause(False)
示例9: SpeechEventModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
class SpeechEventModule(ALModule):
def __init__(self, name, vocabulary, wordspotting=False):
ALModule.__init__(self, name)
global memory
self.memory = ALProxy('ALMemory', NAO_IP, 9559)
self.module_name = name
self.asr = ALProxy("ALSpeechRecognition", NAO_IP, 9559)
#self.asr.setLanguage("Dutch")
self.asr.setVocabulary(vocabulary,wordspotting)
#==============================================================================
# try:
#
# except:
# print("something went wrong with setting the vocabulary.")
# pass
#==============================================================================
self.listen()
def listen(self):
try:
self.memory.unsubscribeToEvent("WordRecognized", self.module_name)
except:
pass
self.memory.subscribeToEvent("WordRecognized", self.module_name, "onWordRecognized")
def unsubscribeFromMemory(self):
try:
self.memory.unsubscribeToEvent("WordRecognized", self.module_name)
except:
pass
def onWordRecognized(self, key, value, message):
""" does this and that """
print "Event detected!"
print "Key: ", key
print "Value: " , value
print "Message: " , message
if (value[0] == 'Bitterballen') & (value[1] < 0.4):
print("I'm not confident enough that I really heard Bitterballen")
else:
self.memory.unsubscribeToEvent("WordRecognized", self.module_name)
示例10: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
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
# Create a proxy to ALTextToSpeech for later use
self.tts = ALProxy("ALTextToSpeech")
asr = ALProxy("ALSpeechRecognition")
asr.pause(True)
asr.setVocabulary(["point"], True)
asr.setAudioExpression(True)
asr.setVisualExpression(True)
asr.pause(False)
# Subscribe to the FaceDetected event:
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("WordRecognized", "Test", "onWordRecognized")
示例11: init
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
def init():
NAO_IP = "nao.local"
NAO_PORT = 9559
print "init"
global memory
memory = ALProxy("ALMemory", NAO_IP, NAO_PORT)
global broker
broker = ALBroker("pythonBroker", "0.0.0.0", 0, NAO_IP, NAO_PORT)
global motion
motion = ALProxy("ALMotion", "nao.local", NAO_PORT)
motion.setStiffnesses("Body", 1.0)
global dialog
dialog = ALProxy('ALDialog', NAO_IP, NAO_PORT)
dialog.setLanguage("French")
global aas
aas = ALProxy("ALAnimatedSpeech", NAO_IP, NAO_PORT)
global asr
asr = ALProxy("ALSpeechRecognition", NAO_IP, NAO_PORT)
global vocabulary
vocabulary = ["oui", "non", "nathan", "michel", "test", "viens"]
asr.subscribe("Test_ASR")
asr.pause(True)
asr.setVocabulary(vocabulary, False)
asr.pause(False)
asr.NameFound = False
print "init end"
try:
p = ALProxy("faceHandlerModule")
p.exit() # kill previous instance
except:
pass
try:
q = ALProxy("voiceHandlerModule")
q.exit()
except:
pass
示例12: ALProxy
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
# -*- encoding: UTF-8 -*-
import sys
import time
import random
import motion
from naoqi import ALProxy
tts = ALProxy("ALTextToSpeech","nao.local",9559)
sr = ALProxy("ALSpeechRecognition","nao.local",9559)
memProxy = ALProxy("ALMemory","nao.local",9559)
motion = ALProxy("ALMotion","nao.local",9559)
sr.setVocabulary(["oui","non","un","deux","trois","quatre","cinq","six","sept","huit","neuf","dix","douze","quatorze","quinze","seize","dix-huit","vingt","vingt-et-un","vingt-quatre","vingt-cinq","vingt-sept","vingt-huit","trente","trente-deux","trente-cinq","trente-six","quarante","quarante-deux","quarante-cinq","quarante-huit","quarante-neuf","cinquante","cinquante-quatre","cinquante-six","soixante","soixante-trois","soixante-quatre","soixante-dix","soixante-douze","quatre-vingts","quatre-vingt-un","quatre-vingt-dix","cent"],True)
sr.setAudioExpression(True)
sr.setVisualExpression(True)
fini = False
x = "WordRecognized"
cpt = 3
def onWordRecognized(x,total):
"""Ici on regarde le mot reconnu si l'indice de fiabilité est supérieur à 0.5 """
retVal = memProxy.getData("WordRecognized")
print x, retVal[0], retVal[1]
print total
if(retVal[0] != "" and retVal[1]>0.5):
if(retVal[0] == "un" and total == 1):
return True
elif retVal[0] == "deux" and total == 2:
示例13: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
#.........这里部分代码省略.........
def headmove(self, angles,speed):
if self.headlock == True:
return
self.headlock == True
Id = self.motionProxy.post.setAngles(["HeadYaw", "HeadPitch"], angles, speed)
self.motionProxy.wait(Id, 0)
self.headlock == False
def search(self):
prevodom = self.headOdom
self.headmove([-0.8,self.headOdom[1]],0.1)
time.sleep(2)
if self.stop == False :
self.headmove([0.8, self.headOdom[1]],0.1)
time.sleep(2)
#return to original
if self.stop == False:
self.headmove(prevodom,0.1)
self.stop = False
def audio_callback(self,msg):
if self.speechini == False :
self.speechini = True
self.asr.pause(True)
self.vocabulary = ["yes", "no", "please", "hello","the","be","to","of","and","in","that","have","it","robot"]
self.asr.setVocabulary(self.vocabulary, True)
self.asr.setVisualExpression(True)
self.asr.setAudioExpression(True)
self.asr.subscribe("ASR")
self.asr.pause(False)
nodetectionCount = 0
# print msg.azimuth.data
while True:
time.sleep(0.8)
speech = self.memoryProxy.getData(self.memValue, 0)
voice = self.memoryProxy.getData('SpeechDetected', 0)
if (voice ==1 ):
if speech[1] > 0.1:
nodetectionCount =0
self.speechPub.publish(True)
return
else:
nodetectionCount +=1
if nodetectionCount >10:
self.asr.pause(True)
return
def navigate(self,x):
self.checkawake()
self.motionProxy.moveTo(x,0,0)
def rotate(self,z):
示例14: Motion
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
#.........这里部分代码省略.........
def turn_right(self):
if(self.robot_position.get()) == "Sitting":
self.tts.say(random.choice(self.expressions))
else:
self.motion.moveTo(0 , 0 , -1.5709)
if (self.command_origin.get()) == 0:
self.log_list.insert('end' ,("Turn right (Keyboard Command)") )
else:
pass
# Checks the position of the robot and if robot is sitting down a random voice message from a predefined list of expressions
# (declared at the top) informs the the user that the robot has to stand up first if the case is to turn left.If the robot
# though is standind up,turns its body on the left regarding the theta axis.The movement equals to pi/2.
# if the command has been given by voice inserts a relevant text to the list on the right otherwise sets a text saying that the command comes from the keyboard
def turn_left(self):
if(self.robot_position.get()) == "Sitting":
self.tts.say(random.choice(self.expressions))
else:
self.motion.moveTo(0 , 0 , 1.5709)
if (self.command_origin.get()) == 0:
self.log_list.insert('end' ,("Turn left (Keyboard Command)") )
else:
pass
# When is called opens a dialog window between the user and the robot that lasts 3 seconds.During that time the robot listens
# the words that the user says ,retrieves from memory the list of the predefined words given at the beggining and
# with the help of the getMostConfWord method acts in a different way every time depending on the word has been received.
# At the beggining of the dialog robot speaks to the user and informs him that is ready to accept any words want to provide.
def start_vocabulary(self):
self.speechrec.setVocabulary(self.words_list , True)
if (self.speech_counter) == True :
self.tts.say("Hello my friend.Simply tell me in which direction you want me to move"
"and I will do it. You can choose any of the movements displayed on the pc screen.In case you want me to stop "
"just tell me the word relax. Please speak clear and loud now")
else:
pass
# A loop opens a connection with the robot initially ,then gets the word that the user says and proceeds to the relevant action.
while self.speech_counter == True :
self.speechrec.subscribe("tts")
print("subscribed")
time.sleep(4)
list = self.memory.getData("WordRecognized")
self.getMostConfWord(list, 0.25)
self.speechrec.unsubscribe("tts")
print("unsubscribed")
else:
self.tts.say("You have selected to exit the conversation.")
self.tts.say("To be honest with you,I have started feeling a bit tired with all these movements.Bye Bye")
pass
return
# Selects the word with the highest level of confidentiality from a list of predefined
# words (that has been set at initialization) when users speaks to the robot.
def getMostConfWord(self,recogList, threshold):
示例15: NaoSpeechRecognition
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import setVocabulary [as 别名]
#.........这里部分代码省略.........
def add_listener(self, listener, words):
"""
Adds a speech listener
:param listener: Listener to add
:param words: Words recognized by the listener
"""
self._listeners[listener] = words
_logger.info("Adding words: %s (%s)", words, type(words).__name__)
def remove_listener(self, listener):
"""
Removes a speech listener
:param listener: Listener to remove
:raise KeyError: Unknown listener
"""
del self._listeners[listener]
def recognize(self, words=None):
"""
Starts the recognition
:param words: The vocabulary to use (optional)
"""
self._can_recog.clear()
# Start the speech recognition
if not words:
words = set()
for listener_words in self._listeners.values():
words.update(listener_words)
self._recog.setVocabulary(list(words), True)
# Pause the TTS service, if any
if self._tts is not None:
self._tts.pause()
# Subscribe the word recognition event
self._memory.subscribeToEvent("WordRecognized",
self._name,
self.on_word_recognized.__name__)
def simple_recognize(self, words):
"""
One-shot recognition
"""
# Wait to be able to recognize
self._can_recog.wait()
self._can_recog.clear()
# Prepare the recognition
self._recog.setVocabulary(list(words), True)
self._single_recognized.clear()
# Pause the TTS service, if any
if self._tts is not None:
self._tts.pause()
# Subscribe the word recognition event
self._memory.subscribeToEvent("WordRecognized",
self._name,
self.on_single_recognized.__name__)
# Wait for the word to be recognized