コード例 #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},
                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_Stt(self):
        stt1 = Stt(name="stt1", parameters={"key1": "val1"})
        stt2 = Stt(name="stt2", parameters={"key2": "val2"})
        stt3 = Stt(name="stt1", parameters={"key1": "val1"})

        expected_result_serialize = {'name': 'stt1', 'parameters': {'key1': 'val1'}}

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

        self.assertTrue(stt1.__eq__(stt3))
        self.assertFalse(stt1.__eq__(stt2))
コード例 #4
0
ファイル: SettingLoader.py プロジェクト: navet56/kalliope
    def _get_stts(settings):
        """
        Return a list of stt object

        :param settings: The YAML settings file
        :type settings: dict
        :return: List of Stt
        :rtype: list

        :Example:

            stts = cls._get_stts(settings)

        .. seealso:: Stt
        .. raises:: SettingNotFound
        .. warnings:: Class Method and Private
        """

        try:
            speechs_to_text_list = settings["speech_to_text"]
        except KeyError:
            raise SettingNotFound("speech_to_text settings not found")

        stts = list()
        for speechs_to_text_el in speechs_to_text_list:
            if isinstance(speechs_to_text_el, dict):
                # print "Neurons dict ok"
                for stt_name in speechs_to_text_el:
                    name = stt_name
                    parameters = speechs_to_text_el[name]
                    new_stt = Stt(name=name, parameters=parameters)
                    stts.append(new_stt)
            else:
                # the stt does not have parameter
                new_stt = Stt(name=speechs_to_text_el, parameters=dict())
                stts.append(new_stt)
        return stts
コード例 #5
0
 def test_get_stts(self):
     stt = Stt(name="google", parameters={'language': 'fr-FR'})
     sl = SettingLoader(file_path=self.settings_file_to_test)
     self.assertEqual([stt], sl._get_stts(self.settings_dict))
コード例 #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)