Exemple #1
0
 def _publish_helper(self, msg):
     msg = decode_vex_message(msg)
     self.chatter.on_next(msg)
     # FIXME: Awkward way to replace the uuid by creating a new vexmessage
     msg = create_vex_message(msg.target, msg.source, self.uuid, **msg.contents)
     self.loop.add_callback(self.subscription_socket.send_multipart, msg)
     self._heartbeat_helper.message_recieved()
Exemple #2
0
 def _send_state(self):
     time_now = time.time()
     delta_time = time_now - self.last_message_time
     if delta_time > 1.5:
         msg = create_vex_message('', self.messaging._service_name, self.messaging.uuid)
         self.messaging.add_callback(self.messaging.subscription_socket.send_multipart, msg)
         self.last_message_time = time_now
Exemple #3
0
    def send_audio(self, target, **contents):
        frame = create_vex_message(target,
                                   'microphone',
                                   'AUDIO',
                                   **contents)

        self.audio_socket.send_multipart(frame)
Exemple #4
0
    def send_response(self, target, **contents):
        frame = create_vex_message(target,
                                   'microphone',
                                   'RSP',
                                   **contents)

        self.publish_socket.send_multipart(frame)
Exemple #5
0
    def send_command(self, target='', **command):
        frame = create_vex_message(target,
                                   self._service_name,
                                   'CMD',
                                   **command)

        self.pub_socket.send_multipart(frame)
Exemple #6
0
    def send_status(self, status, target='', **kwargs):
        frame = create_vex_message(target,
                                   self._service_name,
                                   'STATUS',
                                   status=status,
                                   **kwargs)

        self.pub_socket.send_multipart(frame)
Exemple #7
0
    def send_command(self, text, target=''):
        # FIXME
        frame = create_vex_message(target,
                                   'chatimus',
                                   'CMD',
                                   command=text)

        self.pub_socket.send_multipart(frame)
Exemple #8
0
    def send_status(self, status, target='', **kwargs):
        frame = create_vex_message(target,
                                   self._service_name,
                                   'STATUS',
                                   status=status,
                                   **kwargs)

        self.pub_socket.send_multipart(frame)
Exemple #9
0
    def publish_message(self, service, user, text, target=''):
        # FIXME
        frame = create_vex_message(target,
                                   service,
                                   'MSG',
                                   author=user,
                                   message=text)

        self.pub_socket.send_multipart(frame)
Exemple #10
0
    def publish_message(self, service, user, text, target=''):
        # FIXME
        frame = create_vex_message(target,
                                   service,
                                   'MSG',
                                   author=user,
                                   message=text)

        self.pub_socket.send_multipart(frame)
Exemple #11
0
    def send_chatter(self, target: str = '', from_='', *args, **chatter: dict):
        if from_ == '':
            from_ = self._service_name

        self._messaging_logger.publish.info(' send_chatter to: %s %s', target,
                                            chatter)

        frame = create_vex_message(target, self._service_name, self.uuid,
                                   **chatter)
        self.add_callback(self.subscription_socket.send_multipart, frame)
Exemple #12
0
    def run(self):
        while True:
            frame = self.subscription_socket.recv_multipart()
            msg = decode_vex_message(frame)

            # add one to the counter
            self._counter += 1
            if msg.type == 'MSG':
                # TODO: add in some `None` parsing here
                string = msg.contents.get('message')
                # TODO: move into the classify parser
                # msg = util.clean_text(msg)
                parse_result = []
                for parser in self.parsers:
                    result = parser.parse(string)
                    # TODO: do more complex parsing here
                    # currently just get the first result and stop
                    if result:
                        parse_result.extend(result)
                        break

                for result in parse_result:
                    past_count = self._memory.get(result, 0)
                    # check to see if this was responded to recently and
                    # not respond if so
                    if (self._counter - past_count > 8 or
                            past_count == 0 or
                            string[0] == '!'):

                        keys_to_pop = ['source', 'to', 'response', 'author', 'message']
                        past_msg_content = dict(msg.contents)

                        _pop_helper(past_msg_content, keys_to_pop)

                        # FIXME
                        frame = create_vex_message(msg.source,
                                                   'vexparser',
                                                   'RSP',
                                                   author='Vex',
                                                   to=msg.contents.get('author'),
                                                   response=result,
                                                   **past_msg_content)

                        self.publish_socket.send_multipart(frame)
                        self._memory[result] = self._counter
Exemple #13
0
    def run(self):
        while True:
            frame = self.audio_socket.recv_multipart()
            message = decode_vex_message(frame)
            if message.type == 'AUDIO':
                sample_rate = message.contents['sample_rate']
                sample_width = message.contents['sample_width']
                number_channels = message.contents['number_channels']
                stream_data = message.contents['audio']

                msg = self.speechtotext.get_msg(stream_data,
                                                sample_rate,
                                                sample_width,
                                                number_channels)


                """
                filename = '{}.wav'.format(uuid.uuid4())

                with wave.open(filename, 'wb') as f:
                    f.setnchannels(number_channels)
                    f.setsampwidth(sample_width)
                    f.setframerate(sample_rate)
                    f.writeframes(stream_data)

                logging.error(msg)
                """

                if msg:
                    try:
                        message = msg.get('alternative')[0]['transcript']
                        alternative = msg.get('alternative')
                    except AttributeError:
                        message = msg
                        alternative = None
                    response = create_vex_message('',
                                                  'speechtotext',
                                                  'MSG',
                                                  message=message,
                                                  alternative=alternative)

                    self.publish_socket.send_multipart(response)
                else:
                    pass
Exemple #14
0
    def run(self):
        while True:
            frame = self.audio_socket.recv_multipart()
            message = decode_vex_message(frame)
            if message.type == 'AUDIO':
                sample_rate = message.contents['sample_rate']
                sample_width = message.contents['sample_width']
                number_channels = message.contents['number_channels']
                stream_data = message.contents['audio']

                msg = self.speechtotext.get_msg(stream_data, sample_rate,
                                                sample_width, number_channels)
                """
                filename = '{}.wav'.format(uuid.uuid4())

                with wave.open(filename, 'wb') as f:
                    f.setnchannels(number_channels)
                    f.setsampwidth(sample_width)
                    f.setframerate(sample_rate)
                    f.writeframes(stream_data)

                logging.error(msg)
                """

                if msg:
                    try:
                        message = msg.get('alternative')[0]['transcript']
                        alternative = msg.get('alternative')
                    except AttributeError:
                        message = msg
                        alternative = None
                    response = create_vex_message('',
                                                  'speechtotext',
                                                  'MSG',
                                                  message=message,
                                                  alternative=alternative)

                    self.publish_socket.send_multipart(response)
                else:
                    pass
Exemple #15
0
    def run(self):
        messaging = self.messaging
        # TODO: create better type here
        startup_frame = create_vex_message('',
                                           'microphone',
                                           'STATUS',
                                           status='recording')

        messaging.publish_socket.send_multipart(startup_frame)

        while True:
            # NOTE: `frame` is a list of byte strings
            # Once we recv here, MUST reply in order to loop again!
            try:
                frame = self.messaging.subscribe_socket.recv_multipart()
            except KeyboardInterrupt:
                break

            msg = decode_vex_message(frame)

            if msg.type == 'CMD':
                self.command_manager.handle_command(msg)
Exemple #16
0
 def send_message(self, target='', **msg):
     frame = create_vex_message(target, self._service_name, 'MSG', **msg)
     self.pub_socket.send_multipart(frame)
Exemple #17
0
    def send_audio(self, target, **contents):
        frame = create_vex_message(target, 'microphone', 'AUDIO', **contents)

        self.audio_socket.send_multipart(frame)
Exemple #18
0
    def send_command(self, text, target=''):
        # FIXME
        frame = create_vex_message(target, 'chatimus', 'CMD', command=text)

        self.pub_socket.send_multipart(frame)
Exemple #19
0
 def send_message(self, target='', **msg):
     frame = create_vex_message(target, self._service_name, 'MSG', **msg)
     self.pub_socket.send_multipart(frame)
Exemple #20
0
 def _create_frame(self, type_, target='', **contents):
     return create_vex_message(target, self._service_name, type_,
                               **contents)
Exemple #21
0
 def send_log(self, *args, **kwargs):
     frame = create_vex_message('', self._service_name, self.uuid, **kwargs)
     if self.subscription_socket:
         self.add_callback(self.subscription_socket.send_multipart, frame)
Exemple #22
0
 def _create_frame(self, type, target='', **contents):
     return create_vex_message(target, 'robot', type, **contents)
Exemple #23
0
 def _create_frame(self, type, target='', **contents):
     return create_vex_message(target, 'robot', type, **contents)
Exemple #24
0
    def send_response(self, target, **contents):
        frame = create_vex_message(target, 'microphone', 'RSP', **contents)

        self.publish_socket.send_multipart(frame)
Exemple #25
0
    def send_command(self, target='', **command):
        frame = create_vex_message(target, self._service_name, 'CMD',
                                   **command)

        self.pub_socket.send_multipart(frame)