当前位置: 首页>>代码示例>>Python>>正文


Python Brain.query方法代码示例

本文整理汇总了Python中brain.Brain.query方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.query方法的具体用法?Python Brain.query怎么用?Python Brain.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brain.Brain的用法示例。


在下文中一共展示了Brain.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)

    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:
            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)
开发者ID:tdmike,项目名称:SASCHA,代码行数:37,代码来源:conversation.py

示例2: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
class Conversation(object):

    def __init__(self, persona, speaker, profile):
        self.persona = persona
        self.speaker = speaker
        self.profile = profile
        self.notifier = Notifier(profile)
        self.brain = Brain(speaker, profile)

    def handleForever(self):

        while True:

            notifications = self.notifier.getAllNotifications()
            for notif in notifications:
                self.speaker.say(notif)

            threshold, transcribed = self.speaker.passiveListen(self.persona)
            if not threshold or not transcribed:
                continue

            input = self.speaker.activeListenToAllOptions(threshold)

            if input:
                self.brain.query(self.profile, transcribed)
开发者ID:saarthaks,项目名称:just-another-AI,代码行数:27,代码来源:conversation.py

示例3: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
class Conversation(object):

    def __init__(self, persona, mic, profile, dispatcherClient):
        self.persona = persona
        self.mic = mic
        self.profile = profile
        self.brain = Brain(mic, profile, dispatcherClient)
        
    def delegateInput(self, text):
        """A wrapper for querying brain."""
        self.brain.query(text)

    def handleForever(self):
        """Delegates user input to the handling function when activated."""
        while True:

            # # Print notifications until empty
            # notifications = self.notifier.getAllNotifications()
            # for notif in notifications:
            #     self.mic.say(notif)

            threshold, transcribed = self.mic.passiveListen(self.persona)
            if not transcribed or not threshold:
                continue

            input = self.mic.activeListen(threshold)
            if input:
                self.delegateInput(input)
            else:
                self.mic.say("Pardon?")
开发者ID:easyNav,项目名称:easyNav-Voice-deprecated-,代码行数:32,代码来源:conversation.py

示例4: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
class Conversation(object):

    def __init__(self, persona, mic, profile, isPassiveEnabled):
        self._logger = logging.getLogger(__name__)
        self.persona = persona
        self.mic = mic
        self.profile = profile
        self.brain = Brain(mic, profile)
        self.notifier = Notifier(profile)
        self.isPassiveEnabled = isPassiveEnabled

    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, passivePhrases = \
                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)

            if self.isPassiveEnabled is True and len(passivePhrases) != 0:

                input = passivePhrases
                self._logger.debug("Checking for passive phrase '%s' with " +
                                   "threshold: %r", input, threshold)

            else:

                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?")
开发者ID:PLockhart,项目名称:jasper-client,代码行数:56,代码来源:conversation.py

示例5: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
class Conversation(object):

    def __init__(self, persona, mic, profile, house):
        self.persona = persona
        self.mic = mic
        self.profile = profile
        self.brain = Brain(mic, profile, house)
        self.notifier = Notifier(profile, house)
        self.house = house

    def delegateInput(self, text):
        """A wrapper for querying brain."""

        # check if input is meant to start the music module
        if any(x in text.upper() for x in ["SPOTIFY", "MUSIC"]):
            # check if mpd client is running
            try:
                client = MPDClient()
                client.timeout = None
                client.idletimeout = None
                client.connect("localhost", 6600)
            except:
                self.mic.say(
                    "I'm sorry. It seems that Spotify is not enabled. Please read the documentation to learn how to configure Spotify.")
                return

            self.mic.say("Please give me a moment, I'm loading your Spotify playlists.")
            music_mode = MusicMode(self.persona, self.mic)
            music_mode.handleForever()
            return

        self.brain.query(text)

    def handleForever(self):
        """Delegates user input to the handling function when activated."""
        while True:

            # Print notifications until empty
            notifications = self.notifier.getAllNotifications()
            for notif in notifications:
                print notif
                self.mic.say(notif)
            try:
                threshold, transcribed = self.mic.passiveListen(self.persona)
            except:
                continue

            if threshold:
                input = self.mic.activeListen(threshold)
                if input:
                    self.delegateInput(input)
                else:
                    self.mic.say("Pardon?")
开发者ID:pyroesque,项目名称:jasper_home_automation,代码行数:55,代码来源:conversation.py

示例6: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)

    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))

            # Word we listen for to self terminate
            TERMINATE = 'GOODBYE'

            self._logger.debug("Started listening for keyword '%s' or '%s'",
                               self.persona, TERMINATE)
            threshold, transcribed = self.mic.passiveListen(self.persona, TERMINATE)
            self._logger.debug("Stopped listening for keyword '%s' or '%s'",
                               self.persona, TERMINATE)

            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)

            # Terminate on goodbye
            if transcribed == TERMINATE:
                friendly.goodbye(self.mic, self.profile)
                sys.exit(0)

            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?")
开发者ID:shaggy8871,项目名称:jasper,代码行数:53,代码来源:conversation.py

示例7: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)

    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 on == True:

            nu()
            # 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:
                messages = ["what?",
                            "what did you say",
                            "Say that again?", "speak the fuck up", "i cant fucking hear you", "blah blah blah", "did you say something?"]

                message = random.choice(messages)
                zip2()
                self.mic.say(message)
开发者ID:DarthToker,项目名称:jasper-client,代码行数:53,代码来源:conversationbac.py

示例8: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)

    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
            try:
                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?")
            except KeyboardInterrupt:
                print "Keyboard Interrupt!"
                try:
                    sys.exit(0)
                except SystemExit:
                    os._exit(0)
开发者ID:dylanjbarth,项目名称:jasper-client,代码行数:52,代码来源:conversation.py

示例9: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
class Conversation(object):
  def __init__(self, persona, mic, server, profile):
    self._logger = logging.getLogger(__name__)
    self.persona = persona
    self.mic = mic
    self.profile = profile
    self.brain = Brain(mic, profile)
    self.notifier = Notifier(profile)
    self.server = server

  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))

      if 'jasper.server.enabled' in self.profile and self.profile['jasper.server.enabled']:
        inputDevice = self.server
        self._logger.debug("Listening to tcp socket with Jasper server")
      else:
        inputDevice = self.mic
        self._logger.debug("Listening to attached microphone")

      self._logger.debug("Started listening for keyword '%s'",
                         self.persona)
      threshold, transcribed = inputDevice.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 = inputDevice.activeListenToAllOptions(threshold)
      self._logger.debug("Stopped to listen actively with threshold: %r",
                         threshold)

      if input:
        self.brain.query(input)
      else:
        inputDevice.say("Pardon?")
开发者ID:anfreita,项目名称:jasper-client,代码行数:52,代码来源:conversation.py

示例10: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)

    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 = []
	    print "entering input"
            input = client.grab_input().strip().split()
            #input = self.mic.activeListenToAllOptions(threshold)
            #self._logger.debug("Stopped to listen actively with threshold: %r",
                              # threshold)
	    print input

            if input:
		print "if entered"
                self.brain.query(input)
            else:
                self.mic.say("Pardon?")
		print "else entered"
开发者ID:devagul93,项目名称:Jarvis-System,代码行数:50,代码来源:conversation.py

示例11: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
class Conversation(object):
    def __init__(self, persona, mic, profile):
        self.persona = persona
        self.mic = mic
        self.profile = profile
        self.brain = Brain(mic, profile)
        # self.notifier = Notifier(profile)

    def delegateInput(self, text):
        """A wrapper for querying brain."""

        # check if input is meant to start the music module

        # if any(x in text.upper() for x in ["SPOTIFY","MUSIC"]):
        #     self.mic.say("Please give me a moment, I'm loading your Spotify playlists.")
        #     music_mode = MusicMode(self.persona, self.mic)
        #     music_mode.handleForever()
        #     return
        if any(x in text.upper() for x in ["EXIT", "QUIT"]):
            exit()

        self.brain.query(text)

    def handleForever(self):
        """Delegates user input to the handling function when activated."""
        while True:

            # Print notifications until empty
            # notifications = self.notifier.getAllNotifications()
            # for notif in notifications:
            #     print notif

            try:
                threshold, transcribed = self.mic.passiveListen(self.persona)
            except:
                continue

            if threshold:
                input = self.mic.activeListen(threshold)
                if input:
                    self.delegateInput(input)
                    if any(x in input.upper() for x in ["EXIT", "QUIT"]):
                        break
                else:
                    self.mic.say("Pardon?")
        exit()
开发者ID:Bohdan-Anderson,项目名称:myJasper,代码行数:48,代码来源:conversation.py

示例12: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)

    def handleForever(self):
        """
        Delegates user input to the handling function when activated.
        """
        self._logger.info("Starting to handle conversation with keyword '%s'.",
                          self.persona)
        
        try_num =0
        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)

            #msg = xbee.Receive()   #this is where we get our serial data during downtime
            if input:
                self.brain.query(input)
            else:
                self.mic.say("Pardon?")
开发者ID:cpatchava,项目名称:brainiac,代码行数:48,代码来源:conversation.py

示例13: Conversation

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [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)
        self.shutdown = False

    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 not self.shutdown:
            # 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)
            self.mic.say(random.choice(["your wish is my command", "what is thy bidding, my master", "I live to serve"]))
            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?")
开发者ID:chriswijones,项目名称:jasper-client,代码行数:47,代码来源:conversation.py

示例14: start

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
def start():
   global Make_Notes, internet_Check
   file = open(jangopath.HOME_DIR + "/ans.txt", 'w+')
   file.close()
   if request.method=='GET':
      res = ""
      return render_template('test.html',res=res)
   else:
      brain = Brain()
      query = request.form['url']
      if bool(re.search('make', query, re.IGNORECASE))==True or bool(re.search('write', query, re.IGNORECASE))==True:
         Make_Notes = 1
         return render_template('test.html',res="What shall I note down?")
      if Make_Notes==1:
         Make_Notes=0
         note.handle(query)
      else:
        brain.query(query)
      f = open(jangopath.HOME_DIR + "/ans.txt",'r')
      res = ""
      line = ""
      while True:
   		line = f.readline()
   		if line:
   			res = res+line
   		else:
   			break
      f.close()
      res = strip_non_ascii(res)
      res = res.replace('\n','')
      res = Markup(res)
      if bool(re.search('search', query, re.IGNORECASE))==True:
         print "1"
         return render_template('test.html',res=res)
      else:
         print "2"
         return render_template('test.html',res2=res)
开发者ID:demo32501,项目名称:Jango,代码行数:39,代码来源:Interactive.py

示例15: handleForever

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import query [as 别名]
def handleForever():
   brain = Brain()
   while True:
      text = raw_input("-> ")
      brain.query(text)
开发者ID:callmeaatrey,项目名称:Jango,代码行数:7,代码来源:conversation.py


注:本文中的brain.Brain.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。