Exemple #1
0
def main():
    global ws
    global config
    global pulse
    ws = WebsocketClient()
    ConfigurationManager.init(ws)
    config = ConfigurationManager.get()
    speech.init(ws)

    # Setup control of pulse audio
    if pulsectl and config.get('Audio').get('pulseaudio') == 'mute':
        pulse = pulsectl.Pulse('Mycroft-audio-service')
    else:
        pulse = None

    def echo(message):
        try:
            _message = json.loads(message)

            if 'mycroft.audio.service' in _message.get('type'):
                return
            message = json.dumps(_message)
        except:
            pass
        logger.debug(message)

    logger.info("Staring Audio Services")
    ws.on('message', echo)
    ws.once('open', load_services_callback)
    try:
        ws.run_forever()
    except KeyboardInterrupt, e:
        logger.exception(e)
        speech.shutdown()
        sys.exit()
Exemple #2
0
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping):
    """Start the Audio Service and connect to the Message Bus"""
    LOG.info("Starting Audio Service")
    try:
        reset_sigint_handler()
        check_for_signal("isSpeaking")
        whitelist = ['mycroft.audio.service']
        bus = start_message_bus_client("AUDIO", whitelist=whitelist)
        callbacks = StatusCallbackMap(on_ready=ready_hook,
                                      on_error=error_hook,
                                      on_stopping=stopping_hook)
        status = ProcessStatus('audio', bus, callbacks)

        speech.init(bus)

        # Connect audio service instance to message bus
        audio = AudioService(bus)
        status.set_started()
    except Exception as e:
        status.set_error(e)
    else:
        if audio.wait_for_load() and len(audio.service) > 0:
            # If at least one service exists, report ready
            status.set_ready()
            wait_for_exit_signal()
            status.set_stopping()
        else:
            status.set_error('No audio services loaded')

        speech.shutdown()
        audio.shutdown()
Exemple #3
0
def main():
    """ Main function. Run when file is invoked. """
    ws = WebsocketClient()
    Configuration.init(ws)
    speech.init(ws)

    def echo(message):
        """ Echo message bus messages. """
        try:
            _message = json.loads(message)
            if 'mycroft.audio.service' not in _message.get('type'):
                return
            message = json.dumps(_message)
        except Exception as e:
            LOG.exception(e)
        LOG.debug(message)

    LOG.info("Staring Audio Services")
    ws.on('message', echo)
    AudioService(ws)  # Connect audio service instance to message bus
    try:
        ws.run_forever()
    except KeyboardInterrupt as e:
        LOG.exception(e)
        speech.shutdown()
        sys.exit()
Exemple #4
0
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping):
    """ Main function. Run when file is invoked. """
    try:
        reset_sigint_handler()
        check_for_signal("isSpeaking")
        bus = MessageBusClient()  # Connect to the Mycroft Messagebus
        Configuration.set_config_update_handlers(bus)
        speech.init(bus)

        LOG.info("Starting Audio Services")
        bus.on('message',
               create_echo_function('AUDIO', ['mycroft.audio.service']))

        # Connect audio service instance to message bus
        audio = AudioService(bus)
    except Exception as e:
        error_hook(e)
    else:
        create_daemon(bus.run_forever)
        if audio.wait_for_load() and len(audio.service) > 0:
            # If at least one service exists, report ready
            ready_hook()
            wait_for_exit_signal()
            stopping_hook()
        else:
            error_hook('No audio services loaded')

        speech.shutdown()
        audio.shutdown()
Exemple #5
0
def main():
    global ws
    global config
    ws = WebsocketClient()
    Configuration.init(ws)
    config = Configuration.get()
    speech.init(ws)

    # Setup control of pulse audio
    setup_pulseaudio_handlers(config.get('Audio').get('pulseaudio'))

    def echo(message):
        try:
            _message = json.loads(message)
            if 'mycroft.audio.service' not in _message.get('type'):
                return
            message = json.dumps(_message)
        except:
            pass
        LOG.debug(message)

    LOG.info("Staring Audio Services")
    ws.on('message', echo)
    ws.once('open', load_services_callback)
    try:
        ws.run_forever()
    except KeyboardInterrupt, e:
        LOG.exception(e)
        speech.shutdown()
        sys.exit()
def main():
    global ws
    global config
    ws = WebsocketClient()
    ConfigurationManager.init(ws)
    config = ConfigurationManager.get()
    speech.init(ws)

    # Setup control of pulse audio
    setup_pulseaudio_handlers(config.get('Audio').get('pulseaudio'))

    def echo(message):
        try:
            _message = json.loads(message)
            if 'mycroft.audio.service' not in _message.get('type'):
                return
            message = json.dumps(_message)
        except:
            pass
        LOG.debug(message)

    LOG.info("Staring Audio Services")
    ws.on('message', echo)
    ws.once('open', load_services_callback)
    try:
        ws.run_forever()
    except KeyboardInterrupt, e:
        LOG.exception(e)
        speech.shutdown()
        sys.exit()
Exemple #7
0
    def test_life_cycle(self, tts_factory_mock, config_mock):
        """Ensure the init and shutdown behaves as expected."""
        setup_mocks(config_mock, tts_factory_mock)
        bus = mock.Mock()
        speech.init(bus)

        self.assertTrue(tts_factory_mock.create.called)
        bus.on.assert_any_call('mycroft.stop', speech.handle_stop)
        bus.on.assert_any_call('mycroft.audio.speech.stop', speech.handle_stop)
        bus.on.assert_any_call('speak', speech.handle_speak)

        speech.shutdown()
        self.assertTrue(tts_mock.playback.stop.called)
        self.assertTrue(tts_mock.playback.join.called)
    def test_speak(self, tts_factory_mock, config_mock):
        """Ensure the speech handler executes the tts."""
        setup_mocks(config_mock, tts_factory_mock)
        bus = mock.Mock()
        speech.init(bus)

        speak_msg = Message('speak',
                            data={'utterance': 'hello there. world',
                                  'listen': False},
                            context={'ident': 'a'})
        speech.handle_speak(speak_msg)
        tts_mock.execute.assert_has_calls(
                [mock.call('hello there.', 'a', False),
                 mock.call('world', 'a', False)])
Exemple #9
0
    def test_stop(self, check_for_signal_mock, tts_factory_mock, config_mock):
        """Ensure the stop handler signals stop correctly."""
        setup_mocks(config_mock, tts_factory_mock)
        bus = mock.Mock()
        config_mock.get.return_value = {'tts': {'module': 'test'}}
        speech.init(bus)

        speech._last_stop_signal = 0
        check_for_signal_mock.return_value = False
        speech.handle_stop(Message('mycroft.stop'))
        self.assertEqual(speech._last_stop_signal, 0)

        check_for_signal_mock.return_value = True
        speech.handle_stop(Message('mycroft.stop'))
        self.assertNotEqual(speech._last_stop_signal, 0)
Exemple #10
0
def main():
    """ Main function. Run when file is invoked. """
    reset_sigint_handler()
    ws = WebsocketClient()
    Configuration.init(ws)
    speech.init(ws)

    LOG.info("Starting Audio Services")
    ws.on('message', create_echo_function('AUDIO', ['mycroft.audio.service']))
    audio = AudioService(ws)  # Connect audio service instance to message bus
    create_daemon(ws.run_forever)

    wait_for_exit_signal()

    speech.shutdown()
    audio.shutdown()
Exemple #11
0
    def test_speak_picroft(self, tts_factory_mock, config_mock):
        """Ensure that picroft doesn't split the sentence."""
        setup_mocks(config_mock, tts_factory_mock)
        bus = mock.Mock()
        config_mock.get.return_value = {'enclosure': {'platform': 'picroft'}}
        speech.init(bus)

        speak_msg = Message('speak',
                            data={'utterance': 'hello there. world',
                                  'listen': False},
                            context={'ident': 'a'})
        speech.handle_speak(speak_msg)
        tts_mock.execute.assert_has_calls(
                [mock.call('hello there. world', 'a', False)])

        config_mock.get.return_value = {}
Exemple #12
0
def main():
    """ Main function. Run when file is invoked. """
    reset_sigint_handler()
    check_for_signal("isSpeaking")
    bus = WebsocketClient()  # Connect to the Mycroft Messagebus
    Configuration.init(bus)
    speech.init(bus)

    LOG.info("Starting Audio Services")
    bus.on('message', create_echo_function('AUDIO', ['mycroft.audio.service']))
    audio = AudioService(bus)  # Connect audio service instance to message bus
    create_daemon(bus.run_forever)

    wait_for_exit_signal()

    speech.shutdown()
    audio.shutdown()
def main():
    """ Main function. Run when file is invoked. """
    reset_sigint_handler()
    check_for_signal("isSpeaking")
    bus = MessageBusClient()  # Connect to the Mycroft Messagebus
    Configuration.set_config_update_handlers(bus)
    speech.init(bus)

    LOG.info("Starting Audio Services")
    bus.on('message', create_echo_function('AUDIO', ['mycroft.audio.service']))
    audio = AudioService(bus)  # Connect audio service instance to message bus
    create_daemon(bus.run_forever)

    wait_for_exit_signal()

    speech.shutdown()
    audio.shutdown()
Exemple #14
0
    def test_speak_update_tts(self, tts_factory_mock, config_mock):
        """Verify that a new config triggers reload of tts."""
        setup_mocks(config_mock, tts_factory_mock)
        bus = mock.Mock()
        config_mock.get.return_value = {'tts': {'module': 'test'}}
        speech.init(bus)
        tts_factory_mock.create.reset_mock()
        speak_msg = Message('speak',
                            data={'utterance': 'hello there. world',
                                  'listen': False},
                            context={'ident': 'a'})
        speech.handle_speak(speak_msg)
        self.assertFalse(tts_factory_mock.create.called)

        speech.config = {'tts': {'module': 'test2'}}
        speech.handle_speak(speak_msg)
        self.assertTrue(tts_factory_mock.create.called)
Exemple #15
0
    def test_speak_errorsound_global_conf(self, tts_factory_mock, config_mock):
        """Ensure the speech handler executes the error sound instead of
        the utterance."""
        setup_mocks(config_mock, tts_factory_mock)
        bus = mock.Mock()
        speech.init(bus)
        config_mock.get.return_value = {'error_as_sound': True}

        speak_msg = Message('speak',
                            data={
                                'utterance': 'hello there. world',
                                'listen': False,
                                'is_error': True
                            },
                            context={'ident': 'a'})
        speech.handle_speak(speak_msg)
        tts_mock.execute.assert_has_calls(
            [mock.call('hello there. world', 'a', False, True)])
Exemple #16
0
    def test_fallback_tts(self, mimic_cls_mock, tts_factory_mock, config_mock):
        """Ensure the fallback tts is triggered if the remote times out."""
        setup_mocks(config_mock, tts_factory_mock)
        mimic_mock = mock.Mock()
        mimic_cls_mock.return_value = mimic_mock

        tts = tts_factory_mock.create.return_value
        tts.execute.side_effect = speech.RemoteTTSTimeoutException

        bus = mock.Mock()
        speech.init(bus)

        speak_msg = Message('speak',
                            data={'utterance': 'hello there. world',
                                  'listen': False},
                            context={'ident': 'a'})
        speech.handle_speak(speak_msg)
        mimic_mock.execute.assert_has_calls(
                [mock.call('hello there.', 'a', False),
                 mock.call('world', 'a', False)])
Exemple #17
0
    def test_abort_speak(self, check_for_signal_mock, tts_factory_mock,
                         config_mock):
        """Ensure the speech handler aborting speech on stop signal."""
        setup_mocks(config_mock, tts_factory_mock)
        check_for_signal_mock.return_value = True
        tts = tts_factory_mock.create.return_value

        def execute_trigger_stop():
            speech.handle_stop(None)

        tts.execute.side_effect = execute_trigger_stop

        bus = mock.Mock()
        speech.init(bus)

        speak_msg = Message('speak',
                            data={'utterance': 'hello there. world',
                                  'listen': False},
                            context={'ident': 'a'})
        speech.handle_speak(speak_msg)
        self.assertTrue(tts.playback.clear.called)
def main():
    rospy.init_node('mycroft_tts')
    rospy.loginfo(rospy.get_caller_id() + " started")
    rospy.Subscriber("mycroft/speak", String, handle_speak)
    rospy.Subscriber("mycroft/stop", String, handle_stop)
    """ Main function. Run when file is invoked. """
    global bus
    reset_sigint_handler()
    check_for_signal("isSpeaking")
    bus = WebsocketClient()  # Connect to the Mycroft Messagebus
    Configuration.init(bus)
    speech.init(bus)

    LOG.info("Starting Audio Services")
    bus.on('message', create_echo_function('AUDIO', ['mycroft.audio.service']))
    audio = AudioService(bus)  # Connect audio service instance to message bus
    create_daemon(bus.run_forever)

    wait_for_exit_signal()

    speech.shutdown()
    audio.shutdown()
    # keep node running
    rospy.spin()