def test_singleton(self):
        s1 = SettingLoader.Instance(file_path=self.settings_file_to_test)
        s2 = SettingLoader.Instance(file_path=self.settings_file_to_test)

        self.assertTrue(s1.settings is s2.settings)

        del s1
        del s2
Пример #2
0
def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    sl = SettingLoader.Instance()
    settings = sl.settings
    return username == settings.rest_api.login and password == settings.rest_api.password
Пример #3
0
    def __init__(self, **kwargs):

        # set parameter from what we receive from the settings
        self.cache = kwargs.get('cache', False)
        self.language = kwargs.get('language', None)
        self.voice = kwargs.get('voice', "default")
        # the name of the TSS is the name of the Tss module that have instantiated TTSModule
        self.tts_caller_name = self.__class__.__name__

        # we don't know yet the words that will be converted to an audio and so we don't have the audio path yet too
        self.words = None
        self.file_path = None
        self.base_cache_path = None

        # load settings
        sl = SettingLoader.Instance()
        self.settings = sl.settings

        # create the path in the tmp folder
        base_path = os.path.join(self.settings.cache_path,
                                 self.tts_caller_name, self.language,
                                 self.voice)
        FileManager.create_directory(base_path)

        logger.debug(
            "Class TTSModule called from module %s, cache: %s, language: %s, voice: %s"
            % (self.tts_caller_name, self.cache, self.language, self.voice))
    def test_get_default_speech_to_text(self):
        expected_default_speech_to_text = "google"
        sl = SettingLoader.Instance(file_path=self.settings_file_to_test)

        self.assertEqual(expected_default_speech_to_text,
                         sl._get_default_speech_to_text(self.settings_dict))
        del sl
Пример #5
0
    def __init__(self, **kwargs):
        """
        Class used by neuron for talking
        :param kwargs: Same parameter as the Child. Can contain info about the tts to use instead of the
        default one
        """
        # get the child who called the class
        child_name = self.__class__.__name__
        logger.debug("NeuronModule called from class %s with parameters: %s" % (child_name, str(kwargs)))

        sl = SettingLoader.Instance()
        self.settings = sl.settings
        brain_loader = BrainLoader.Instance()
        self.brain = brain_loader.brain

        # check if the user has overrider the TTS
        tts = kwargs.get('tts', None)
        if tts is None:
            # No tts provided,  we load the default one
            self.tts = self.settings.default_tts_name
        else:
            self.tts = tts

        # get if the cache settings is present
        self.override_cache = kwargs.get('cache', None)

        # get templates if provided
        # Check if there is a template associate to the output message
        self.say_template = kwargs.get('say_template', None)
        # check if there is a template file associate to the output message
        self.file_template = kwargs.get('file_template', None)
Пример #6
0
 def decorated(*args, **kwargs):
     sl = SettingLoader.Instance()
     settings = sl.settings
     if settings.rest_api.password_protected:
         auth = request.authorization
         if not auth or not check_auth(auth.username, auth.password):
             return authenticate()
     return f(*args, **kwargs)
 def test_get_triggers(self):
     trigger1 = Trigger(
         name="snowboy",
         parameters={
             'pmdl_file':
             'trigger/snowboy/resources/kalliope-FR-6samples.pmdl'
         })
     sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
     self.assertEqual([trigger1], sl._get_triggers(self.settings_dict))
     del sl
    def test_get_rest_api(self):
        expected_rest_api = RestAPI(password_protected=True,
                                    active=True,
                                    login="******",
                                    password="******",
                                    port=5000)

        sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
        self.assertEqual(expected_rest_api,
                         sl._get_rest_api(self.settings_dict))
        del sl
 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.Instance(file_path=self.settings_file_to_test)
     self.assertEqual([tts1, tts2], sl._get_ttss(self.settings_dict))
     del sl
Пример #10
0
    def __init__(self, brain=None):
        """
        Load a GUI in a shell console for testing TTS, STT and brain configuration
        :param brain: The Brain object provided by the brain.yml
        :type brain: Brain

        .. seealso:: Brain
        """
        # override brain
        self.brain = brain

        # get settings
        sl = SettingLoader.Instance()
        self.settings = sl.settings
        locale.setlocale(locale.LC_ALL, '')

        self.d = Dialog(dialog="dialog")

        self.d.set_background_title("Kalliope shell UI")

        self.show_main_menu()
Пример #11
0
    def __init__(self, callback=None, stt=None):
        """
        This class is called after we catch the hotword that have woke up Kalliope.
        We now wait for an order spoken out loud by the user, translate the order into a text and run the action
         attached to this order from settings
        :param callback: callback function to call
        :type callback: Callback function
        :param stt: Speech to text plugin name to load. If not provided,
        :type stt: STT instance
        we will load the default one set in settings

        .. seealso::  STT
        """
        # this is a trick to ignore ALSA output error
        # see http://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time
        super(OrderListener, self).__init__()
        self.stt = stt
        self._ignore_stderr()
        self.stt_module_name = stt
        self.callback = callback
        sl = SettingLoader.Instance()
        self.settings = sl.settings
Пример #12
0
    def __init__(self, brain=None):
        self.brain = brain
        # get global configuration
        sl = SettingLoader.Instance()
        self.settings = sl.settings

        # run the api if the user want it
        if self.settings.rest_api.active:
            Utils.print_info("Starting REST API Listening port: %s" %
                             self.settings.rest_api.port)
            app = Flask(__name__)
            flask_api = FlaskAPI(app,
                                 port=self.settings.rest_api.port,
                                 brain=self.brain)
            flask_api.daemon = True
            flask_api.start()

        # create an order listener object. This last will the trigger callback before starting
        self.order_listener = OrderListener(self.analyse_order)
        # Wait that the kalliope trigger is pronounced by the user
        self.trigger_instance = self._get_default_trigger()
        self.trigger_instance.start()
        Utils.print_info("Waiting for trigger detection")
Пример #13
0
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.8
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from kalliope.core.ConfigurationManager import SettingLoader
from sys import version_info

sl = SettingLoader.Instance()
settings = sl.settings
module_file_path = "%s/_snowboydetect" % settings.machine

if version_info >= (2, 6, 0):

    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module(
                module_file_path, [dirname(__file__)])
        except ImportError:
            import _snowboydetect
            return _snowboydetect
        if fp is not None:
            try:
                _mod = imp.load_module('_snowboydetect', fp, pathname,
                                       description)
            finally:
                fp.close()
            return _mod
Пример #14
0
 def test_get_default_text_to_speech(self):
     expected_default_text_to_speech = "pico2wave"
     sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
     self.assertEqual(expected_default_text_to_speech,
                      sl._get_default_text_to_speech(self.settings_dict))
     del sl
Пример #15
0
 def test_get_cache_path(self):
     expected_cache_path = '/tmp/kalliope_tts_cache'
     sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
     self.assertEqual(expected_cache_path,
                      sl._get_cache_path(self.settings_dict))
     del sl
Пример #16
0
 def test_get_random_wake_up_answers(self):
     expected_random_wake_up_answers = ['Oui monsieur?']
     sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
     self.assertEqual(expected_random_wake_up_answers,
                      sl._get_random_wake_up_answers(self.settings_dict))
     del sl
Пример #17
0
 def test_get_stts(self):
     stt = Stt(name="google", parameters={'language': 'fr-FR'})
     sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
     self.assertEqual([stt], sl._get_stts(self.settings_dict))
     del sl
Пример #18
0
 def test_get_default_trigger(self):
     expected_default_trigger = "snowboy"
     sl = SettingLoader.Instance(file_path=self.settings_file_to_test)
     self.assertEqual(expected_default_trigger,
                      sl._get_default_trigger(self.settings_dict))
     del sl