Example #1
0
    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
Example #2
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)
Example #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
        self.settings = SettingLoader.get_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))
Example #4
0
    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
Example #5
0
 def decorated(*args, **kwargs):
     settings = SettingLoader.get_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)
Example #6
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
Example #7
0
 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
Example #8
0
    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
Example #9
0
    def __init__(self, brain_file=None):
        # override brain
        self.brain_file = brain_file
        # get settings
        self.settings = SettingLoader.get_settings()
        locale.setlocale(locale.LC_ALL, '')

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

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

        self.show_main_menu()
Example #10
0
 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
Example #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
     :param stt: Speech to text plugin name to load. If not provided,
     we will load the default one set in settings
     """
     # 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
     self.settings = SettingLoader.get_settings()
Example #12
0
    def __init__(self, brain_file=None):
        self.brain_file = brain_file
        # get global configuration
        self.settings = SettingLoader.get_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_file=brain_file)
            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")
Example #13
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
        self.settings = SettingLoader.get_settings()
        locale.setlocale(locale.LC_ALL, '')

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

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

        self.show_main_menu()
Example #14
0
def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    settings = SettingLoader.get_settings()
    return username == settings.rest_api.login and password == settings.rest_api.password
Example #15
0
# coding: utf8
import logging
import re
from collections import Counter

from flask import Flask
from core.RestAPI.FlaskAPI import FlaskAPI
from core import OrderAnalyser
from core.ConfigurationManager import SettingLoader
from core.ConfigurationManager import YAMLLoader
from core.ConfigurationManager.BrainLoader import BrainLoader

from neurons import Systemdate
from neurons.tasker_autoremote.tasker_autoremote import Tasker_autoremote

logging.basicConfig()
logger = logging.getLogger("kalliope")
logger.setLevel(logging.DEBUG)

# order = "quelle heure est-il"
# oa = OrderAnalyser(order=order)
# oa.start()

SettingLoader.get_settings()

# app = Flask(__name__)
# flask_api = FlaskAPI(app)
# flask_api.start()
Example #16
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 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
    _snowboydetect = swig_import_helper()
    del swig_import_helper
Example #17
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
Example #18
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
Example #19
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
Example #20
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
Example #21
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