コード例 #1
0
def load_online_features(dir, file_name):
    """
    load POI or road network and covert key from str to tuple
    """
    data = load_json_data(dir, file_name)
    data = {}

    return data
コード例 #2
0
def load_rid_freqs(dir, file_name):
    """
    load rid freqs and convert key from str to int
    """
    rid_freqs = load_json_data(dir, file_name)
    rid_freqs = {int(k): int(v)
                 for k, v in rid_freqs.items()}  # convert key from str to int

    return rid_freqs
コード例 #3
0
 def set_language(self, language):
     """
     Sets _language of resolver and load keywords based on _language.
     :param str language: _language code
     :rtype: None
     :return: void method
     """
     assert (isinstance(language, str))
     logger.debug("Command resolver _language = {}.".format(language))
     self._language = language
     keywords = load_json_data(LANG_KEYWORDS[language])
     self._set_keywords(keywords)
コード例 #4
0
def load_rn_dict(dir, file_name):
    """
    This function will be use in rate2gps.
    """
    rn_dict = load_json_data(dir, file_name)
    new_rn_dict = {}
    for k, v in rn_dict.items():
        new_rn_dict[int(k)] = {}
        new_rn_dict[int(k)]['coords'] = [
            SPoint(coord[0], coord[1]) for coord in v['coords']
        ]
        # convert str to SPoint() to calculate distance
        new_rn_dict[int(k)]['length'] = v['length']
        new_rn_dict[int(k)]['level'] = v['level']
    del rn_dict
    return new_rn_dict
コード例 #5
0
from config.config import COMMANDS, logger, FAIL, FATAL
from exceptions.exception_handler import ExceptionHandler
from exceptions.exceptions import VoiceAssistantException
from services.common.action_result import ActionResult
from utils.utils import load_json_data
from utils import data_extraction

commands = load_json_data(COMMANDS)


class ServiceExecutor:
    def __init__(self, service_pool={}):
        """
        service_command_methods - dictionary that contains all exec methods for service - key:service_alias,
        value:dictionary with the following structure - key: service method, value:dictionary of service method
        arguments e.g.mailing:{send_email:{recipient : None, subject :None, content:None}}
        :param service_pool: cache of services objects
        """

        self._service_command_methods = {}
        self._populate_service_command_methods()
        self._service_pool = service_pool
        self._language = None

    def set_services_language(self, language):
        """
        Sets the _language to all services.
        :param (str or None) language: _language code
        :rtype: None
        :return: void method
        """
コード例 #6
0
 def __init__(self, language="en"):
     self._api = Translator()
     self._language = language
     #TODO:this field is tight coupled with serbian _language usage logic, solve that
     self._langs_in_serbian = load_json_data(LANGUAGES_IN_SERBIAN)
コード例 #7
0
from exceptions.exception_handler import ExceptionHandler
from config.config import LANG_CODES, LANGUAGES_IN_SERBIAN, SUCCESS, FAIL, logger, FATAL, PATH_TO_AUDIO_DIR, \
    CALL_MESSAGE
from services.common.action_result import ActionResult
from utils.utils import load_json_data, convert_latin_to_cyrillic, get_language_code, delete_all_mp3_files, \
    delete_log_file

LANGUAGES = load_json_data(LANG_CODES)
SR_LANGUAGES = load_json_data(LANGUAGES_IN_SERBIAN)


class Controller:
    def __init__(self, recognizer, speaker, command_resolver, executor):
        self._recognizer = recognizer #stt Recognizer
        self._speaker = speaker #tts Speaker
        self._command_resolver = command_resolver #CommandResolver
        self._executor = executor #ServiceExecutor
        self._language = "en" #operating language
        self._speaking_language = "en" #speaking language

    # public methods
    def set_language(self, language_str):
        """
        Sets the operating language of the voice assistant (recognizer, speaker, executor, command resolver and services
        ). Raises KeyError/ValueError if invalid language is set.
        :param str language_str: string that contains language name
        :rtype: None
        :return: void method
        """
        assert (isinstance(language_str, str))
        try: