class AssistantSkill:
    """
    This class is the parent of all skill classes.
    """
    first_activation = True
    console_manager = ConsoleManager()
    engine = engines.TTSEngine() if GENERAL_SETTINGS.get(
        'response_in_speech') else engines.TTTEngine()

    @classmethod
    def response(cls, text):
        cls.engine.assistant_response(text)

    @classmethod
    def extract_tags(cls, voice_transcript, tags):
        """
        This method identifies the tags from the user transcript for a specific skill.

        e.x
        Let's that the user says "hi jarvis!".
        The skill analyzer will match it with enable_assistant skill which has tags 'hi, hello ..'
        This method will identify the that the enabled word was the 'hi' not the hello.

        :param voice_transcript: string
        :param tags: string
        :return: set
        """
        try:
            transcript_words = voice_transcript.split()
            tags = tags.split(',')
            return set(transcript_words).intersection(tags)
        except Exception as e:
            logging.error("Failed to extract tags with message {0}".format(e))
            return set()
Exemplo n.º 2
0
    def __init__(self, settings_, db):
        self.settings = settings_
        self.db = db
        self.input_engine = engines.STTEngine(
                                        pause_threshold=self.settings.SPEECH_RECOGNITION.get('pause_threshold'),
                                        energy_theshold=self.settings.SPEECH_RECOGNITION.get('energy_threshold'),
                                        ambient_duration=self.settings.SPEECH_RECOGNITION.get('ambient_duration'),
                                        dynamic_energy_threshold=self.settings.SPEECH_RECOGNITION.get(
                                            'dynamic_energy_threshold'),
                                        sr=sr
                                        ) if db.get_documents(collection='general_settings')[0]['input_mode'] == InputMode.VOICE.value \
            else engines.TTTEngine()

        self.output_engine = engines.TTSEngine() if db.get_documents(collection='general_settings')[0]['response_in_speech'] \
            else engines.TTTEngine()
        self.response_creator = ResponseCreator()
        self.skill_analyzer = SkillAnalyzer(
            weight_measure=TfidfVectorizer,
            similarity_measure=cosine_similarity,
            args=self.settings.SKILL_ANALYZER.get('args'),
            sensitivity=self.settings.SKILL_ANALYZER.get('sensitivity'),
            db=self.db)
 def set_engine(cls):
     if not cls.engine and not db.is_collection_empty(
             collection='general_settings'):
         cls.engine = engines.TTSEngine() if db.get_documents(collection='general_settings')[0]['response_in_speech']\
                 else engines.TTTEngine()
Exemplo n.º 4
0
import jarvis.engines as engines

# ----------------------------------------------------------------------------------------------------------------------
# Create a Console & Rotating file logger
# ----------------------------------------------------------------------------------------------------------------------
config.dictConfig(ROOT_LOG_CONF)

# ----------------------------------------------------------------------------------------------------------------------
# Clear log file in each assistant fresh start
# ----------------------------------------------------------------------------------------------------------------------
with open(ROOT_LOG_CONF['handlers']['file']['filename'], 'r+') as f:
    f.truncate(0)

# ----------------------------------------------------------------------------------------------------------------------
# Configuare MongoDB, load skills and settings
# ----------------------------------------------------------------------------------------------------------------------
configure_MongoDB(db, settings)

# ----------------------------------------------------------------------------------------------------------------------
# Get assistant settings
# ----------------------------------------------------------------------------------------------------------------------
input_mode = db.get_documents(collection='general_settings')[0]['input_mode']
response_in_speech = db.get_documents(collection='general_settings')[0]['response_in_speech']
assistant_name = db.get_documents(collection='general_settings')[0]['assistant_name']

# ----------------------------------------------------------------------------------------------------------------------
# Create assistant input and output engine instances
# ----------------------------------------------------------------------------------------------------------------------
input_engine = engines.STTEngine() if input_mode == InputMode.VOICE.value else engines.TTTEngine()
output_engine = engines.TTSEngine() if response_in_speech else engines.TTTEngine()