Example #1
0
    def __init__(self, *args):
        _IdleObject.__init__(self)
        # Returns the global default main context.
        # This is the main context used for main loop functions
        # when a main loop is not explicitly specified,
        # and corresponds to the "main" main loop.
        # See also GLib.MainContext.get_thread_default().
        context = GObject.MainContext.default()

        self.bucket = bucket = queue.Queue()  # NOQA
        self.hello = None
        self.running = False
        self.bus = None
        self.scarlett_dbus = None
        self.available = False
        self._handler = TaskSignalHandler()

        # Get a dbus proxy and check if theres a service registered called 'org.scarlett.Listener'
        # if not, then we can skip all further processing. (The scarlett-os-mpris-dbus seems not to be running)
        self.__dr = DBusRunner.get_instance()

        logger.info("Initializing ScarlettTasker")

        self._failed_signal_callback = None
        self._ready_signal_callback = None
        self._keyword_recognized_signal_callback = None
        self._command_recognized_signal_callback = None
        self._cancel_signal_callback = None
        self._connect_signal_callback = None
        self._id_do_play_sound = None
Example #2
0
    def __init__(self, bus, path):
        _IdleObject.__init__(self)

        # Synchronously connects to the message bus specified by bus_type
        self.con = Gio.bus_get_sync(Gio.BusType.SESSION, None)
        self.bus_conn = bus
        self.path = path
        self.address = "org.scarlett"

        # Starts acquiring name on the bus specified by bus_type and calls name_acquired_handler and name_lost_handler when the name is acquired respectively lost.
        # Callbacks will be invoked in the thread-default main loop of the thread you are calling this function from.
        Gio.bus_own_name_on_connection(self.con, "org.scarlett",
                                       Gio.BusNameOwnerFlags.NONE, None, None)

        Server.__init__(self, bus, path)

        super(ScarlettListener, self).__init__()

        self.dbus_stack = []
        self._message = "This is the DBusServer"
        self._status_ready = "  ScarlettListener is ready"
        self._status_kw_match = "  ScarlettListener caught a keyword match"
        self._status_cmd_match = "  ScarlettListener caught a command match"
        self._status_stt_failed = "  ScarlettListener hit Max STT failures"
        self._status_cmd_start = "  ScarlettListener emitting start command"
        self._status_cmd_fin = "  ScarlettListener Emitting Command run finish"
        self._status_cmd_cancel = "  ScarlettListener cancel speech Recognition"

        self.dbus_stack.append(bus)
        self.dbus_stack.append(path)
        logger.debug("Inside self.dbus_stack")
        pp.pprint(self.dbus_stack)
Example #3
0
 def __init__(self, name=None):
     self.initialized = False
     self.suspended = False
     self.terminated = False
     self.done = False
     self.tasks_finished = 0
     _IdleObject.__init__(self)
     threading.Thread.__init__(self, name=name)
Example #4
0
 def __init__(self):
     threading.Thread.__init__(self)
     _IdleObject.__init__(self)
Example #5
0
    def __init__(self, name, config_manager, *args):
        threading.Thread.__init__(self)
        _IdleObject.__init__(self)

        self.running = False
        self.finished = False
        self.ready_sem = threading.Semaphore(SEMAPHORE_NUM)
        self.queue = queue.Queue(QUEUE_SIZE)

        # Load in config object, and set default device information
        self._config_manager = config_manager
        self._graphviz_debug_dir = self._config_manager.cfg[
            "graphviz_debug_dir"]

        self._device = self._config_manager.cfg["pocketsphinx"]["device"]
        self._hmm = self._config_manager.cfg["pocketsphinx"]["hmm"]
        self._lm = self._config_manager.cfg["pocketsphinx"]["lm"]
        self._dic = self._config_manager.cfg["pocketsphinx"]["dict"]
        self._fwdflat = bool(
            self._config_manager.cfg["pocketsphinx"]["fwdflat"])
        self._bestpath = bool(
            self._config_manager.cfg["pocketsphinx"]["bestpath"])
        self._dsratio = int(
            self._config_manager.cfg["pocketsphinx"]["dsratio"])
        self._maxhmmpf = int(
            self._config_manager.cfg["pocketsphinx"]["maxhmmpf"])
        self._bestpath = bool(
            self._config_manager.cfg["pocketsphinx"]["bestpath"])
        self._silprob = float(
            self._config_manager.cfg["pocketsphinx"]["silprob"])
        self._wip = float(self._config_manager.cfg["pocketsphinx"]["wip"])

        # dotfile setup
        self._dotfile_listener = os.path.join(self._graphviz_debug_dir,
                                              "generator-listener.dot")
        self._pngfile_listener = os.path.join(
            self._graphviz_debug_dir, "generator-listener-pipeline.png")

        # self._handler = DbusSignalHandler()

        # Get a dbus proxy and check if theres a service registered called 'org.scarlett.Listener'
        # if not, then we can skip all further processing. (The scarlett-os-mpris-dbus seems not to be running)
        # self.__dr = DBusRunner.get_instance()

        logger.info("Initializing ScarlettListenerI")

        # This wil get filled with an exception if opening fails.
        self.read_exc = None
        self.dot_exc = None

        self.cancelled = False
        self.name = name
        self.setName("{}".format(self.name))

        self.pipelines_stack = []
        self.elements_stack = []
        self.gst_bus_stack = []

        self._message = "This is the ScarlettListenerI"
        # TODO: When we're ready to unit test, config this back in!!!!!
        # self.config = scarlett_config.Config()
        self.config = None
        self.override_parse = ""
        self.failed = 0
        self.kw_found = 0
        self.debug = False
        self.create_dot = True
        self.terminate = False

        self.capsfilter_queue_overrun_handler_id = None

        self._cancel_signal_callback = None

        # source: https://github.com/ljmljz/xpra/blob/b32f748e0c29cdbfab836b3901c1e318ea142b33/src/xpra/sound/sound_pipeline.py  # NOQA
        self.bus = None
        self.bus_message_element_handler_id = None
        self.bus_message_error_handler_id = None
        self.bus_message_eos_handler_id = None
        self.bus_message_state_changed_handler_id = None
        self.pipeline = None
        self.start_time = 0
        self.state = "stopped"
        self.buffer_count = 0
        self.byte_count = 0

        self._status_ready = "  ScarlettListener is ready"
        self._status_kw_match = "  ScarlettListener caught a keyword match"
        self._status_cmd_match = "  ScarlettListener caught a command match"
        self._status_stt_failed = "  ScarlettListener hit Max STT failures"
        self._status_cmd_start = "  ScarlettListener emitting start command"
        self._status_cmd_fin = "  ScarlettListener Emitting Command run finish"
        self._status_cmd_cancel = "  ScarlettListener cancel speech Recognition"

        if self.debug:
            # NOTE: For testing puposes, mainly when in public
            # so you dont have to keep yelling scarlett in front of strangers
            self.kw_to_find = ["yo", "hello", "man", "children"]
        else:
            # NOTE: Before we start worrying about the config class, lets hardcode what we care about
            # ADD ME BACK IN WHEN WE REALLY START UNIT TESTING # self.kw_to_find = self.config.get('scarlett', 'keywords')
            self.kw_to_find = ["scarlett", "SCARLETT"]

        if self.read_exc:
            # An error occurred before the stream became ready.
            self.close(True)
            raise self.read_exc  # pylint: disable=raising-bad-type
Example #6
0
    def __init__(self, name, config_manager, *args):
        threading.Thread.__init__(self)
        _IdleObject.__init__(self)

        self.running = False
        self.finished = False
        self.ready_sem = threading.Semaphore(SEMAPHORE_NUM)
        self.queue = queue.Queue(QUEUE_SIZE)

        # Load in config object, and set default device information
        self._config_manager = config_manager
        self._graphviz_debug_dir = self._config_manager.cfg["graphviz_debug_dir"]

        self._device = self._config_manager.cfg["pocketsphinx"]["device"]
        self._hmm = self._config_manager.cfg["pocketsphinx"]["hmm"]
        self._lm = self._config_manager.cfg["pocketsphinx"]["lm"]
        self._dic = self._config_manager.cfg["pocketsphinx"]["dict"]
        self._fwdflat = bool(self._config_manager.cfg["pocketsphinx"]["fwdflat"])
        self._bestpath = bool(self._config_manager.cfg["pocketsphinx"]["bestpath"])
        self._dsratio = int(self._config_manager.cfg["pocketsphinx"]["dsratio"])
        self._maxhmmpf = int(self._config_manager.cfg["pocketsphinx"]["maxhmmpf"])
        self._bestpath = bool(self._config_manager.cfg["pocketsphinx"]["bestpath"])
        self._silprob = float(self._config_manager.cfg["pocketsphinx"]["silprob"])
        self._wip = float(self._config_manager.cfg["pocketsphinx"]["wip"])

        # dotfile setup
        self._dotfile_listener = os.path.join(
            self._graphviz_debug_dir, "generator-listener.dot"
        )
        self._pngfile_listener = os.path.join(
            self._graphviz_debug_dir, "generator-listener-pipeline.png"
        )

        # self._handler = DbusSignalHandler()

        # Get a dbus proxy and check if theres a service registered called 'org.scarlett.Listener'
        # if not, then we can skip all further processing. (The scarlett-os-mpris-dbus seems not to be running)
        # self.__dr = DBusRunner.get_instance()

        logger.info("Initializing ScarlettListenerI")

        # This wil get filled with an exception if opening fails.
        self.read_exc = None
        self.dot_exc = None

        self.cancelled = False
        self.name = name
        self.setName("{}".format(self.name))

        self.pipelines_stack = []
        self.elements_stack = []
        self.gst_bus_stack = []

        self._message = "This is the ScarlettListenerI"
        # TODO: When we're ready to unit test, config this back in!!!!!
        # self.config = scarlett_config.Config()
        self.config = None
        self.override_parse = ""
        self.failed = 0
        self.kw_found = 0
        self.debug = False
        self.create_dot = True
        self.terminate = False

        self.capsfilter_queue_overrun_handler_id = None

        self._cancel_signal_callback = None

        # source: https://github.com/ljmljz/xpra/blob/b32f748e0c29cdbfab836b3901c1e318ea142b33/src/xpra/sound/sound_pipeline.py  # NOQA
        self.bus = None
        self.bus_message_element_handler_id = None
        self.bus_message_error_handler_id = None
        self.bus_message_eos_handler_id = None
        self.bus_message_state_changed_handler_id = None
        self.pipeline = None
        self.start_time = 0
        self.state = "stopped"
        self.buffer_count = 0
        self.byte_count = 0

        self._status_ready = "  ScarlettListener is ready"
        self._status_kw_match = "  ScarlettListener caught a keyword match"
        self._status_cmd_match = "  ScarlettListener caught a command match"
        self._status_stt_failed = "  ScarlettListener hit Max STT failures"
        self._status_cmd_start = "  ScarlettListener emitting start command"
        self._status_cmd_fin = "  ScarlettListener Emitting Command run finish"
        self._status_cmd_cancel = "  ScarlettListener cancel speech Recognition"

        if self.debug:
            # NOTE: For testing puposes, mainly when in public
            # so you dont have to keep yelling scarlett in front of strangers
            self.kw_to_find = ["yo", "hello", "man", "children"]
        else:
            # NOTE: Before we start worrying about the config class, lets hardcode what we care about
            # ADD ME BACK IN WHEN WE REALLY START UNIT TESTING # self.kw_to_find = self.config.get('scarlett', 'keywords')
            self.kw_to_find = ["scarlett", "SCARLETT"]

        if self.read_exc:
            # An error occurred before the stream became ready.
            self.close(True)
            raise self.read_exc  # pylint: disable=raising-bad-type
Example #7
0
 def __init__(self):
     threading.Thread.__init__(self)
     _IdleObject.__init__(self)