Exemplo n.º 1
0
    def convert(self, message, lang="en"):
        """Convert the text to sound and return this sound.

        :param message: A string containing the message
        :type message: str
        :param lang: The lang to use
        :type lang: str
        :returns: Audio data.
        """
        combined_sound = []

        tempwav = tempfile.NamedTemporaryFile(suffix=".wav")
        tempmp3 = tempfile.NamedTemporaryFile(suffix=".mp3")

        if 'en' in lang:
            language = 'en-US'
        else:
            language = '-'.join([str(lang), str(lang).upper()])
        try:
            commandwav = ['pico2wave', '-w', tempwav.name, '-l', language, '--', message]
            logger.debug("Command used to generate the wav sound : %s in the file %s" % (commandwav, tempwav.name))
            logger.debug(subprocess.check_output(commandwav, stderr=subprocess.STDOUT))
            commandmp3 = ['avconv', '-y', '-f', 'wav', '-i', tempwav.name, '-b:a', '256k', '-f', 'mp3', tempmp3.name]
            logger.debug("Command used to generate the mp3 sound : %s in the file %s" % (commandmp3, tempmp3.name))
            logger.debug(subprocess.check_output(commandmp3, stderr=subprocess.STDOUT))
        except subprocess.CalledProcessError as error:
            logger.error('Problem generating sound')
            logger.debug('Output : %s' % str(error.output))
            return False
        combined_sound.append(tempmp3.read())
        tempwav.close()
        tempmp3.close()
        return b"".join(combined_sound)
Exemplo n.º 2
0
    def send_message(self, message, zone='all', source='api'):
        """Send a text message.

        :param message: A string containing the message
        :type message: str
        :param zone: The zone where the message will be sent
        :type lang: str
        :param source: The zone where the message came from
        :type lang: str
        :returns: True or False.
        :rtype: Boolean
        """
        if not zone:
            zone = 'all'
        lisa_exchange = Exchange('lisa', 'topic', durable=True)
        client_queue = Queue('client', exchange=lisa_exchange, routing_key='client.%s' % zone)

        rabbitmq_creds = {
            'user': config.rabbitmq.user,
            'password': config.rabbitmq.password,
            'host': config.rabbitmq.host,
        }

        with Connection('amqp://{user}:{password}@{host}//'.format(**rabbitmq_creds),
                        transport_options={'confirm_publish': True}) as conn:
            producer = conn.Producer(serializer='json')
            producer.publish({'message': message, 'zone': zone, 'source': source},
                             exchange=lisa_exchange, routing_key='client.%s' % zone,
                             declare=[client_queue])
            logger.debug(msg='Publishing a message on %s, with %s' %
                             ('client.' + zone,
                              {'message': message, 'zone': zone, 'source': source}))
            return True
Exemplo n.º 3
0
def _get_global_plugins():
    r = requests.get('https://raw.githubusercontent.com/project-lisa/lisa/master/lisa-plugins/lisa-plugins.json')
    if r.ok:
        logger.debug('Refreshing plugin list')
        lisa_all_plugins = r.json()
        return lisa_all_plugins
    else:
        return False
Exemplo n.º 4
0
def _get_global_plugins():
    r = requests.get(
        'https://raw.githubusercontent.com/project-lisa/lisa/master/lisa-plugins/lisa-plugins.json'
    )
    if r.ok:
        logger.debug('Refreshing plugin list')
        lisa_all_plugins = r.json()
        return lisa_all_plugins
    else:
        return False
Exemplo n.º 5
0
    def send_message(self, message, zone='all', source='api'):
        """Send a text message.

        :param message: A string containing the message
        :type message: str
        :param zone: The zone where the message will be sent
        :type lang: str
        :param source: The zone where the message came from
        :type lang: str
        :returns: True or False.
        :rtype: Boolean
        """
        if not zone:
            zone = 'all'
        lisa_exchange = Exchange('lisa', 'topic', durable=True)
        client_queue = Queue('client',
                             exchange=lisa_exchange,
                             routing_key='client.%s' % zone)

        rabbitmq_creds = {
            'user': config.rabbitmq.user,
            'password': config.rabbitmq.password,
            'host': config.rabbitmq.host,
        }

        with Connection(
                'amqp://{user}:{password}@{host}//'.format(**rabbitmq_creds),
                transport_options={'confirm_publish': True}) as conn:
            producer = conn.Producer(serializer='json')
            producer.publish(
                {
                    'message': message,
                    'zone': zone,
                    'source': source
                },
                exchange=lisa_exchange,
                routing_key='client.%s' % zone,
                declare=[client_queue])
            logger.debug(msg='Publishing a message on %s, with %s' %
                         ('client.' + zone, {
                             'message': message,
                             'zone': zone,
                             'source': source
                         }))
            return True
Exemplo n.º 6
0
    def convert(self, message, lang="en"):
        """Convert the text to sound and return this sound.

        :param message: A string containing the message
        :type message: str
        :param lang: The lang to use
        :type lang: str
        :returns: Audio data.
        """
        combined_sound = []

        tempwav = tempfile.NamedTemporaryFile(suffix=".wav")
        tempmp3 = tempfile.NamedTemporaryFile(suffix=".mp3")

        if 'en' in lang:
            language = 'en-US'
        else:
            language = '-'.join([str(lang), str(lang).upper()])
        try:
            commandwav = [
                'pico2wave', '-w', tempwav.name, '-l', language, '--', message
            ]
            logger.debug(
                "Command used to generate the wav sound : %s in the file %s" %
                (commandwav, tempwav.name))
            logger.debug(
                subprocess.check_output(commandwav, stderr=subprocess.STDOUT))
            commandmp3 = [
                'avconv', '-y', '-f', 'wav', '-i', tempwav.name, '-b:a',
                '256k', '-f', 'mp3', tempmp3.name
            ]
            logger.debug(
                "Command used to generate the mp3 sound : %s in the file %s" %
                (commandmp3, tempmp3.name))
            logger.debug(
                subprocess.check_output(commandmp3, stderr=subprocess.STDOUT))
        except subprocess.CalledProcessError as error:
            logger.error('Problem generating sound')
            logger.debug('Output : %s' % str(error.output))
            return False
        combined_sound.append(tempmp3.read())
        tempwav.close()
        tempmp3.close()
        return b"".join(combined_sound)
Exemplo n.º 7
0
 def load(self, filenames):
     """Import the configuration from a list of configuration files."""
     logger.debug("Loading files %s" % str(filenames))
     self._filename = filenames
     self.parser.read(filenames)
     self._populate_cache()
Exemplo n.º 8
0
 def load(self, filenames):
     """Import the configuration from a list of configuration files."""
     logger.debug("Loading files %s" % str(filenames))
     self._filename = filenames
     self.parser.read(filenames)
     self._populate_cache()