def test_get_options(self): expected_result = Options( recognizer_multiplier=1.0, recognizer_energy_ratio=1.5, recognizer_recording_timeout=15.0, recognizer_recording_timeout_with_silence=3.0, deaf=True, mute=False) sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(expected_result, sl._get_options(self.settings_dict))
def _get_options(settings): """ Return the Options settings if not set, default values are : deaf: False mute: False energy_threshold = 4000 adjust_for_ambient_noise_second = 0 :param settings: The YAML settings file :type settings: dict :return: An Options with the start options :rtype: Options """ deaf = False mute = False recognizer_multiplier = 1.0 recognizer_energy_ratio = 1.5 recognizer_recording_timeout = 15.0 recognizer_recording_timeout_with_silence = 3.0 try: options = settings["options"] if "deaf" in options: deaf = options['deaf'] if "mute" in options: mute = options['mute'] if "recognizer_multiplier" in options: recognizer_multiplier = options["recognizer_multiplier"] if "recognizer_energy_ratio" in options: recognizer_energy_ratio = options["recognizer_energy_ratio"] if "recognizer_recording_timeout" in options: recognizer_recording_timeout = options[ "recognizer_recording_timeout"] if "recognizer_recording_timeout_with_silence" in options: recognizer_recording_timeout_with_silence = options[ "recognizer_recording_timeout_with_silence"] except KeyError as e: logger.debug("[SettingsLoader] missing settings key: %s" % e) pass options = Options( recognizer_multiplier=recognizer_multiplier, recognizer_energy_ratio=recognizer_energy_ratio, recognizer_recording_timeout=recognizer_recording_timeout, recognizer_recording_timeout_with_silence= recognizer_recording_timeout_with_silence, deaf=deaf, mute=mute) logger.debug("[SettingsLoader] Options: %s" % options) return options
def _get_options(settings): """ Return the Options settings if not set, default values are : deaf: False mute: False energy_threshold = 4000 adjust_for_ambient_noise_second = 0 :param settings: The YAML settings file :type settings: dict :return: An Options with the start options :rtype: Options """ deaf = False mute = False energy_threshold = 4000 adjust_for_ambient_noise_second = 0 stt_timeout = 0 try: options = settings["options"] if "deaf" in options: deaf = options['deaf'] if "mute" in options: mute = options['mute'] if "energy_threshold" in options: energy_threshold = options["energy_threshold"] if "adjust_for_ambient_noise_second" in options: adjust_for_ambient_noise_second = options[ "adjust_for_ambient_noise_second"] if "stt_timeout" in options: stt_timeout = options["stt_timeout"] except KeyError as e: logger.debug("[SettingsLoader] missing settings key: %s" % e) pass options = Options( energy_threshold=energy_threshold, adjust_for_ambient_noise_second=adjust_for_ambient_noise_second, deaf=deaf, mute=mute, stt_timeout=stt_timeout) logger.debug("[SettingsLoader] Options: %s" % options) return options
def test_get_options(self): expected_result = Options(energy_threshold=3000, deaf=True, mute=False) sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(expected_result, sl._get_options(self.settings_dict))
def test_get_settings(self): settings_object = Settings() settings_object.default_tts_name = "pico2wave" settings_object.default_stt_name = "google" settings_object.default_trigger_name = "snowboy" settings_object.default_player_name = "mplayer" tts1 = Tts(name="pico2wave", parameters={ 'cache': True, 'language': 'fr-FR' }) tts2 = Tts(name="googletts", parameters={ 'language': 'fr', 'cache': True }) settings_object.ttss = [tts1, tts2] stt = Stt(name="google", parameters={'language': 'fr-FR'}) settings_object.stts = [stt] trigger1 = Trigger( name="snowboy", parameters={ 'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl' }) settings_object.triggers = [trigger1] player1 = Player(name="mplayer", parameters={}) player2 = Player(name="pyalsaaudio", parameters={"device": "default"}) settings_object.players = [player1, player2] settings_object.rest_api = RestAPI(password_protected=True, active=True, login="******", password="******", port=5000, allowed_cors_origin=False) settings_object.cache_path = '/tmp/kalliope_tts_cache' resources = Resources( neuron_folder="/tmp/kalliope/tests/kalliope_resources_dir/neurons", stt_folder="/tmp/kalliope/tests/kalliope_resources_dir/stt", tts_folder="/tmp/kalliope/tests/kalliope_resources_dir/tts", trigger_folder="/tmp/kalliope/tests/kalliope_resources_dir/trigger" ) settings_object.resources = resources settings_object.variables = { "author": "Lamonf", "test_number": 60, "test": "kalliope" } settings_object.options = Options(energy_threshold=3000, deaf=True, mute=False) settings_object.machine = platform.machine() settings_object.hooks = { 'on_waiting_for_trigger': 'test', 'on_stop_listening': None, 'on_start_listening': None, 'on_order_found': None, 'on_start': ['on-start-synapse', 'bring-led-on'], 'on_undeaf': [], 'on_triggered': ['on-triggered-synapse'], 'on_deaf': [], 'on_mute': [], 'on_unmute': [], 'on_order_not_found': ['order-not-found-synapse'], 'on_processed_synapses': None, 'on_start_speaking': None, 'on_stop_speaking': None, } sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(settings_object, sl.settings)
def test_Settings(self): with mock.patch('platform.machine', return_value='pumpkins'): rest_api1 = RestAPI(password_protected=True, login="******", password="******", active=True, port=5000, allowed_cors_origin="*") tts1 = Tts(name="tts1", parameters=dict()) tts2 = Tts(name="tts2", parameters=dict()) stt1 = Stt(name="stt1", parameters=dict()) stt2 = Stt(name="stt2", parameters=dict()) trigger1 = Trigger(name="snowboy", parameters=dict()) player = Player(name="player1") resources = Resources() options = Options() setting1 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=[tts1], stts=[stt1], triggers=[trigger1], players=[player], rest_api=rest_api1, cache_path="/tmp/kalliope", resources=resources, variables={"key1": "val1"}, options=options, send_anonymous_usage_stats=0) setting1.kalliope_version = "0.4.5" setting2 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=[tts2], stts=[stt2], triggers=[trigger1], players=[player], rest_api=rest_api1, cache_path="/tmp/kalliope", resources=resources, variables={"key1": "val1"}, options=options, send_anonymous_usage_stats=0) setting3 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=[tts1], stts=[stt1], triggers=[trigger1], players=[player], rest_api=rest_api1, cache_path="/tmp/kalliope", resources=resources, variables={"key1": "val1"}, options=options, send_anonymous_usage_stats=0) setting3.kalliope_version = "0.4.5" expected_result_serialize = { 'default_tts_name': 'pico2wav', 'default_stt_name': 'google', 'default_trigger_name': 'swoyboy', 'default_player_name': 'mplayer', 'ttss': [{ 'name': 'tts1', 'parameters': {} }], 'stts': [{ 'name': 'stt1', 'parameters': {} }], 'triggers': [{ 'name': 'snowboy', 'parameters': {} }], 'players': [{ 'name': 'player1', 'parameters': None }], 'rest_api': { 'password_protected': True, 'login': '******', 'password': '******', 'active': True, 'port': 5000, 'allowed_cors_origin': '*' }, 'cache_path': '/tmp/kalliope', 'resources': { 'neuron_folder': None, 'stt_folder': None, 'tts_folder': None, 'trigger_folder': None, 'signal_folder': None }, 'variables': { 'key1': 'val1' }, 'machine': 'pumpkins', 'kalliope_version': '0.4.5', 'options': { 'name': 'Options', 'recognizer_multiplier': 1.0, 'recognizer_energy_ratio': 1.5, 'recognizer_recording_timeout': 15.0, 'recognizer_recording_timeout_with_silence': 3.0, 'deaf': None, 'mute': None }, 'hooks': None, 'send_anonymous_usage_stats': 0 } self.maxDiff = None self.assertDictEqual(expected_result_serialize, setting1.serialize()) self.assertTrue(setting1.__eq__(setting3)) self.assertFalse(setting1.__eq__(setting2))