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" tts1 = Tts(name="pico2wave", parameters={ 'cache': True, 'language': 'fr-FR' }) tts2 = Tts(name="voxygen", parameters={ 'voice': 'Agnes', 'cache': True }) settings_object.ttss = [tts1, tts2] stt = Stt(name="google", parameters={'language': 'fr-FR'}) settings_object.stts = [stt] settings_object.random_wake_up_answers = ['Oui monsieur?'] settings_object.random_wake_up_sounds = [ 'sounds/ding.wav', 'sounds/dong.wav' ] settings_object.play_on_ready_notification = "never" settings_object.on_ready_answers = ['Kalliope is ready'] settings_object.on_ready_sounds = [ 'sounds/ding.wav', 'sounds/dong.wav' ] trigger1 = Trigger( name="snowboy", parameters={ 'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl' }) settings_object.triggers = [trigger1] 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' settings_object.default_synapse = 'Default-synapse' 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.machine = platform.machine() sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(settings_object, sl.settings)
def test_Tts(self): tts1 = Tts(name="tts1", parameters={"key1": "val1"}) tts2 = Tts(name="tts2", parameters={"key2": "val2"}) tts3 = Tts(name="tts1", parameters={"key1": "val1"}) expected_result_serialize = {'name': 'tts1', 'parameters': {'key1': 'val1'}} self.assertDictEqual(expected_result_serialize, tts1.serialize()) self.assertTrue(tts1.__eq__(tts3)) self.assertFalse(tts1.__eq__(tts2))
def test_get_ttss(self): tts1 = Tts(name="pico2wave", parameters={ 'cache': True, 'language': 'fr-FR' }) tts2 = Tts(name="voxygen", parameters={ 'voice': 'Agnes', 'cache': True }) sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual([tts1, tts2], sl._get_ttss(self.settings_dict))
def test_get_tts_object(self): # no TTS name provided. should return the default tts expected_tts = Tts(name="pico2wave", parameters={ "language": "fr-FR", "cache": True }) self.assertEqual(NeuronModule._get_tts_object(settings=self.settings), expected_tts) # TTS provided, only cache parameter updated expected_tts = Tts(name="pico2wave", parameters={ "language": "fr-FR", "cache": False }) self.assertEqual( NeuronModule._get_tts_object(tts_name="pico2wave", override_parameter={"cache": False}, settings=self.settings), expected_tts) # TTS provided, all parameters updated expected_tts = Tts(name="pico2wave", parameters={ "language": "es-ES", "cache": False }) self.assertEqual( NeuronModule._get_tts_object(tts_name="pico2wave", override_parameter={ "language": "es-ES", "cache": False }, settings=self.settings), expected_tts) # TTS not existing in settings with self.assertRaises(TTSModuleNotFound): NeuronModule._get_tts_object(tts_name="no_existing_tts", override_parameter={"cache": False}, settings=self.settings)
def _get_ttss(settings): """ Return a list of stt object :param settings: The YAML settings file :type settings: dict :return: List of Ttss :rtype: list :Example: ttss = cls._get_ttss(settings) .. seealso:: Tts .. raises:: SettingNotFound .. warnings:: Static Method and Private """ try: text_to_speech_list = settings["text_to_speech"] except KeyError as e: raise SettingNotFound("%s setting not found" % e) ttss = list() for text_to_speech_el in text_to_speech_list: if isinstance(text_to_speech_el, dict): for tts_name in text_to_speech_el: name = tts_name parameters = text_to_speech_el[name] new_tts = Tts(name=name, parameters=parameters) ttss.append(new_tts) else: # the neuron does not have parameter new_tts = Tts(name=text_to_speech_el) ttss.append(new_tts) return ttss
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="voxygen", parameters={ 'voice': 'Agnes', '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.start_options = {"muted": True} settings_object.machine = platform.machine() settings_object.recognition_options = RecognitionOptions() 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_unmute': [], 'on_triggered': ['on-triggered-synapse'], 'on_mute': [], 'on_order_not_found': ['order-not-found-synapse'], 'on_start_speaking': None, 'on_stop_speaking': None, } sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(settings_object, sl.settings)
.. warnings:: Class Method and Private """ try: text_to_speech_list = settings["text_to_speech"] except KeyError, e: raise SettingNotFound("%s setting not found" % e) ttss = list() for text_to_speech_el in text_to_speech_list: if isinstance(text_to_speech_el, dict): # print "Neurons dict ok" for tts_name in text_to_speech_el: name = tts_name parameters = text_to_speech_el[name] new_tts = Tts(name=name, parameters=parameters) ttss.append(new_tts) else: # the neuron does not have parameter new_tts = Tts(name=text_to_speech_el) ttss.append(new_tts) return ttss @staticmethod def _get_triggers(settings): """ Return a list of Trigger object :param settings: The YAML settings file :type settings: dict :return: List of Trigger