示例#1
0
    def test_load_stt_plugin(self):

        # Test getting default stt
        ol = OrderListener()

        stt1 = Stt(name="default-stt", parameters=dict())

        stt2 = Stt(name="second-stt", parameters=dict())

        stt3 = Stt(name="third-stt", parameters=dict())

        resources = Resources(stt_folder="/tmp")
        ol.settings = mock.MagicMock(default_stt_name="default-stt",
                                     stts=[stt1, stt2, stt3],
                                     resources=resources)

        callback = mock.MagicMock()

        ol.callback = callback

        with mock.patch("kalliope.core.Utils.get_dynamic_class_instantiation"
                        ) as mock_get_dynamic_class_instantiation:
            mock_get_dynamic_class_instantiation.return_value = 'class_instance'
            self.assertEqual(ol.load_stt_plugin(), "class_instance",
                             "Fail getting the proper value")

            mock_get_dynamic_class_instantiation.assert_called_once_with(
                package_name="stt",
                module_name="Default-stt",
                parameters={
                    'callback': callback,
                    'audio_file_path': None
                },
                resources_dir="/tmp")
示例#2
0
    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)
示例#3
0
    def test_Resources(self):
        resource1 = Resources(neuron_folder="/path/neuron",
                              stt_folder="/path/stt",
                              tts_folder="/path/tts",
                              trigger_folder="/path/trigger")

        resource2 = Resources(neuron_folder="/other_path/neuron",
                              stt_folder="/other_path/stt",
                              tts_folder="/other_path/tts",
                              trigger_folder="/other_path/trigger")

        resource3 = Resources(neuron_folder="/path/neuron",
                              stt_folder="/path/stt",
                              tts_folder="/path/tts",
                              trigger_folder="/path/trigger")

        expected_result_serialize = {
            'tts_folder': '/path/tts',
            'neuron_folder': '/path/neuron',
            'stt_folder': '/path/stt',
            'trigger_folder': '/path/trigger',
            'signal_folder': None
        }

        self.assertDictEqual(expected_result_serialize, resource1.serialize())

        self.assertTrue(resource1.__eq__(resource3))
        self.assertFalse(resource1.__eq__(resource2))
示例#4
0
    def test_get_resources(self):

        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")
        expected_resource = resources
        sl = SettingLoader(file_path=self.settings_file_to_test)
        self.assertEqual(expected_resource, sl._get_resources(self.settings_dict))
示例#5
0
    def test_Resources(self):
        resource1 = Resources(neuron_folder="/path/neuron", stt_folder="/path/stt",
                              tts_folder="/path/tts", trigger_folder="/path/trigger")

        resource2 = Resources(neuron_folder="/other_path/neuron", stt_folder="/other_path/stt",
                              tts_folder="/other_path/tts", trigger_folder="/other_path/trigger")

        resource3 = Resources(neuron_folder="/path/neuron", stt_folder="/path/stt",
                              tts_folder="/path/tts", trigger_folder="/path/trigger")

        expected_result_serialize = {
            'tts_folder': '/path/tts',
            'neuron_folder': '/path/neuron',
            'stt_folder': '/path/stt',
            'trigger_folder': '/path/trigger',
            'signal_folder': None
        }

        self.assertDictEqual(expected_result_serialize, resource1.serialize())

        self.assertTrue(resource1.__eq__(resource3))
        self.assertFalse(resource1.__eq__(resource2))
示例#6
0
    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)
示例#7
0
    def test_is_settings_ok(self):
        # -----------------
        # valid resource
        # -----------------
        # valid neuron
        valid_resource = Resources()
        valid_resource.neuron_folder = "/path"
        dna = Dna()
        dna.module_type = "neuron"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid stt
        valid_resource = Resources()
        valid_resource.stt_folder = "/path"
        dna = Dna()
        dna.module_type = "stt"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid tts
        valid_resource = Resources()
        valid_resource.tts_folder = "/path"
        dna = Dna()
        dna.module_type = "tss"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid trigger
        valid_resource = Resources()
        valid_resource.trigger_folder = "/path"
        dna = Dna()
        dna.module_type = "trigger"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # -----------------
        # invalid resource
        # -----------------
        # valid neuron
        valid_resource = Resources()
        valid_resource.neuron_folder = None
        dna = Dna()
        dna.module_type = "neuron"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid stt
        valid_resource = Resources()
        valid_resource.stt_folder = None
        dna = Dna()
        dna.module_type = "stt"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid tts
        valid_resource = Resources()
        valid_resource.tts_folder = None
        dna = Dna()
        dna.module_type = "tts"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid trigger
        valid_resource = Resources()
        valid_resource.trigger_folder = None
        dna = Dna()
        dna.module_type = "trigger"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
示例#8
0
    def test_get_target_folder(self):
        # test get neuron folder
        resources = Resources()
        resources.neuron_folder = '/var/tmp/test/resources'
        self.assertEqual(
            ResourcesManager._get_target_folder(resources, "neuron"),
            "/var/tmp/test/resources")

        # test get stt folder
        resources = Resources()
        resources.stt_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "stt"),
                         "/var/tmp/test/resources")

        # test get tts folder
        resources = Resources()
        resources.tts_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "tts"),
                         "/var/tmp/test/resources")

        # test get trigger folder
        resources = Resources()
        resources.trigger_folder = '/var/tmp/test/resources'
        self.assertEqual(
            ResourcesManager._get_target_folder(resources, "trigger"),
            "/var/tmp/test/resources")

        # test get non existing resource
        resources = Resources()
        self.assertIsNone(
            ResourcesManager._get_target_folder(resources, "not_existing"))
    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))
    def test_is_settings_ok(self):
        # -----------------
        # valid resource
        # -----------------
        # valid neuron
        valid_resource = Resources()
        valid_resource.neuron_folder = "/path"
        dna = Dna()
        dna.module_type = "neuron"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid stt
        valid_resource = Resources()
        valid_resource.stt_folder = "/path"
        dna = Dna()
        dna.module_type = "stt"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid tts
        valid_resource = Resources()
        valid_resource.tts_folder = "/path"
        dna = Dna()
        dna.module_type = "tss"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid trigger
        valid_resource = Resources()
        valid_resource.trigger_folder = "/path"
        dna = Dna()
        dna.module_type = "trigger"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid signal
        valid_resource = Resources()
        valid_resource.signal_folder = "/path"
        dna = Dna()
        dna.module_type = "signal"
        self.assertTrue(ResourcesManager.is_settings_ok(valid_resource, dna))

        # -----------------
        # invalid resource
        # -----------------
        # valid neuron
        valid_resource = Resources()
        valid_resource.neuron_folder = None
        dna = Dna()
        dna.module_type = "neuron"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid stt
        valid_resource = Resources()
        valid_resource.stt_folder = None
        dna = Dna()
        dna.module_type = "stt"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid tts
        valid_resource = Resources()
        valid_resource.tts_folder = None
        dna = Dna()
        dna.module_type = "tts"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid trigger
        valid_resource = Resources()
        valid_resource.trigger_folder = None
        dna = Dna()
        dna.module_type = "trigger"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))

        # valid signal
        valid_resource = Resources()
        valid_resource.signal_folder = None
        dna = Dna()
        dna.module_type = "signal"
        self.assertFalse(ResourcesManager.is_settings_ok(valid_resource, dna))
    def test_get_target_folder(self):
        # test get neuron folder
        resources = Resources()
        resources.neuron_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "neuron"), "/var/tmp/test/resources")

        # test get stt folder
        resources = Resources()
        resources.stt_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "stt"), "/var/tmp/test/resources")

        # test get tts folder
        resources = Resources()
        resources.tts_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "tts"), "/var/tmp/test/resources")

        # test get trigger folder
        resources = Resources()
        resources.trigger_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "trigger"), "/var/tmp/test/resources")

        # test get signal folder
        resources = Resources()
        resources.signal_folder = '/var/tmp/test/resources'
        self.assertEqual(ResourcesManager._get_target_folder(resources, "signal"), "/var/tmp/test/resources")

        # test get non existing resource
        resources = Resources()
        self.assertIsNone(ResourcesManager._get_target_folder(resources, "not_existing"))