def __init__(self, **kwargs): super(Snowboy, self).__init__() self._ignore_stderr() # pause listening boolean self.interrupted = False self.kill_received = False # get the sensitivity if set by the user self.sensitivity = kwargs.get('sensitivity', 0.5) # callback function to call when hotword caught self.callback = kwargs.get('callback', None) if self.callback is None: raise MissingParameterException( "callback function is required with snowboy") # get the pmdl file to load self.pmdl = kwargs.get('pmdl_file', None) if self.pmdl is None: raise MissingParameterException( "Pmdl file is required with snowboy") self.pmdl_path = Utils.get_real_file_path(self.pmdl) if not os.path.isfile(self.pmdl_path): raise SnowboyModelNotFounfd( "The snowboy model file %s does not exist" % self.pmdl_path) self.detector = snowboydecoder.HotwordDetector( self.pmdl_path, sensitivity=self.sensitivity, detected_callback=self.callback, interrupt_check=self.interrupt_callback, sleep_time=0.03)
def __init__(self, **kwargs): super(Precise, self).__init__() self._ignore_stderr() # pause listening boolean self.interrupted = False # callback function to call when hotword caught self.callback = kwargs.get('callback', None) if self.callback is None: raise MissingParameterException( "Callback function is required with precise") # get the sensitivity if set by the user self.sensitivity = kwargs.get('sensitivity', 0.5) # get the pmdl file to load self.pb_file = kwargs.get('pb_file', None) if self.pb_file is None: raise MissingParameterException( "Wake word file is required with precise") try: os.path.isfile(Utils.get_real_file_path(self.pb_file)) except TypeError: raise PreciseModelNotFound( "Precise wake word file %s does not exist" % self.pb_file) self.detector = HotwordDetector(keyword=self.pb_file, sensitivity=self.sensitivity, detected_callback=self.callback)
def __init__(self, **kwargs): super(Snowboy, self).__init__() self._ignore_stderr() # pause listening boolean self.interrupted = False self.kill_received = False # get the sensitivity if set by the user self.sensitivity = kwargs.get('sensitivity', 0.5) # callback function to call when hotword caught self.callback = kwargs.get('callback', None) if self.callback is None: raise MissingParameterException("callback function is required with snowboy") # get the pmdl file to load self.pmdl = kwargs.get('pmdl_file', None) if self.pmdl is None: raise MissingParameterException("Pmdl file is required with snowboy") self.pmdl_path = Utils.get_real_file_path(self.pmdl) if not os.path.isfile(self.pmdl_path): raise SnowboyModelNotFounfd("The snowboy model file %s does not exist" % self.pmdl_path) self.detector = snowboydecoder.HotwordDetector(self.pmdl_path, sensitivity=self.sensitivity, detected_callback=self.callback, interrupt_check=self.interrupt_callback, sleep_time=0.03)
def check_if_path_is_valid(self, keyword_file): try: keyword_path = Utils.get_real_file_path(keyword_file) os.path.isfile(keyword_path) except TypeError: raise SnowboyModelNotFound("The keyword at %s does not exist" % keyword_file) return True
def __init__(self, **kwargs): super(Enigma, self).__init__(**kwargs) # the args from the neuron configuration self.ip = kwargs.get('ip', None) self.port = kwargs.get('port', 80) self.login = kwargs.get('login', None) self.password = kwargs.get('passwort', None) self.command = kwargs.get('command', None) self.channel = kwargs.get('channel', None) self.file = kwargs.get('file', None) if self._is_parameters_ok(): path = Utils.get_real_file_path(self.file) file = None found = False if self.login: url = "http://" + self.login + ":" + self.password + "@" + str( self.ip) + ":" + str(self.port) else: url = "http://" + str(self.ip) + ":" + str(self.port) if self.channel: url = url + "/web/zap?sRef=" file = open(path, "r") channels = yaml.load(file) for channel in channels: if channel == self.channel: Utils.print_info("Channel found: " + channel) url = url + channels[channel] found = True break if not found: Utils.print_info("Channel : " + self.channel + " not found") else: url = url + "/web/remotecontrol?command=" file = open(path, "r") cmds = yaml.load(file) for cmd in cmds: if cmd == self.command: Utils.print_info("Command found: " + cmd) url = url + cmds[cmd] found = True break if not found: Utils.print_info("Command : " + self.command + " not found") if found: Utils.print_info("Sending: " + url) try: requests.post(url) except requests.exceptions.ConnectionError: Utils.print_info("Failed to establish a new connection")
def _get_random_sound(random_wake_up_sounds): """ Return a path of a sound to play If the path is absolute, test if file exist If the path is relative, we check if the file exist in the sound folder :param random_wake_up_sounds: List of wake_up sounds :return: path of a sound to play """ # take first randomly a path random_path = random.choice(random_wake_up_sounds) logger.debug("[MainController] Selected sound: %s" % random_path) return Utils.get_real_file_path(random_path)
def __init__(self, **kwargs): super(Porcupine, self).__init__() self._ignore_stderr() # Pause listening boolean. self.kill_received = False # Get input device if set by the user. self.input_device_index = kwargs.get('input_device_index', None) # Use tiny keywords if user set to True. self.tiny_keyword = kwargs.get('tiny_keyword', False) # Callback function to call when hotword caught. self.callback = kwargs.get('callback', None) if self.callback is None: raise MissingParameterException( "Callback function is required with porcupine") # Get keywords to load. self.keywords = kwargs.get('keywords', None) if self.keywords is None: raise MissingParameterException( "At least one keyword is required with porcupine") keyword_file_paths = list() sensitivities = list() for keyword in self.keywords: path = Utils.get_real_file_path(keyword['keyword']['ppn_file']) try: os.path.isfile(path) except TypeError: raise PorcupineWakeWordNotFound( "The porcupine keyword at %s does not exist" % keyword['keyword']['ppn_file']) try: sensitivity = keyword['keyword']['sensitivity'] except KeyError: sensitivity = 0.5 keyword_file_paths.append(path) sensitivities.append(sensitivity) keyword_file_paths = ", ".join(keyword_file_paths) sensitivities = ", ".join(map(str, sensitivities)) self.detector = HotwordDetector( keyword_file_paths=keyword_file_paths, sensitivities=sensitivities, input_device_index=self.input_device_index, tiny=self.tiny_keyword, detected_callback=self.callback)
def __init__(self, **kwargs): super(Ownsnowboy, self).__init__() self._ignore_stderr() # pause listening boolean self.interrupted = False self.apply_frontend = kwargs.get('apply_frontend', False) # callback function to call when hotword caught self.callback = kwargs.get('callback', None) if self.callback is None: raise MissingParameterException( "callback function is required with snowboy") self.keywords = kwargs.get('keywords', None) keyword_file_paths = list() sensitivities = list() for keyword in self.keywords: path = Utils.get_real_file_path(keyword['keyword']['pmdl_path']) try: os.path.isfile(path) except TypeError: raise SnowboyModelNotFound( "The Snowboy keyword at %s does not exist" % keyword['keyword']['pmdl_path']) keyword_file_paths.append(path) try: for sens in keyword['keyword']['sensitivity']: sensitivities.append(sens) except KeyError: sensitivities.append("0.5") self.detector = HotwordDetector( keyword_file_paths, sensitivity=sensitivities, detected_callback=self.callback, interrupt_check=self.interrupt_callback, apply_frontend=self.apply_frontend, sleep_time=0.01)
def _is_parameters_ok(self): """ Check the validity for each parameter :return: True if all parameters are set correctly, False otherwise. """ # Players if self.default_player: if not SettingEditor._check_name_in_list_settings_entry(self.default_player, self.settings.players): logger.debug("[Settings] default_player %s is not defined in settings file ", self.default_player) return False if self.players: if not isinstance(self.players, list): logger.debug("[Settings] players current type: %s. players should be a list", type(self.players)) return False for player_el in self.players: if not isinstance(player_el, dict): logger.debug("[Settings] player current element type: %s. player element should be a dict", type(player_el)) return False # STT if self.default_stt: if not SettingEditor._check_name_in_list_settings_entry(self.default_stt, self.settings.stts): logger.debug("[Settings] default_stt %s is not defined in settings file ", self.default_stt) return False if self.speech_to_text: if not isinstance(self.speech_to_text, list): logger.debug("[Settings] speech_to_text current type: %s. speech_to_text should be a list", type(self.speech_to_text)) return False for stt_el in self.speech_to_text: if not isinstance(stt_el, dict): logger.debug( "[Settings] speech_to_text current element type: %s. speech_to_text element should be a dict", type(stt_el)) return False # TRIGGER if self.default_trigger: if not SettingEditor._check_name_in_list_settings_entry(self.default_trigger, self.settings.triggers): logger.debug("[Settings] default_trigger %s is not defined in settings file ", self.default_trigger) return False if self.triggers: if not isinstance(self.triggers, list): logger.debug("[Settings] triggers current type: %s. triggers should be a list", type(self.triggers)) return False for trigger_el in self.triggers: if not isinstance(trigger_el, dict): logger.debug("[Settings] triggers current element type: %s. triggers element should be a dict", type(trigger_el)) return False # TTS if self.default_tts: if not SettingEditor._check_name_in_list_settings_entry(self.default_tts, self.settings.ttss): logger.debug("[Settings] default_tts %s is not defined in settings file ", self.default_tts) return False if self.text_to_speech: if not isinstance(self.text_to_speech, list): logger.debug("[Settings] text_to_speech current type: %s. text_to_speech should be a list", type(self.text_to_speech)) return False for tts_el in self.text_to_speech: if not isinstance(tts_el, dict): logger.debug( "[Settings] text_to_speech element current type: %s. text_to_speech element should be a dict", type(tts_el)) return False # Options if self.deaf is not None: if not isinstance(self.deaf, bool): logger.debug("[Settings] deaf %s is not a correct value, you must define True or False", self.deaf) return False if self.mute is not None: if not isinstance(self.mute, bool): logger.debug("[Settings] mute %s is not a correct value, you must define True or False", self.mute) return False if self.energy_threshold is not None: if not isinstance(self.energy_threshold, int): logger.debug("[Settings] energy_threshold %s is not a correct integer, you must define a number", self.energy_threshold) return False if self.adjust_for_ambient_noise_second is not None: if not isinstance(self.adjust_for_ambient_noise_second, int): logger.debug( "[Settings] adjust_for_ambient_noise_second %s is not a correct integer, you must define a number", self.adjust_for_ambient_noise_second) return False # Hooks if self.hooks: if not isinstance(self.hooks, dict): logger.debug("[Settings] hooks property %s is not a dictionary as it should be.", type(self.hooks)) return False for hook_name, synap in self.hooks.items(): if not isinstance(synap, str) and not isinstance(synap, list): logger.debug( "[Settings] for hook element %s the type %s is nor a string nor a list as it should be.", hook_name, type(synap)) return False # Variables if self.var_files: if not isinstance(self.var_files, list): logger.debug("[Settings] var_files property %s is not a list as it should be.", type(self.var_files)) return False for file_name in self.var_files: var = Utils.get_real_file_path(file_name) if var is None: logger.debug("[Settings] Variables file %s not found", file_name) return False if self.variable: if not isinstance(self.variable, dict): logger.debug("[Settings] variable property %s is not a dict as it should be.", type(self.variable)) return False return True
def _set_settings(self): # PLAYERS if self.default_player: SettingEditor.set_default_player(self.default_player) if self.players: for player_el in self.players: if isinstance(player_el, dict): for player_name in player_el: name = player_name parameters = player_el[name] new_player = Player(name=name, parameters=parameters) SettingEditor.set_players(new_player) # STT if self.default_stt: SettingEditor.set_default_stt(self.default_stt) if self.speech_to_text: for stt_el in self.speech_to_text: if isinstance(stt_el, dict): for stt_name in stt_el: name = stt_name parameters = stt_el[name] new_stt = Stt(name=name, parameters=parameters) SettingEditor.set_stts(new_stt) # TRIGGER if self.default_trigger: SettingEditor.set_default_trigger(self.default_trigger) if self.triggers: for trigger_el in self.triggers: if isinstance(trigger_el, dict): for trigger_name in trigger_el: name = trigger_name parameters = trigger_el[name] new_trigger = Trigger(name=name, parameters=parameters) SettingEditor.set_trigger(new_trigger) # TTS if self.default_tts: SettingEditor.set_default_tts(self.default_tts) if self.text_to_speech: for tts_el in self.text_to_speech: if isinstance(tts_el, dict): for tts_name in tts_el: name = tts_name parameters = tts_el[name] new_tts = Tts(name=name, parameters=parameters) SettingEditor.set_ttss(new_tts) # Options if self.deaf is not None: signal_order = SignalLauncher.get_order_instance() if signal_order is not None: SettingEditor.set_deaf_status(signal_order.trigger_instance, self.deaf) if self.mute is not None: SettingEditor.set_mute_status(self.mute) if self.energy_threshold is not None: SettingEditor.set_energy_threshold(self.energy_threshold) if self.adjust_for_ambient_noise_second is not None: SettingEditor.set_adjust_for_ambient_noise_second(self.adjust_for_ambient_noise_second) # Hooks if self.hooks: SettingEditor.set_hooks(self.hooks) # Variables if self.var_files: variables = dict() for files in self.var_files: var = Utils.get_real_file_path(files) # var is None has been checked previously in _is_parameters_ok() method variables.update(YAMLLoader.get_config(var)) SettingEditor.set_variables(variables) if self.variable is not None: SettingEditor.set_variables(self.variable)
def _is_parameters_ok(self): """ Check the validity for each parameter :return: True if all parameters are set correctly, False otherwise. """ # Players if self.default_player: if not SettingEditor._check_name_in_list_settings_entry( self.default_player, self.settings.players): logger.debug( "[Settings] default_player %s is not defined in settings file ", self.default_player) return False if self.players: if not isinstance(self.players, list): logger.debug( "[Settings] players current type: %s. players should be a list", type(self.players)) return False for player_el in self.players: if not isinstance(player_el, dict): logger.debug( "[Settings] player current element type: %s. player element should be a dict", type(player_el)) return False # STT if self.default_stt: if not SettingEditor._check_name_in_list_settings_entry( self.default_stt, self.settings.stts): logger.debug( "[Settings] default_stt %s is not defined in settings file ", self.default_stt) return False if self.speech_to_text: if not isinstance(self.speech_to_text, list): logger.debug( "[Settings] speech_to_text current type: %s. speech_to_text should be a list", type(self.speech_to_text)) return False for stt_el in self.speech_to_text: if not isinstance(stt_el, dict): logger.debug( "[Settings] speech_to_text current element type: %s. speech_to_text element should be a dict", type(stt_el)) return False # TRIGGER if self.default_trigger: if not SettingEditor._check_name_in_list_settings_entry( self.default_trigger, self.settings.triggers): logger.debug( "[Settings] default_trigger %s is not defined in settings file ", self.default_trigger) return False if self.triggers: if not isinstance(self.triggers, list): logger.debug( "[Settings] triggers current type: %s. triggers should be a list", type(self.triggers)) return False for trigger_el in self.triggers: if not isinstance(trigger_el, dict): logger.debug( "[Settings] triggers current element type: %s. triggers element should be a dict", type(trigger_el)) return False # TTS if self.default_tts: if not SettingEditor._check_name_in_list_settings_entry( self.default_tts, self.settings.ttss): logger.debug( "[Settings] default_tts %s is not defined in settings file ", self.default_tts) return False if self.text_to_speech: if not isinstance(self.text_to_speech, list): logger.debug( "[Settings] text_to_speech current type: %s. text_to_speech should be a list", type(self.text_to_speech)) return False for tts_el in self.text_to_speech: if not isinstance(tts_el, dict): logger.debug( "[Settings] text_to_speech element current type: %s. text_to_speech element should be a dict", type(tts_el)) return False # Options if self.deaf is not None: if not isinstance(self.deaf, bool): logger.debug( "[Settings] deaf %s is not a correct value, you must define True or False", self.deaf) return False if self.mute is not None: if not isinstance(self.mute, bool): logger.debug( "[Settings] mute %s is not a correct value, you must define True or False", self.mute) return False if self.energy_threshold is not None: if not isinstance(self.energy_threshold, int): logger.debug( "[Settings] energy_threshold %s is not a correct integer, you must define a number", self.energy_threshold) return False if self.adjust_for_ambient_noise_second is not None: if not isinstance(self.adjust_for_ambient_noise_second, int): logger.debug( "[Settings] adjust_for_ambient_noise_second %s is not a correct integer, you must define a number", self.adjust_for_ambient_noise_second) return False # Hooks if self.hooks: if not isinstance(self.hooks, dict): logger.debug( "[Settings] hooks property %s is not a dictionary as it should be.", type(self.hooks)) return False for hook_name, synap in self.hooks.items(): if not isinstance(synap, str) and not isinstance(synap, list): logger.debug( "[Settings] for hook element %s the type %s is nor a string nor a list as it should be.", hook_name, type(synap)) return False # Variables if self.var_files: if not isinstance(self.var_files, list): logger.debug( "[Settings] var_files property %s is not a list as it should be.", type(self.var_files)) return False for file_name in self.var_files: var = Utils.get_real_file_path(file_name) if var is None: logger.debug("[Settings] Variables file %s not found", file_name) return False if self.variable: if not isinstance(self.variable, dict): logger.debug( "[Settings] variable property %s is not a dict as it should be.", type(self.variable)) return False return True
def _set_settings(self): # PLAYERS if self.default_player: SettingEditor.set_default_player(self.default_player) if self.players: for player_el in self.players: if isinstance(player_el, dict): for player_name in player_el: name = player_name parameters = player_el[name] new_player = Player(name=name, parameters=parameters) SettingEditor.set_players(new_player) # STT if self.default_stt: SettingEditor.set_default_stt(self.default_stt) if self.speech_to_text: for stt_el in self.speech_to_text: if isinstance(stt_el, dict): for stt_name in stt_el: name = stt_name parameters = stt_el[name] new_stt = Stt(name=name, parameters=parameters) SettingEditor.set_stts(new_stt) # TRIGGER if self.default_trigger: SettingEditor.set_default_trigger(self.default_trigger) if self.triggers: for trigger_el in self.triggers: if isinstance(trigger_el, dict): for trigger_name in trigger_el: name = trigger_name parameters = trigger_el[name] new_trigger = Trigger(name=name, parameters=parameters) SettingEditor.set_trigger(new_trigger) # TTS if self.default_tts: SettingEditor.set_default_tts(self.default_tts) if self.text_to_speech: for tts_el in self.text_to_speech: if isinstance(tts_el, dict): for tts_name in tts_el: name = tts_name parameters = tts_el[name] new_tts = Tts(name=name, parameters=parameters) SettingEditor.set_ttss(new_tts) # Options if self.deaf is not None: signal_order = SignalLauncher.get_order_instance() if signal_order is not None: SettingEditor.set_deaf_status(signal_order.trigger_instance, self.deaf) if self.mute is not None: SettingEditor.set_mute_status(self.mute) if self.energy_threshold is not None: SettingEditor.set_energy_threshold(self.energy_threshold) if self.adjust_for_ambient_noise_second is not None: SettingEditor.set_adjust_for_ambient_noise_second( self.adjust_for_ambient_noise_second) # Hooks if self.hooks: SettingEditor.set_hooks(self.hooks) # Variables if self.var_files: variables = dict() for files in self.var_files: var = Utils.get_real_file_path(files) # var is None has been checked previously in _is_parameters_ok() method variables.update(YAMLLoader.get_config(var)) SettingEditor.set_variables(variables) if self.variable is not None: SettingEditor.set_variables(self.variable)