Exemplo n.º 1
0
    def __init__(self):
        """ Create listener for Nabaztag TTS notification
        """
        XplPlugin.__init__(self, name='nbz_tts')
        # Create logger
        self.log.debug("Listener for Nabaztag TTS notification created")

        # Configuration : list of nabaztag whith serial, token and voice
        self.alias_list = {}
        num = 1
        loop = True
        self._config = Query(self.myxpl, self.log)
        while loop == True:
            nabaztag = self._config.query('nbz_tts', 'name-%s' % str(num))
            serial = self._config.query('nbz_tts', 'serial-%s' % str(num))
            token = self._config.query('nbz_tts', 'token-%s' % str(num))
            voice = self._config.query('nbz_tts', 'voice-%s' % str(num))
            if nabaztag != None:
                mess = "Configuration : nabaztag=" + str(
                    nabaztag) + " , serial=" + str(serial) + ", token=" + str(
                        token) + ", voice=" + str(voice)
                self.log.info(mess)
                print(mess)
                self.alias_list[nabaztag] = {
                    "nabaztag": nabaztag,
                    "serial": serial,
                    "token": token,
                    "voice": voice
                }
                num += 1
            else:
                loop = False

        # no nabaztag configured
        if num == 1:
            msg = "No nabaztag configured. Exiting plugin"
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        # Check serial
        for alias in self.alias_list:
            if str(self.alias_list[alias]['serial']) != "None":
                self.log.debug("Serial for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['serial']))
            else:
                self.log.error(
                    "Can't find the serial for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Check token
        for alias in self.alias_list:
            if str(self.alias_list[alias]['token']) != "None":
                self.log.debug("Token for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['token']))
            else:
                self.log.error(
                    "Can't find the Token for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Check voice
        for alias in self.alias_list:
            if str(self.alias_list[alias]['voice']) != "None":
                self.log.debug("Voice for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['voice']))
            else:
                self.log.error(
                    "Can't find the Voice for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Create NBZNotification object
        self.nbz_notification_manager = NBZNotification(self.log)

        # Create listeners
        Listener(self.nbz_notification_cb, self.myxpl, {
            'schema': 'sendmsg.push',
            'xpltype': 'xpl-cmnd'
        })
        self.enable_hbeat()
Exemplo n.º 2
0
    def __init__(self):
        """ Create listener for Nabaztag TTS notification
        """
        XplPlugin.__init__(self, name="nbz_tts")
        # Create logger
        self.log.debug("Listener for Nabaztag TTS notification created")

        # Configuration : list of nabaztag whith serial, token and voice
        self.alias_list = {}
        num = 1
        loop = True
        self._config = Query(self.myxpl, self.log)
        while loop == True:
            nabaztag = self._config.query("nbz_tts", "name-%s" % str(num))
            serial = self._config.query("nbz_tts", "serial-%s" % str(num))
            token = self._config.query("nbz_tts", "token-%s" % str(num))
            voice = self._config.query("nbz_tts", "voice-%s" % str(num))
            if nabaztag != None:
                mess = (
                    "Configuration : nabaztag="
                    + str(nabaztag)
                    + " , serial="
                    + str(serial)
                    + ", token="
                    + str(token)
                    + ", voice="
                    + str(voice)
                )
                self.log.info(mess)
                print(mess)
                self.alias_list[nabaztag] = {"nabaztag": nabaztag, "serial": serial, "token": token, "voice": voice}
                num += 1
            else:
                loop = False

        # no nabaztag configured
        if num == 1:
            msg = "No nabaztag configured. Exiting plugin"
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        # Check serial
        for alias in self.alias_list:
            if str(self.alias_list[alias]["serial"]) != "None":
                self.log.debug(
                    "Serial for nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " is "
                    + str(self.alias_list[alias]["serial"])
                )
            else:
                self.log.error(
                    "Can't find the serial for the nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " , please check the configuration page of this plugin"
                )
                self.force_leave()
                return

        # Check token
        for alias in self.alias_list:
            if str(self.alias_list[alias]["token"]) != "None":
                self.log.debug(
                    "Token for nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " is "
                    + str(self.alias_list[alias]["token"])
                )
            else:
                self.log.error(
                    "Can't find the Token for the nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " , please check the configuration page of this plugin"
                )
                self.force_leave()
                return

        # Check voice
        for alias in self.alias_list:
            if str(self.alias_list[alias]["voice"]) != "None":
                self.log.debug(
                    "Voice for nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " is "
                    + str(self.alias_list[alias]["voice"])
                )
            else:
                self.log.error(
                    "Can't find the Voice for the nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " , please check the configuration page of this plugin"
                )
                self.force_leave()
                return

        # Create NBZNotification object
        self.nbz_notification_manager = NBZNotification(self.log)

        # Create listeners
        Listener(self.nbz_notification_cb, self.myxpl, {"schema": "sendmsg.push", "xpltype": "xpl-cmnd"})
        self.enable_hbeat()
Exemplo n.º 3
0
class NBZNotificationListener(XplPlugin):
    """ Create listener for xPL messages about Nabaztag TTS notification
    """
    def __init__(self):
        """ Create listener for Nabaztag TTS notification
        """
        XplPlugin.__init__(self, name='nbz_tts')
        # Create logger
        self.log.debug("Listener for Nabaztag TTS notification created")

        # Configuration : list of nabaztag whith serial, token and voice
        self.alias_list = {}
        num = 1
        loop = True
        self._config = Query(self.myxpl, self.log)
        while loop == True:
            nabaztag = self._config.query('nbz_tts', 'name-%s' % str(num))
            serial = self._config.query('nbz_tts', 'serial-%s' % str(num))
            token = self._config.query('nbz_tts', 'token-%s' % str(num))
            voice = self._config.query('nbz_tts', 'voice-%s' % str(num))
            if nabaztag != None:
                mess = "Configuration : nabaztag=" + str(
                    nabaztag) + " , serial=" + str(serial) + ", token=" + str(
                        token) + ", voice=" + str(voice)
                self.log.info(mess)
                print(mess)
                self.alias_list[nabaztag] = {
                    "nabaztag": nabaztag,
                    "serial": serial,
                    "token": token,
                    "voice": voice
                }
                num += 1
            else:
                loop = False

        # no nabaztag configured
        if num == 1:
            msg = "No nabaztag configured. Exiting plugin"
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        # Check serial
        for alias in self.alias_list:
            if str(self.alias_list[alias]['serial']) != "None":
                self.log.debug("Serial for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['serial']))
            else:
                self.log.error(
                    "Can't find the serial for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Check token
        for alias in self.alias_list:
            if str(self.alias_list[alias]['token']) != "None":
                self.log.debug("Token for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['token']))
            else:
                self.log.error(
                    "Can't find the Token for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Check voice
        for alias in self.alias_list:
            if str(self.alias_list[alias]['voice']) != "None":
                self.log.debug("Voice for nabaztag " +
                               str(self.alias_list[alias]['nabaztag']) +
                               " is " + str(self.alias_list[alias]['voice']))
            else:
                self.log.error(
                    "Can't find the Voice for the nabaztag " +
                    str(self.alias_list[alias]['nabaztag']) +
                    " , please check the configuration page of this plugin")
                self.force_leave()
                return

        # Create NBZNotification object
        self.nbz_notification_manager = NBZNotification(self.log)

        # Create listeners
        Listener(self.nbz_notification_cb, self.myxpl, {
            'schema': 'sendmsg.push',
            'xpltype': 'xpl-cmnd'
        })
        self.enable_hbeat()

    def nbz_notification_cb(self, message):
        """ Call Nabaztag TTS lib
            @param message : message to send
        """
        self.log.debug("Call nbz_notification_cb")

        # mandatory keys
        if 'to' in message.data:
            to = message.data['to']
            for alias in self.alias_list:
                try:
                    if str(self.alias_list[alias]['nabaztag']) == str(to):
                        serialkey = self.alias_list[alias]['serial']
                        tokenkey = self.alias_list[alias]['token']
                        voicekey = self.alias_list[alias]['voice']
                except:
                    self.log.debug(
                        "Can't find the recipient, please check the configuration page of this plugin"
                    )
                    self.force_leave()
                    return
        else:
            self.log.warning("No recipient was found in the xpl message")
            return

        if 'body' in message.data:
            body = message.data['body']
        else:
            self.log.warning("No message was found in the xpl message")
            return

        self.log.debug("Call send_tts with following parameters : serial=" +
                       serialkey + ", token=" + tokenkey + ", message=" +
                       body + ", voice=" + voicekey)
        self.nbz_notification_manager.send_tts(serialkey, tokenkey, body,
                                               voicekey)
Exemplo n.º 4
0
class NBZNotificationListener(XplPlugin):
    """ Create listener for xPL messages about Nabaztag TTS notification
    """

    def __init__(self):
        """ Create listener for Nabaztag TTS notification
        """
        XplPlugin.__init__(self, name="nbz_tts")
        # Create logger
        self.log.debug("Listener for Nabaztag TTS notification created")

        # Configuration : list of nabaztag whith serial, token and voice
        self.alias_list = {}
        num = 1
        loop = True
        self._config = Query(self.myxpl, self.log)
        while loop == True:
            nabaztag = self._config.query("nbz_tts", "name-%s" % str(num))
            serial = self._config.query("nbz_tts", "serial-%s" % str(num))
            token = self._config.query("nbz_tts", "token-%s" % str(num))
            voice = self._config.query("nbz_tts", "voice-%s" % str(num))
            if nabaztag != None:
                mess = (
                    "Configuration : nabaztag="
                    + str(nabaztag)
                    + " , serial="
                    + str(serial)
                    + ", token="
                    + str(token)
                    + ", voice="
                    + str(voice)
                )
                self.log.info(mess)
                print(mess)
                self.alias_list[nabaztag] = {"nabaztag": nabaztag, "serial": serial, "token": token, "voice": voice}
                num += 1
            else:
                loop = False

        # no nabaztag configured
        if num == 1:
            msg = "No nabaztag configured. Exiting plugin"
            self.log.info(msg)
            print(msg)
            self.force_leave()
            return

        # Check serial
        for alias in self.alias_list:
            if str(self.alias_list[alias]["serial"]) != "None":
                self.log.debug(
                    "Serial for nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " is "
                    + str(self.alias_list[alias]["serial"])
                )
            else:
                self.log.error(
                    "Can't find the serial for the nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " , please check the configuration page of this plugin"
                )
                self.force_leave()
                return

        # Check token
        for alias in self.alias_list:
            if str(self.alias_list[alias]["token"]) != "None":
                self.log.debug(
                    "Token for nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " is "
                    + str(self.alias_list[alias]["token"])
                )
            else:
                self.log.error(
                    "Can't find the Token for the nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " , please check the configuration page of this plugin"
                )
                self.force_leave()
                return

        # Check voice
        for alias in self.alias_list:
            if str(self.alias_list[alias]["voice"]) != "None":
                self.log.debug(
                    "Voice for nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " is "
                    + str(self.alias_list[alias]["voice"])
                )
            else:
                self.log.error(
                    "Can't find the Voice for the nabaztag "
                    + str(self.alias_list[alias]["nabaztag"])
                    + " , please check the configuration page of this plugin"
                )
                self.force_leave()
                return

        # Create NBZNotification object
        self.nbz_notification_manager = NBZNotification(self.log)

        # Create listeners
        Listener(self.nbz_notification_cb, self.myxpl, {"schema": "sendmsg.push", "xpltype": "xpl-cmnd"})
        self.enable_hbeat()

    def nbz_notification_cb(self, message):
        """ Call Nabaztag TTS lib
            @param message : message to send
        """
        self.log.debug("Call nbz_notification_cb")

        # mandatory keys
        if "to" in message.data:
            to = message.data["to"]
            for alias in self.alias_list:
                try:
                    if str(self.alias_list[alias]["nabaztag"]) == str(to):
                        serialkey = self.alias_list[alias]["serial"]
                        tokenkey = self.alias_list[alias]["token"]
                        voicekey = self.alias_list[alias]["voice"]
                except:
                    self.log.debug("Can't find the recipient, please check the configuration page of this plugin")
                    self.force_leave()
                    return
        else:
            self.log.warning("No recipient was found in the xpl message")
            return

        if "body" in message.data:
            body = message.data["body"]
        else:
            self.log.warning("No message was found in the xpl message")
            return

        self.log.debug(
            "Call send_tts with following parameters : serial="
            + serialkey
            + ", token="
            + tokenkey
            + ", message="
            + body
            + ", voice="
            + voicekey
        )
        self.nbz_notification_manager.send_tts(serialkey, tokenkey, body, voicekey)