mycroft-core/mycroft/skills/main.py

425 lines
15 KiB
Python
Raw Normal View History

# Copyright 2016 Mycroft AI, Inc.
#
# This file is part of Mycroft Core.
#
# Mycroft Core is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mycroft Core is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
import json
2017-04-17 17:25:27 +00:00
import os
2017-04-25 19:15:19 +00:00
import subprocess
import sys
2017-02-21 05:43:50 +00:00
import time
2017-04-06 01:01:40 +00:00
from os.path import exists, join
from threading import Timer, Thread, Event
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
2017-04-05 22:11:45 +00:00
from mycroft import MYCROFT_ROOT_PATH
2016-06-17 18:47:25 +00:00
from mycroft.configuration import ConfigurationManager
2017-04-17 17:25:27 +00:00
from mycroft.lock import Lock # Creates PID file for single instance
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
from mycroft.messagebus.client.ws import WebsocketClient
2017-04-06 23:08:23 +00:00
from mycroft.messagebus.message import Message
2017-04-06 01:01:40 +00:00
from mycroft.skills.core import load_skill, create_skill_descriptor, \
MainModule, FallbackSkill
from mycroft.skills.intent_service import IntentService
from mycroft.skills.padatious_service import PadatiousService
from mycroft.skills.event_scheduler import EventScheduler
2017-04-25 22:18:43 +00:00
from mycroft.util import connected
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
from mycroft.util.log import getLogger
from mycroft.api import is_paired
import mycroft.dialog
2016-09-17 02:08:53 +00:00
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
logger = getLogger("Skills")
__author__ = 'seanfitz'
ws = None
event_scheduler = None
2017-02-21 05:43:50 +00:00
loaded_skills = {}
last_modified_skill = 0
2017-02-22 00:00:11 +00:00
skill_reload_thread = None
skills_manager_timer = None
skills_config = ConfigurationManager.instance().get("skills")
BLACKLISTED_SKILLS = skills_config.get("blacklisted_skills", [])
PRIORITY_SKILLS = skills_config.get("priority_skills", [])
SKILLS_DIR = '/opt/mycroft/skills'
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
installer_config = ConfigurationManager.instance().get("SkillInstallerSkill")
MSM_BIN = installer_config.get("path", join(MYCROFT_ROOT_PATH, 'msm', 'msm'))
2017-04-05 22:11:45 +00:00
2017-03-14 16:12:34 +00:00
2017-02-21 05:43:50 +00:00
def connect():
global ws
2017-02-21 05:43:50 +00:00
ws.run_forever()
2017-04-25 19:15:19 +00:00
def install_default_skills(speak=True):
"""
Install default skill set using msm.
Args:
speak (optional): Enable response for success. Default True
"""
2017-04-25 19:15:19 +00:00
if exists(MSM_BIN):
p = subprocess.Popen(MSM_BIN + " default", stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
res = p.returncode
if res == 0 and speak:
# ws.emit(Message("speak", {
# 'utterance': mycroft.dialog.get("skills updated")}))
pass
2017-04-28 00:32:48 +00:00
elif not connected():
logger.error('msm failed, network connection is not available')
2017-04-28 00:32:48 +00:00
ws.emit(Message("speak", {
'utterance': mycroft.dialog.get("no network connection")}))
elif res != 0:
logger.error('msm failed with error {}: {}'.format(res, output))
ws.emit(Message("speak", {
'utterance': mycroft.dialog.get(
"sorry I couldn't install default skills")}))
2017-04-25 19:15:19 +00:00
else:
logger.error("Unable to invoke Mycroft Skill Manager: " + MSM_BIN)
2017-04-06 23:08:23 +00:00
def skills_manager(message):
"""
skills_manager runs on a Timer every hour and checks for updated
skills.
"""
global skills_manager_timer
if connected():
if skills_manager_timer is None:
pass
# Install default skills and look for updates via Github
logger.debug("==== Invoking Mycroft Skill Manager: " + MSM_BIN)
install_default_skills(False)
# Perform check again once and hour
2017-04-25 19:15:19 +00:00
skills_manager_timer = Timer(3600, _skills_manager_dispatch)
2017-04-06 23:08:23 +00:00
skills_manager_timer.daemon = True
skills_manager_timer.start()
def _skills_manager_dispatch():
2017-08-21 15:05:03 +00:00
"""
Thread function to trigger skill_manager over message bus.
"""
global ws
2017-04-06 23:08:23 +00:00
ws.emit(Message("skill_manager", {}))
def _starting_up():
"""
Start loading skills.
Starts
- reloading of skills when needed
- a timer to check for internet connection
- a timer for updating skills every hour
- adapt intent service
- padatious intent service
"""
global ws, skill_reload_thread, event_scheduler
2017-02-21 05:43:50 +00:00
ws.on('intent_failure', FallbackSkill.make_intent_failure_handler(ws))
# Create skill_manager listener and invoke the first time
2017-04-06 23:08:23 +00:00
ws.on('skill_manager', skills_manager)
2017-04-25 22:18:43 +00:00
ws.on('mycroft.internet.connected', install_default_skills)
2017-04-25 19:18:02 +00:00
ws.emit(Message('skill_manager', {}))
2017-04-06 23:08:23 +00:00
# Create the Intent manager, which converts utterances to intents
# This is the heart of the voice invoked skill system
PadatiousService(ws)
IntentService(ws)
event_scheduler = EventScheduler(ws)
# Create a thread that monitors the loaded skills, looking for updates
skill_reload_thread = WatchSkills()
2017-02-22 00:00:11 +00:00
skill_reload_thread.daemon = True
skill_reload_thread.start()
2016-12-20 21:19:22 +00:00
# Wait until skills have been loaded once before starting to check
# network connection
skill_reload_thread.wait_loaded_priority()
check_connection()
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
2017-04-25 22:18:43 +00:00
def check_connection():
2017-08-21 15:05:03 +00:00
"""
Check for network connection. If not paired trigger pairing.
Runs as a Timer every second until connection is detected.
"""
2017-04-25 22:18:43 +00:00
if connected():
ws.emit(Message('mycroft.internet.connected'))
# check for pairing, if not automatically start pairing
if not is_paired():
# begin the process
payload = {
'utterances': ["pair my device"],
'lang': "en-us"
}
ws.emit(Message("recognizer_loop:utterance", payload))
2017-04-25 22:18:43 +00:00
else:
thread = Timer(1, check_connection)
thread.daemon = True
thread.start()
def _get_last_modified_date(path):
"""
Get last modified date excluding compiled python files, hidden
directories and the settings.json file.
Arg:
path: skill directory to check
Returns: time of last change
"""
last_date = 0
root_dir, subdirs, files = os.walk(path).next()
# get subdirs and remove hidden ones
subdirs = [s for s in subdirs if not s.startswith('.')]
for subdir in subdirs:
2017-08-22 06:45:06 +00:00
for root, _, _ in os.walk(join(path, subdir)):
base = os.path.basename(root)
# checking if is a hidden path
if not base.startswith(".") and not base.startswith("/."):
last_date = max(last_date, os.path.getmtime(root))
# check files of interest in the skill root directory
files = [f for f in files
if not f.endswith('.pyc') and f != 'settings.json']
for f in files:
last_date = max(last_date, os.path.getmtime(os.path.join(path, f)))
return last_date
def load_skill_list(skills_to_load):
"""
load list of specific skills.
Args:
skills_to_load (list): list of skill directories to load
"""
if exists(SKILLS_DIR):
# checking skills dir and getting all priority skills there
skill_list = [folder for folder in filter(
lambda x: os.path.isdir(os.path.join(SKILLS_DIR, x)),
os.listdir(SKILLS_DIR)) if folder in skills_to_load]
for skill_folder in skill_list:
skill = {"id": hash(os.path.join(SKILLS_DIR, skill_folder))}
skill["path"] = os.path.join(SKILLS_DIR, skill_folder)
# checking if is a skill
if not MainModule + ".py" in os.listdir(skill["path"]):
continue
# getting the newest modified date of skill
last_mod = _get_last_modified_date(skill["path"])
skill["last_modified"] = last_mod
# loading skill
skill["loaded"] = True
skill["instance"] = load_skill(
create_skill_descriptor(skill["path"]),
ws, skill["id"])
loaded_skills[skill_folder] = skill
class WatchSkills(Thread):
2017-08-21 15:05:03 +00:00
"""
Thread function to reload skills when a change is detected.
"""
def __init__(self):
super(WatchSkills, self).__init__()
self._stop_event = Event()
self._loaded_once = Event()
self._loaded_priority = Event()
def run(self):
global ws, loaded_skills, last_modified_skill
# Load priority skills first by order
load_skill_list(PRIORITY_SKILLS)
self._loaded_priority.set()
# Scan the file folder that contains Skills. If a Skill is updated,
# unload the existing version from memory and reload from the disk.
while not self._stop_event.is_set():
if exists(SKILLS_DIR):
# checking skills dir and getting all skills there
list = filter(lambda x: os.path.isdir(
os.path.join(SKILLS_DIR, x)), os.listdir(SKILLS_DIR))
for skill_folder in list:
if skill_folder not in loaded_skills:
loaded_skills[skill_folder] = {
"id": hash(os.path.join(SKILLS_DIR, skill_folder))
}
skill = loaded_skills.get(skill_folder)
skill["path"] = os.path.join(SKILLS_DIR, skill_folder)
# checking if is a skill
if not MainModule + ".py" in os.listdir(skill["path"]):
continue
# getting the newest modified date of skill
last_mod = _get_last_modified_date(skill["path"])
skill["last_modified"] = last_mod
modified = skill.get("last_modified", 0)
# checking if skill is loaded and wasn't modified
if skill.get(
"loaded") and modified <= last_modified_skill:
continue
# checking if skill was modified
elif (skill.get("instance") and modified >
last_modified_skill):
# checking if skill should be reloaded
if not skill["instance"].reload_skill:
continue
logger.debug("Reloading Skill: " + skill_folder)
# removing listeners and stopping threads
skill["instance"].shutdown()
# -2 since two local references that are known
refs = sys.getrefcount(skill["instance"]) - 2
if refs > 0:
logger.warn(
"After shutdown of {} there are still "
"{} references remaining. The skill "
"won't be cleaned from memory."
.format(skill['instance'].name, refs))
del skill["instance"]
skill["loaded"] = True
skill["instance"] = load_skill(
create_skill_descriptor(skill["path"]),
ws, skill["id"],
BLACKLISTED_SKILLS)
# get the last modified skill
modified_dates = map(lambda x: x.get("last_modified"),
loaded_skills.values())
if len(modified_dates) > 0:
last_modified_skill = max(modified_dates)
if not self._loaded_once.is_set():
self._loaded_once.set()
# Pause briefly before beginning next scan
time.sleep(2)
def wait_loaded_priority(self):
"""
Block until priority skills have loaded
"""
while not self._loaded_priority.is_set():
time.sleep(1)
def wait_loaded_once(self):
"""
Block until skills have loaded at least once.
"""
while not self._loaded_once.is_set():
time.sleep(1)
def stop(self):
"""
Stop the thread.
"""
self._stop_event.set()
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
def handle_converse_request(message):
2017-08-21 15:05:03 +00:00
"""
handle_converse_request checks if the targeted skill id can handle
conversation.
"""
skill_id = int(message.data["skill_id"])
utterances = message.data["utterances"]
lang = message.data["lang"]
global ws, loaded_skills
# loop trough skills list and call converse for skill with skill_id
for skill in loaded_skills:
if loaded_skills[skill]["id"] == skill_id:
try:
instance = loaded_skills[skill]["instance"]
except:
logger.error("converse requested but skill not loaded")
ws.emit(Message("skill.converse.response", {
"skill_id": 0, "result": False}))
return
try:
result = instance.converse(utterances, lang)
ws.emit(Message("skill.converse.response", {
"skill_id": skill_id, "result": result}))
return
except:
logger.error(
"Converse method malformed for skill " + str(skill_id))
2017-08-21 15:05:03 +00:00
ws.emit(Message("skill.converse.response",
{"skill_id": 0, "result": False}))
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
def main():
global ws
lock = Lock('skills') # prevent multiple instances of this service
# Connect this Skill management process to the websocket
ws = WebsocketClient()
ConfigurationManager.init(ws)
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
ignore_logs = ConfigurationManager.instance().get("ignore_logs")
2017-04-06 17:45:28 +00:00
# Listen for messages and echo them for logging
def _echo(message):
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
try:
_message = json.loads(message)
2017-04-06 17:45:28 +00:00
if _message.get("type") in ignore_logs:
return
if _message.get("type") == "registration":
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
# do not log tokens from registration messages
_message["data"]["token"] = None
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
message = json.dumps(_message)
except:
pass
logger.debug(message)
2017-04-17 17:25:27 +00:00
ws.on('message', _echo)
ws.on('skill.converse.request', handle_converse_request)
# Startup will be called after websocket is full live
ws.once('open', _starting_up)
ws.run_forever()
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
if event_scheduler:
event_scheduler.shutdown()
# Do a clean shutdown of all skills and terminate all running threads
2017-02-21 05:43:50 +00:00
for skill in loaded_skills:
try:
loaded_skills[skill]['instance'].shutdown()
except:
pass
if skills_manager_timer:
skills_manager_timer.cancel()
2017-02-22 00:00:11 +00:00
if skill_reload_thread:
skill_reload_thread.stop()
skill_reload_thread.join()
2017-02-22 00:00:11 +00:00
finally:
sys.exit()