Beispiel #1
0
    def callback(self, text):
        """
            callback
        """
        if self.configure_command in text:
            text = TAGGER.get_main_words(text.replace(self.configure_command, ""), lemmatize=True, type_w=["N", "X"])

            # Sorry, only the first noun =P
            # this way we can use complex phrasing and still
            # make it work. Like 'Add a new remote called Balls'
            # And unknown names, as 'Add a new remote called MyBalls'
            # =)

            self.configure_new_remote(text[0])
            self.reload_remotes()
            return

        text = TAGGER.get_main_words(text, lemmatize=True, type_w=["W", "N"])
        for remote, buttons in self.remotes:
            for button in buttons:
                tags = TAGGER.get_main_words(button.split("_"), lemmatize=True, type_w=["W", "N"])
                if tags == text:
                    # And yes, with this code you could accidentally make
                    # make the same button on different remotes
                    # without really realising it... need to make
                    # it into the docs =P
                    self.exec_remote(remote, button)
Beispiel #2
0
    def configure_new_remote(self, remote_name):
        pe = pexpect.check_call("irrecord --ignore-namespace {}".format(LIRC_FILE))
        pe.expect("Don't stop pressing buttons")
        self.caller.tts.say(
            _(
                """We're going to configure your remote now.
                              Reserved words for buttons are cancel and done.
                              Please, keep pressing buttons (a second each)
                              for half a minute, until I tell you to stop."""
            )
        )
        pe.sendline()
        pe.expect("Found")
        self.caller.tts.say(
            _(
                """Please, continue pressing buttons as before, we are almost
                              there"""
            )
        )
        pe.sendline()

        self.caller.tts.say(
            _(
                """You can stop pressing buttons now.
                              Now we're going to record the buttons.
                              When you're finished with them, say done.

                              Tell me the trigger phrase of the first button
                              to configure

                              After each button, I'll tell you what I've
                              recognized.

                              I will interpret everything as close as possible
                              to reality.

                              If I have not correctly recognized your button,
                              you can say cancel to retry.
                              """
            )
        )

        while True:
            action = next(self.caller.stt.text)
            if action == _("cancel"):
                continue
            if action == _("done"):
                pe.sendline()
                pe.sendline()
                break

            tags = TAGGER.get_main_words(action, lemmatize=True, type_w=["W", "N"])

            button = "_".join(tags)

            pe.sendline(button)
            pe.expect("Now hold down")
            self.caller.tts.say(_("""Now press the button"""))

        return subprocess.Popen()