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


Python Notifier.getAllNotifications方法代码示例

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


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

示例1: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例2: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例3: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例4: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例5: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例6: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例7: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例8: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例9: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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

示例10: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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
        '''

        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)
                else:
                    self.mic.say("Pardon?")
开发者ID:mellonball,项目名称:raz,代码行数:45,代码来源:conversation.py

示例11: Conversation

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

            # Add reveil
            now = datetime.now()

            if now.hour == 8 and now.minute == 35 and now.weekday() < 5:
                self.mic.say("Debout là dedans c'est l'heure")
                self._logger.info("Reveil")
                music = self.getRandomMusic()
                self._logger.debug("Start playing" + music[0])
                call(["mpsyt", "playurl", music[1]])


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

    def getRandomMusic(self, filename=jasperpath.data('text', 'YOUTUBE.txt')):
        youtubeFile = open(filename, "r")
        musics = []
        start = ""
        end = ""
        for line in youtubeFile.readlines():
            line = line.replace("\n", "")

            if start == "":
                start = line
                continue

            if end == "":
                end = line
                continue

            musics.append((start, end))
            start = ""
            end = ""

        musics.append((start, end))
        music = random.choice(musics)
        return music
开发者ID:JeremieSamson,项目名称:jasper,代码行数:80,代码来源:conversation.py

示例12: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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.radioPaused = False

    def determineIntent(self, input):
        if (len(input) == 0):
            return {}
        
        print input[0]
        parameters = {"q" : input[0].lower()}
        r = requests.post('https://api.wit.ai/message?v=20150524',
                      headers={ 'Authorization': 'Bearer TBYTRFCCBMHAKHHDKDCR7JTPMKNSVLOS',
                     'accept': 'application/json'},
                     params=parameters)
                     
        print r.url
        
        try:
            r.raise_for_status()
            text = r.json()['outcomes']
            self._logger.info(len(r.json()["outcomes"]))
        except requests.exceptions.HTTPError:
            self._logger.critical('Request failed with response: %r',
                                  r.text,
                                  exc_info=True)
            return []
        except requests.exceptions.RequestException:
            self._logger.critical('Request failed.', exc_info=True)
            return []
        except ValueError as e:
            self._logger.critical('Cannot parse response: %s',
                                  e.args[0])
            return []
        except KeyError:
            self._logger.critical('Cannot parse response.',
                                  exc_info=True)
            return []
        else:
            transcribed = text[0]
            self._logger.info('Intent: %r', transcribed)
            return transcribed

    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
            
            # Pause the radio
            if House.radioPlaying():
                self.radioPaused = True
                self._logger.info("Pausing radio...")
                House.stopRadio()
            
            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 (len(input) > 1):
                intent = input[1]
                input = [input[0]]
            else:
                intent = self.determineIntent(input)
            
            if input:
                self.brain.query(input,intent)
            else:
                self.mic.say("Pardon?")
            
            # Resume if necessary
            if self.radioPaused == True:
                self.radioPaused = False
                self._logger.info("Resuming radio...")
#.........这里部分代码省略.........
开发者ID:OnlyByGrace,项目名称:jasper-client,代码行数:103,代码来源:conversation.py

示例13: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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 delegateInput(self, texts):
        """A wrapper for querying brain."""

        # check if input is meant to start the music module
        for text in texts:
            if any(x in text.upper() for x in ["SPOTIFY", "MUSIC"]):
                self._logger.debug("Preparing to start music module")
                # check if mpd client is running
                try:
                    client = MPDClient()
                    client.timeout = None
                    client.idletimeout = None
                    client.connect("localhost", 6600)
                except:
                    self._logger.critical("Can't connect to mpd client, cannot start music mode.", exc_info=True)
                    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.")
                self._logger.debug("Starting music mode")
                music_mode = MusicMode(self.persona, self.mic)
                music_mode.handleForever()
                self._logger.debug("Exiting music mode")
                return

        self.brain.query(texts)

    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.delegateInput(input)
            else:
                self.mic.say("Pardon?")
开发者ID:gregnorth,项目名称:jasper-client,代码行数:66,代码来源:conversation.py

示例14: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [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()
开发者ID:fullbright,项目名称:jasper-client,代码行数:65,代码来源:conversation.py

示例15: Conversation

# 需要导入模块: from notifier import Notifier [as 别名]
# 或者: from notifier.Notifier import getAllNotifications [as 别名]
class Conversation(object):

    def __init__(self, persona, mic, profile, pygm):
        self._logger = logging.getLogger(__name__)
        self.persona = persona
        self.mic = mic
        self.pygm = pygm
        self.profile = profile
        self.brain = Brain(mic, profile, pygm)
        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 self.pygm.on == True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    on = False
                if event.type == pygame.KEYDOWN:           
                    if event.key == pygame.K_RIGHT:
                        self.pygm.on = False
                if event.type == pygame.MOUSEBUTTONDOWN:
                    self.pygm.on = False
                    
            self.pygm.blitimg(image, size, black, x, y)   
            # 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.pygm.blittxt('???', 400, red, black)

                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)
                self.mic.say(message)
        pygame.quit()
开发者ID:DarthToker,项目名称:jasper-client,代码行数:65,代码来源:conversation.py


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