本文整理汇总了Python中naoqi.ALProxy.say方法的典型用法代码示例。如果您正苦于以下问题:Python ALProxy.say方法的具体用法?Python ALProxy.say怎么用?Python ALProxy.say使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类naoqi.ALProxy
的用法示例。
在下文中一共展示了ALProxy.say方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NaoTTS
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
class NaoTTS(object):
"""
Nao text-to-speech service
"""
def __init__(self):
"""
Sets up members
"""
self._tts = None
# Authorization to speak
self._can_speak = threading.Event()
self._can_speak.set()
self.__speaking_lock = threading.Lock()
@Validate
def validate(self, context):
"""
Component validated
"""
# Set up the TTS proxy
self._tts = ALProxy("ALTextToSpeech")
@Invalidate
def invalidate(self, context):
"""
Component invalidated
"""
# Stop using the proxy
self._tts = None
# Unlock everything
self._can_speak.set()
def say(self, sentence):
"""
Says the given sentence
:param sentence: Text to say
"""
with self.__speaking_lock:
# Wait to be authorized to speak
self._can_speak.wait()
# Say what we have to
self._tts.say(sentence)
def resume(self):
"""
Allows Nao to speak
"""
self._can_speak.set()
def pause(self):
"""
Forbids Nao to speak
"""
if self._can_speak.is_set():
with self.__speaking_lock:
self._can_speak.clear()
示例2: post
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def post(self):
naoip=self.get_argument('ip','')
naoport= self.get_argument('port','')
ncmd= self.get_argument('cmd','')
if(ncmd=='walk'):
motion = ALProxy("ALMotion", str(naoip), int(naoport))
tts = ALProxy("ALTextToSpeech", str(naoip), int(naoport))
motion.moveInit()
motion.post.moveTo(0.5, 0, 0)
tts.say("I'm walking")
self.write("DONE!")
if(ncmd=='talk'):
naoip=self.get_argument('ip','')
naoport= self.get_argument('port','')
talk=self.get_argument('nspeak','')
if (talk==''):
talk="Hello, I am Nao"
animatedSpeechProxy = ALProxy("ALAnimatedSpeech", str(naoip), int(naoport))
# set the local configuration
configuration = {"bodyLanguageMode":"contextual"}
# say the text with the local configuration
animatedSpeechProxy.say(str(talk), configuration)
self.write("DONE!")
if(ncmd=='dance'):
naoip=self.get_argument('ip','')
naoport= self.get_argument('port','')
behaviorName=str(self.get_argument('ndance',''))
managerProxy = ALProxy("ALBehaviorManager", str(naoip), int(naoport))
getBehaviors(managerProxy)
launchAndStopBehavior(managerProxy, behaviorName)
defaultBehaviors(managerProxy, behaviorName)
self.write("DONE!")
示例3: TactileHeadModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
class TactileHeadModule(ALModule):
AudioModule = None
def __init__(self, name, audiomodule):
ALModule.__init__(self, name)
self.AudioModule = audiomodule
# Create a proxy to ALTextToSpeech for later use
self.tts = ALProxy("ALTextToSpeech")
# Subscribe to TouchChanged event:
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("MiddleTactilTouched",
"ReactToTouch",
"onTouched")
def onTouched(self, strVarName, value):
""" This will be called each time a touch
is detected.
"""
# Unsubscribe to the event when talking,
# to avoid repetitions
memory.unsubscribeToEvent("MiddleTactilTouched",
"ReactToTouch")
self.tts.say("D'accord, on arrête de jouer")
self.AudioModule.cs = 0
# Subscribe again to the event
memory.subscribeToEvent("MiddleTactilTouched",
"ReactToTouch",
"onTouched")
示例4: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def main(robotIP, PORT=9559):
''' Example showing a hand ellipsoid
Warning: Needs a PoseInit before executing
'''
motionProxy = ALProxy("ALMotion", robotIP, PORT)
postureProxy = ALProxy("ALRobotPosture", robotIP, PORT)
# Wake up robot
motionProxy.wakeUp()
# Send robot to Stand Init
postureProxy.goToPosture("StandInit", 0.5)
#tts = ALProxy("ALTextToSpeech", "192.168.2.17", 9559)
tts = ALProxy("ALTextToSpeech", "168.156.34.195", 9559)
tts.say("Hello, I'm going to move my left arm.")
tts.say("Then I will go back to the rest position!")
effector = "LArm"
frame = motion.FRAME_TORSO
axisMask = almath.AXIS_MASK_VEL # just control position
useSensorValues = False
path = []
currentTf = motionProxy.getTransform(effector, frame, useSensorValues)
# point 1
targetTf = almath.Transform(currentTf)
targetTf.r2_c4 -= 0.05 # y
path.append(list(targetTf.toVector()))
# point 2
targetTf = almath.Transform(currentTf)
targetTf.r3_c4 += 0.04 # z
path.append(list(targetTf.toVector()))
# point 3
targetTf = almath.Transform(currentTf)
targetTf.r2_c4 += 0.04 # y
path.append(list(targetTf.toVector()))
# point 4
targetTf = almath.Transform(currentTf)
targetTf.r3_c4 -= 0.02 # z
path.append(list(targetTf.toVector()))
# point 5
targetTf = almath.Transform(currentTf)
targetTf.r2_c4 -= 0.05 # y
path.append(list(targetTf.toVector()))
# point 6
path.append(currentTf)
times = [0.5, 1.0, 2.0, 3.0, 4.0, 4.5] # seconds
motionProxy.transformInterpolations(effector, frame, path, axisMask, times)
# Go to rest position
motionProxy.rest()
示例5: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def main():
asr = ALProxy("ALSoundRecognition", "192.168.3.13", 9559)
tts = ALProxy("ALTextToSpeech", "192.168.3.13", 9559)
rec = asr.getStatus()
print rec
if rec == 0:
print u"未初始化成功"
elif rec == 4:
asr.restart()
while 1:
print "start recognition"
asr.startSession()
while 1:
rec = asr.getStatus()
if rec == 2:
continue
else:
break
if rec == 5:
result = asr.getResult()
print "result:"
if result!='':
result_json = json.loads(result)
print result_json
if result_json["rc"]==0:
tts.say(result_json["answer"]["text"].encode("utf-8"))
else:
#print result_json["text"],type(result_json["text"])
tts.say(result_json["text"].encode("utf-8"))
elif rec == 4:
errorCode = asr.getResult()
print u"error:",errorCode
asr.stopSession()
elif rec == 3:
print "识别中止"
示例6: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [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")
示例7: powerOff
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def powerOff (self):
tts = ALProxy("ALTextToSpeech", 'nao.local', 9559)
tts.say("即将执行关机操作!")
command1 = 'sudo shutdown -h now'
os.system(command1)
command2 = 'root\r' # here is tha default password of root user
os.system(command2)
示例8: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def main():
""" Main entry point
"""
################MAIN() CODE FOR FREEZING BOT#############################
global brokyControlly
brokyControlly = BrokerController()
brokyControlly.createBroker()
# Warning: BotFreezer must be a global variable
# The name given to the constructor must be the name of the
# variable
global BotFreezer
BotFreezer = BotFreezerModule("BotFreezer")
##########END MAIN() CODE FOR FREEZING BOT################################
#############################PROGRAM SPECIFIC ############################
# Program specific proxies
speechProxy = ALProxy("ALTextToSpeech")
global nonBlockyWalky
nonBlockyWalky = NonBlockWalk2("nonBlockyWalky")
nonBlocky = ALProxy("nonBlockyWalky")
# nonBlocky also has to have a post in it, along with
# the walk commands INSIDE "NonBlockWalk2.py", if wait()
# is going to work correctly
id = nonBlocky.post.walk()
nonBlocky.wait(id, 0)
speechProxy.say("I have arrived.")
############################END PROGRAM SPECIFIC############################
################MAIN() CODE FOR FREEZING BOT################################
brokyControlly.waitToStop()
示例9: HumanGreeterModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
class HumanGreeterModule(ALModule):
""" A simple module able to react
to facedetection events
"""
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")
# Subscribe to the FaceDetected event:
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("FaceDetected","HumanGreeter", "onFaceDetected")
def onFaceDetected(self, *_args):
""" This will be called each time a face is
detected."""
# Unsubscribe to the event when talking,
# to avoid repetitions
memory.unsubscribeToEvent("FaceDetected", "HumanGreeter")
self.tts.say("je suis content")
# Subscribe again to the event
memory.subscribeToEvent("FaceDetected", "HumanGreeter", "onFaceDetected")
示例10: searchweb
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def searchweb(searchquery):
url = 'http://www.bing.com/search?q='
#searchquery = raw_input('Enter search query: ')
url = url + searchquery
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
tts = ALProxy('ALTextToSpeech','localhost',9559)
#print htmltext
if searchquery.startswith(('who','whos','who\'s')) or re.search(r'^[Ww]ho is',searchquery):
regex = '<div class="b_hide"(.*?)><span>(.+?)</span></div>' #check with .* and .*?
so = re.search(regex,htmltext,re.M|re.I)
#print so.group()
#answer = re.findall(regex,str(htmltext))
#print answer some weird tuple forms
sentences = re.split('\.',so.group(2))
print sentences[0]
elif searchquery.startswith(('distance')) or re.search(r'^[Hh]ow far',searchquery):
regex = '<p class="drHours" data-tag="drDistance">(.+?)</p>'
answer = re.findall(regex, str(htmltext))
regex ='<p class="drHoursLabel" data-tag="drDistanceLabel">(.+?)</p>'
answer.append((re.findall(regex,htmltext))[0])
#print answer
print "".join(answer)
else:
regex = '<div class="(\w*\s*)b_focusText(Medium|Large|Small)">(.+?)</div>'
#so = re.search(regex,htmltext,re.M|re.I)
#print so.group()
#pattern = re.compile(regex)
answer = re.findall(regex, str(htmltext))
#print answer
if answer:
so1 = re.search(r'<a(.*)>(.+?)</a>',answer[0][2],re.M|re.I) #extracting from href
if so1:
print 'Answer: ',tts.say(so1.group(2))
else:
print 'Answer: ',tts.say(answer[0][2])
else:
print 'Sorry. Couldn\'t find anything'
示例11: speakFunction
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def speakFunction(text_dialog):#,PARALLEL_TASKS):
#,PARALLEL_TASKS is defined GLOBAl
tts = ALProxy("ALTextToSpeech",robotIP,PORT2)
if(PARALLEL_TASKS):
print "::PARALLEL_TASKS=ON"
tts.post.say(text_dialog)
else:
print "::PARALLEL_TASKS=OFF"
tts.say(text_dialog)
示例12: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def main(robotIP, PORT=9559):
animatedSpeechProxy = ALProxy("ALAnimatedSpeech", robotIP, PORT)
configuration = {"bodyLanguageMode":"contextual"}
lines = "^start(animations/Stand/Gestures/YouKnowWhat_1) \
He wants to rule over all humans and robots."
animatedSpeechProxy.say(lines)
示例13: ConversationModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
class ConversationModule(ALModule):
def __init__(self, name):
ALModule.__init__(self, name)
self.tts = ALProxy("ALTextToSpeech")
self.ears = ALProxy("ALSpeechRecognition")
self.memory = ALProxy("ALMemory")
self.log = ALProxy("ALLogger")
self.ears.subscribe("Conversation")
self.memory.subscribeToEvent("WordRecognized", "Conversation", "onWordRecognized")
def onWordRecognized(self, key, value, message):
"""
Subscribe to change in mood
:param key: memory key
:param value: memory value
:param message: message of the event
:return:
"""
self.ears.unsubscribe("Conversation")
self.tts.say("I recognized %s" % value)
self.ears.subscribe("Conversation")
pass
def setMood(self, value):
"""
Sets the current mood felt by the robot
:param value: Mood value 1=good, 0=neutral, -1=bad
:return:
"""
self.__previousMood = self.__mood
self.__mood = Mood(value)
self.memory.raiseEvent("Brain/Mood/Text", self.__mood.text)
self.memory.raiseEvent("Brain/Mood/Value", self.__mood.value)
pass
def getMood(self):
"""
Gets the current mood
:return:
"""
return self.__mood
def getPreviousMood(self):
"""
Gets the previous mood
:return:
"""
return self.__previousMood
示例14: BrainProxy
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
class BrainProxy():
def __init__(self):
self.init_logger()
self.read_config()
self.log.info("Brain Proxy started")
self.host_name = str(self.config['serverHostName'])
# self.host_name = "nao2.local"
self.naoqi_port = int(self.config['naoQiPort'])
self.naoMotion = NaoMotion(self.host_name, self.naoqi_port)
self.ttsProxy = ALProxy("ALTextToSpeech", self.host_name, self.naoqi_port)
websocket.enableTrace(False)
self.ws_uri = "ws://localhost:" + str(self.config['websocketPort'])
self.ws = websocket.WebSocketApp(self.ws_uri,
on_message=self.on_message,
on_error=self.on_error,
on_close=self.on_close)
self.ws.on_open = self.on_open
self.ws.run_forever()
def on_message(self, ws, message):
self.log.info("Received : " + message)
sign = str(json.loads(message)['GESTURE'])
self.ttsProxy.say(sign)
# time.sleep(3)
self.log.info("Message sent to Al-TTS")
# self.naoMotion.handGesture(data)
self.naoMotion.walk(sign)
def on_error(self, ws, error):
print error
def on_close(self, ws):
self.log.info("Connection closed")
def on_open(self, ws):
self.ws.send("AL")
self.log.info("Connected to Brain")
def read_config(self):
with open('../config/hri.json') as config_file:
self.config = json.load(config_file)
self.log.info("Config file parsed")
def init_logger(self):
# logging.basicConfig()
self.log = logging.getLogger('brain')
self.log.setLevel(logging.INFO)
format = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch = logging.StreamHandler(sys.stdout)
ch.setFormatter(format)
self.log.addHandler(ch)
示例15: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import say [as 别名]
def main(ip, port):
try:
motionProxy = MMMotion.MotionProxy(ip, port)
visionProxy = MMVision.VisionProxy(ip, port)
memoryProxy = MMMemory.MemoryProxy(ip, port)
sayproxy = ALProxy("ALTextToSpeech", "192.168.1.100", 9559)
sayproxy.say("Started")
except Exception, e:
print "ERROR:"
print e
sys.exit(1)