本文整理汇总了Python中brain.Brain.tick方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.tick方法的具体用法?Python Brain.tick怎么用?Python Brain.tick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.tick方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Conversation
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import tick [as 别名]
class Conversation(object):
def __init__(self, persona, mic, profile):
self._logger = logging.getLogger(__name__)
self.persona = persona
self.mic = mic
self.profile = profile
self.brain = Brain(mic, profile)
self.notifier = Notifier(profile)
# Load the aiml module
self.aimlkernel = aiml.Kernel()
# Load the aiml files
folder = "/home/pi/jasper/client/modules/aiml/alice/"
for file in os.listdir(folder):
if file.endswith(".aiml"):
self.aimlkernel.learn(folder+file)
print(folder+file)
folder = "/home/pi/jasper/client/modules/aiml/standard/"
for file in os.listdir(folder):
if file.endswith(".aiml"):
self.aimlkernel.learn(folder+file)
print(folder+file)
def handleForever(self):
"""
Delegates user input to the handling function when activated.
"""
self._logger.info("Starting to handle conversation with keyword '%s'.",
self.persona)
while True:
# Print notifications until empty
notifications = self.notifier.getAllNotifications()
for notif in notifications:
self._logger.info("Received notification: '%s'", str(notif))
self._logger.debug("Started listening for keyword '%s'",
self.persona)
threshold, transcribed = self.mic.passiveListen(self.persona)
self._logger.debug("Stopped listening for keyword '%s'",
self.persona)
if not transcribed or not threshold:
self._logger.info("Nothing has been said or transcribed.")
continue
self._logger.info("Keyword '%s' has been said!", self.persona)
self._logger.debug("Started to listen actively with threshold: %r",
threshold)
input = self.mic.activeListenToAllOptions(threshold)
self._logger.debug("Stopped to listen actively with threshold: %r",
threshold)
if input:
self.brain.query(input)
else:
self.mic.say("Pardon?")
# Call behaviour tree
self._logger.debug("Calling next on the behaviour tree")
print("Calling next on the behaviour tree")
self.brain.tick()