def main(): rospy.init_node('mycroft_message_bus') rospy.loginfo(rospy.get_caller_id() + " started") import tornado.options reset_sigint_handler() lock = Lock("service") tornado.options.parse_command_line() def reload_hook(): """ Hook to release lock when autoreload is triggered. """ lock.delete() autoreload.add_reload_hook(reload_hook) config = Configuration.get().get("websocket") host = config.get("host") port = config.get("port") route = config.get("route") validate_param(host, "websocket.host") validate_param(port, "websocket.port") validate_param(route, "websocket.route") routes = [(route, WebsocketEventHandler)] application = web.Application(routes, **settings) application.listen(port, host) create_daemon(ioloop.IOLoop.instance().start) wait_for_exit_signal() rospy.spin()
def before_all(context): log = create_voight_kampff_logger() bus = InterceptAllBusClient() bus_connected = Event() bus.once('open', bus_connected.set) create_daemon(bus.run_forever) context.msm = MycroftSkillsManager() # Wait for connection log.info('Waiting for messagebus connection...') bus_connected.wait() log.info('Waiting for skills to be loaded...') start = monotonic() while True: response = bus.wait_for_response(Message('mycroft.skills.all_loaded')) if response and response.data['status']: break elif monotonic() - start >= 2 * 60: raise Exception('Timeout waiting for skills to become ready.') else: sleep(1) context.bus = bus context.matched_message = None context.log = log
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): global bus global loop global config try: reset_sigint_handler() PIDLock("voice") config = Configuration.get() bus = start_message_bus_client("VOICE") connect_bus_events(bus) callbacks = StatusCallbackMap(on_ready=ready_hook, on_error=error_hook, on_stopping=stopping_hook) status = ProcessStatus('speech', bus, callbacks) # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop(watchdog) connect_loop_events(loop) create_daemon(loop.run) status.set_started() except Exception as e: error_hook(e) else: status.set_ready() wait_for_exit_signal() status.set_stopping()
def main(): global ws global loop reset_sigint_handler() PIDLock("voice") ws = WebsocketClient() Configuration.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:speech.recognition.unknown', handle_unknown) loop.on('speak', handle_speak) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:awoken', handle_awoken) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:no_internet', handle_no_internet) ws.on('open', handle_open) ws.on('complete_intent_failure', handle_complete_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.mic.mute', handle_mic_mute) ws.on('mycroft.mic.unmute', handle_mic_unmute) ws.on('mycroft.mic.get_status', handle_mic_get_status) ws.on("mycroft.paired", handle_paired) ws.on('recognizer_loop:audio_output_start', handle_audio_start) ws.on('recognizer_loop:audio_output_end', handle_audio_end) ws.on('mycroft.stop', handle_stop) create_daemon(ws.run_forever) create_daemon(loop.run) wait_for_exit_signal()
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping): # Read the system configuration """Launch one of the available enclosure implementations. This depends on the configured platform and can currently either be mycroft_mark_1 or mycroft_mark_2, if unconfigured a generic enclosure with only the GUI bus will be started. """ # Read the system configuration system_config = LocalConf(SYSTEM_CONFIG) platform = system_config.get("enclosure", {}).get("platform") enclosure = create_enclosure(platform) if enclosure: try: LOG.debug("Enclosure started!") reset_sigint_handler() create_daemon(enclosure.run) ready_hook() wait_for_exit_signal() stopping_hook() except Exception as e: print(e) else: LOG.info("No enclosure available for this hardware, running headless")
def listener(): rospy.init_node('mycroft_skills') rospy.loginfo(rospy.get_caller_id() + " started") rospy.Subscriber("mycroft/utterance", String, handle_utterance) rospy.Subscriber("mycroft/remove_skill", String, handle_remove_skill) s = rospy.Service('mycroft/register_skill', MycroftService, handle_register_skill) global bus reset_sigint_handler() # Create PID file, prevent multiple instancesof this service mycroft.lock.Lock('skills') # Connect this Skill management process to the Mycroft Messagebus bus = WebsocketClient() Configuration.init(bus) config = Configuration.get() # Set the active lang to match the configured one set_active_lang(config.get('lang', 'en-us')) bus.on('skill.manager.initialised', initialise_response_server) bus.on('message', create_echo_function('SKILLS')) # Startup will be called after the connection with the Messagebus is done bus.once('open', _starting_up) bus.on('skill.converse.request', check_working) create_daemon(bus.run_forever) wait_for_exit_signal() shutdown() rospy.spin()
def main(): import tornado.options reset_sigint_handler() lock = Lock("service") tornado.options.parse_command_line() def reload_hook(): """ Hook to release lock when autoreload is triggered. """ lock.delete() autoreload.add_reload_hook(reload_hook) config = Configuration.get().get("websocket") host = config.get("host") port = config.get("port") route = config.get("route") validate_param(host, "websocket.host") validate_param(port, "websocket.port") validate_param(route, "websocket.route") routes = [ (route, WebsocketEventHandler) ] application = web.Application(routes, **settings) application.listen(port, host) create_daemon(ioloop.IOLoop.instance().start) wait_for_exit_signal()
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()
def __init__(self): super(HelioViewerSkill, self).__init__(name="HelioViewerSkill") self.session = CachedSession(backend='memory', expire_after=timedelta(hours=6)) self.translate_cache = {} # save calls to avoid ip banning self.img_cache = {} # dont re-parse for speed self.current_date = datetime.now() self.current_camera = "sunspots" create_daemon(self.bootstrap)
def initialize(self): self.settings.set_changed_callback(self.handle_settings_changed) if "hotwords" not in self.settings: self.settings["hotwords"] = {} self.kaldi = KaldiWWSpotter() self.kaldi.on("hotword", self.handle_hotword) for hw in self.settings["hotwords"]: self.kaldi.add_hotword(hw, self.settings["hotwords"][hw]) create_daemon(self.kaldi.run)
def main(): global ws ws = WebsocketClient() Configuration.init(ws) create_daemon(ws.run_forever) if proximity_enabled: BT_Scanner() wait_for_exit_signal()
def create_gui_service(enclosure, config): import tornado.options LOG.info('Starting message bus for GUI...') # Disable all tornado logging so mycroft loglevel isn't overridden tornado.options.parse_command_line(['--logging=None']) routes = [(config['route'], GUIWebsocketHandler)] application = web.Application(routes, debug=True) application.enclosure = enclosure application.listen(config['base_port'], config['host']) create_daemon(ioloop.IOLoop.instance().start) LOG.info('GUI Message bus started!') return application
def __init__(self): super(HubbleTelescopeSkill, self).__init__(name="HubbleTelescopeSkill") if "random" not in self.settings: # idle screen, random or latest self.settings["random"] = True if "include_james_webb" not in self.settings: self.settings["include_james_webb"] = False if "exclude_long" not in self.settings: self.settings["exclude_long"] = True self.session = CachedSession(backend='memory', expire_after=timedelta(hours=6)) self.translate_cache = {} # bootstrap - cache image data create_daemon(self.latest_hubble)
def _start_message_bus_client(): """Start the bus client daemon and wait for connection.""" bus = MessageBusClient() Configuration.set_config_update_handlers(bus) bus_connected = Event() bus.on('message', create_echo_function('SKILLS')) # Set the bus connected event when connection is established bus.once('open', bus_connected.set) create_daemon(bus.run_forever) # Wait for connection bus_connected.wait() LOG.info('Connected to messagebus') return bus
def main(): global bus reset_sigint_handler() # Create PID file, prevent multiple instancesof this service mycroft.lock.Lock('skills') # Connect this Skill management process to the Mycroft Messagebus bus = WebsocketClient() Configuration.init(bus) bus.on('message', create_echo_function('SKILLS')) # Startup will be called after the connection with the Messagebus is done bus.once('open', _starting_up) create_daemon(bus.run_forever) wait_for_exit_signal() shutdown()
def main(): global bus reset_sigint_handler() # Create PID file, prevent multiple instancesof this service mycroft.lock.Lock('skills') # Connect this Skill management process to the Mycroft Messagebus bus = WebsocketClient() Configuration.init(bus) bus.on('message', create_echo_function('SKILLS')) # Startup will be called after the connection with the Messagebus is done bus.once('open', _starting_up) create_daemon(bus.run_forever) wait_for_exit_signal() shutdown()
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()
def initialize(self): self.register_fallback(self.handle_fallback, int(self.settings["priority"])) self._converse_keepalive = create_daemon(self.converse_keepalive) say_voc = self.find_resource('and_say.voc', 'vocab') if say_voc: # load vocab and flatten into a simple list # TODO sort by length self.say_vocab = list(chain(*read_vocab_file(say_voc))) self.start_sip() if self.settings["sipxcom_sync"]: self.sipxcom_sync() # Register GUI Events self.handle_gui_state("Clear") self.gui.register_handler("voip.jarbas.acceptCall", self.accept_call) self.gui.register_handler("voip.jarbas.hangCall", self.hang_call) self.gui.register_handler("voip.jarbas.muteCall", self.mute_call) self.gui.register_handler("voip.jarbas.unmuteCall", self.unmute_call) self.gui.register_handler("voip.jarbas.callContact", self.handle_call_contact_from_gui) self.gui.register_handler("voip.jarbas.updateConfig", self.handle_config_from_gui) self.add_event('skill--voip.jarbasskills.home', self.show_homescreen)
def __init__(self, id, config, callback_disconnect, enclosure): LOG.debug("Creating GUIConnection") self.id = id self.socket = None self.callback_disconnect = callback_disconnect self.enclosure = enclosure # Each connection will run its own Tornado server. If the # connection drops, the server is killed. websocket_config = config.get("gui_websocket") host = websocket_config.get("host") route = websocket_config.get("route") base_port = websocket_config.get("base_port") while True: self.port = base_port + GUIConnection._last_idx GUIConnection._last_idx += 1 try: self.webapp = tornado.web.Application( [(route, GUIWebsocketHandler)], **gui_app_settings) # Hacky way to associate socket with this object: self.webapp.gui = self self.webapp.listen(self.port, host) except Exception as e: LOG.debug('Error: {}'.format(repr(e))) continue break # Can't run two IOLoop's in the same process if not GUIConnection.server_thread: GUIConnection.server_thread = create_daemon( ioloop.IOLoop.instance().start) LOG.debug('IOLoop started @ ' 'ws://{}:{}{}'.format(host, self.port, route))
def __init__(self, id, config, callback_disconnect, enclosure): LOG.debug("Creating GUIConnection") self.id = id self.socket = None self.callback_disconnect = callback_disconnect self.enclosure = enclosure # Each connection will run its own Tornado server. If the # connection drops, the server is killed. websocket_config = config.get("gui_websocket") host = websocket_config.get("host") route = websocket_config.get("route") base_port = websocket_config.get("base_port") while True: self.port = base_port + GUIConnection._last_idx GUIConnection._last_idx += 1 try: self.webapp = tornado.web.Application( [(route, GUIWebsocketHandler)], **gui_app_settings ) # Hacky way to associate socket with this object: self.webapp.gui = self self.webapp.listen(self.port, host) except Exception as e: LOG.debug('Error: {}'.format(repr(e))) continue break # Can't run two IOLoop's in the same process if not GUIConnection.server_thread: GUIConnection.server_thread = create_daemon( ioloop.IOLoop.instance().start) LOG.debug('IOLoop started @ ' 'ws://{}:{}{}'.format(host, self.port, route))
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()
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 initialize(self): self.register_fallback(self.handle_fallback, int(self.settings["priority"])) self._converse_keepalive = create_daemon(self.converse_keepalive) say_voc = self.find_resource('and_say.voc', 'vocab') if say_voc: # load vocab and flatten into a simple list self.say_vocab = list(chain(*read_vocab_file(say_voc))) self.start_sip()
def main(): import tornado.options LOG.info('Starting message bus service...') reset_sigint_handler() lock = Lock("service") # Disable all tornado logging so mycroft loglevel isn't overridden tornado.options.parse_command_line(sys.argv + ['--logging=None']) def reload_hook(): """ Hook to release lock when auto reload is triggered. """ lock.delete() autoreload.add_reload_hook(reload_hook) config = load_message_bus_config() routes = [(config.route, MessageBusEventHandler)] application = web.Application(routes, debug=True) application.listen(config.port, config.host) create_daemon(ioloop.IOLoop.instance().start) LOG.info('Message bus service started!') wait_for_exit_signal()
def __init__(self, id, config, callback_disconnect, enclosure): DEBUG("Creating GUIConnection") self.id = id self.socket = None self.callback_disconnect = callback_disconnect self.enclosure = enclosure self._active_namespaces = None # This datastore holds the data associated with the GUI provider. Data # is stored in Namespaces, so you can have: # self.datastore["namespace"]["name"] = value # Typically the namespace is a meaningless identifier, but there is a # special "SYSTEM" namespace. self.datastore = {} self.current_namespace = None self.current_pages = [] self.current_index = None # self.loaded is a list, each element consists of a namespace named # tuple. # The namespace namedtuple has the properties "name" and "pages" # The name contains the namespace name as a string and pages is a # mutable list of loaded pages. # # [Namespace name, [List of loaded qml pages]] # [ # ["SKILL_NAME", ["page1.qml, "page2.qml", ... , "pageN.qml"] # [...] # ] self.loaded = [] # list of lists in order. self.explicit_move = True # Set to true to send reorder commands # Each connection will run its own Tornado server. If the # connection drops, the server is killed. websocket_config = config.get("gui_websocket") host = websocket_config.get("host") route = websocket_config.get("route") self.port = websocket_config.get("base_port") + GUIConnection._last_idx GUIConnection._last_idx += 1 try: self.webapp = tornado.web.Application([ (route, GUIWebsocketHandler) ], **gui_app_settings) self.webapp.gui = self # Hacky way to associate socket with this self.webapp.listen(self.port, host) except Exception as e: DEBUG('Error: {}'.format(repr(e))) # Can't run two IOLoop's in the same process if not GUIConnection.server_thread: GUIConnection.server_thread = create_daemon( ioloop.IOLoop.instance().start) DEBUG("IOLoop started @ ws://{}:{}{}".format(host, self.port, route))
def main(): rospy.init_node('mycroft_stt') rospy.loginfo(rospy.get_caller_id() + " started") global bus global loop global config reset_sigint_handler() PIDLock("voice") bus = WebsocketClient() # Mycroft messagebus, see mycroft.messagebus Configuration.init(bus) config = Configuration.get() # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:speech.recognition.unknown', handle_unknown) loop.on('speak', handle_speak) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:awoken', handle_awoken) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:no_internet', handle_no_internet) # Register handlers for events on main Mycroft messagebus bus.on('open', handle_open) bus.on('complete_intent_failure', handle_complete_intent_failure) bus.on('recognizer_loop:sleep', handle_sleep) bus.on('recognizer_loop:wake_up', handle_wake_up) bus.on('mycroft.mic.mute', handle_mic_mute) bus.on('mycroft.mic.unmute', handle_mic_unmute) bus.on('mycroft.mic.get_status', handle_mic_get_status) bus.on("mycroft.paired", handle_paired) bus.on('recognizer_loop:audio_output_start', handle_audio_start) bus.on('recognizer_loop:audio_output_end', handle_audio_end) bus.on('mycroft.stop', handle_stop) create_daemon(bus.run_forever) create_daemon(loop.run) wait_for_exit_signal() rospy.spin()
def main(): global bus global loop global config reset_sigint_handler() PIDLock("voice") bus = WebsocketClient() # Mycroft messagebus, see mycroft.messagebus Configuration.init(bus) config = Configuration.get() # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:speech.recognition.unknown', handle_unknown) loop.on('speak', handle_speak) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:awoken', handle_awoken) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:no_internet', handle_no_internet) # Register handlers for events on main Mycroft messagebus bus.on('open', handle_open) bus.on('complete_intent_failure', handle_complete_intent_failure) bus.on('recognizer_loop:sleep', handle_sleep) bus.on('recognizer_loop:wake_up', handle_wake_up) bus.on('mycroft.mic.mute', handle_mic_mute) bus.on('mycroft.mic.unmute', handle_mic_unmute) bus.on('mycroft.mic.get_status', handle_mic_get_status) bus.on("mycroft.paired", handle_paired) bus.on('recognizer_loop:audio_output_start', handle_audio_start) bus.on('recognizer_loop:audio_output_end', handle_audio_end) bus.on('mycroft.stop', handle_stop) create_daemon(bus.run_forever) create_daemon(loop.run) wait_for_exit_signal()
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()
def before_all(context): log = create_voight_kampff_logger() bus = InterceptAllBusClient() bus_connected = Event() bus.once('open', bus_connected.set) create_daemon(bus.run_forever) context.msm = MycroftSkillsManager() # Wait for connection log.info('Waiting for messagebus connection...') bus_connected.wait() log.info('Waiting for skills to be loaded...') start = monotonic() while True: response = bus.wait_for_response(Message('mycroft.skills.all_loaded')) if response and response.data['status']: break elif monotonic() - start >= 2 * 60: raise Exception('Timeout waiting for skills to become ready.') else: sleep(1) # Temporary bugfix - First test to run sometimes fails # Sleeping to see if something isn't finished setting up when tests start # More info in Jira Ticket MYC-370 # TODO - remove and fix properly dependant on if failures continue sleep(10) context.bus = bus context.matched_message = None context.log = log context.original_config = {} context.config = Configuration.get() Configuration.set_config_update_handlers(bus)
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): global bus global loop global config try: reset_sigint_handler() PIDLock("voice") bus = MessageBusClient() # Mycroft messagebus, see mycroft.messagebus Configuration.set_config_update_handlers(bus) config = Configuration.get() # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop(watchdog) connect_loop_events(loop) connect_bus_events(bus) create_daemon(bus.run_forever) create_daemon(loop.run) except Exception as e: error_hook(e) else: ready_hook() wait_for_exit_signal() stopping_hook()
def initialize(self): self.register_fallback(self.handle_fallback, int(self.settings["priority"])) self.add_event(self.namespace + ".success", self.handle_success) self.add_event(self.namespace + ".failure", self.handle_failure) self.add_event(self.namespace + ".converse.activate", self.handle_converse_enable) self.add_event(self.namespace + ".converse.deactivate", self.handle_converse_disable) self._converse_keepalive = create_daemon(self.converse_keepalive) self.initial_setup() self.add_event('skill-XXX.jarbasskills.home', self.homepage)
def __init__(self, id, config, callback_disconnect, enclosure): DEBUG("Creating GUIConnection") self.id = id self.socket = None self.callback_disconnect = callback_disconnect self.enclosure = enclosure self._active_namespaces = None # This datastore holds the data associated with the GUI provider. Data # is stored in Namespaces, so you can have: # self.datastore["namespace"]["name"] = value # Typically the namespace is a meaningless identifier, but there is a # special "SYSTEM" namespace. self.datastore = {} self.current_namespace = None self.current_page = None # Each connection will run its own Tornado server. If the # connection drops, the server is killed. websocket_config = config.get("gui_websocket") host = websocket_config.get("host") route = websocket_config.get("route") self.port = websocket_config.get("base_port") + GUIConnection._last_idx GUIConnection._last_idx += 1 self.webapp = tornado.web.Application([(route, GUIWebsocketHandler)], **gui_app_settings) self.webapp.gui = self # Hacky way to associate socket with this self.webapp.listen(self.port, host) # TODO: This might need to move up a level # Can't run two IOLoop's in the same process if not GUIConnection.server_thread: GUIConnection.server_thread = create_daemon( ioloop.IOLoop.instance().start) DEBUG("IOLoop started @ ws://" + str(host) + ":" + str(self.port) + str(route))
def initialize(self): create_daemon(self.get_news) # bootstrap cache self.update_rss_feeds() # start periodic RSS parsing
def __init__(self, bus=None, timeout=5): if bus is None: bus = MessageBusClient() create_daemon(bus.run_forever) self.bus = bus self.timeout = timeout
def initialize(self): self.backend = create_daemon(start_backend)