def __init__(self, name, emitter=None): self.name = name self.bind(emitter) self.config_core = ConfigurationManager.get() self.config = self.config_core.get(name) self.dialog_renderer = None self.file_system = FileSystemAccess(join('skills', name)) self.registered_intents = [] self.log = getLogger(name)
import os import sys import urllib2 import webbrowser from adapt.intent import IntentBuilder from adapt.tools.text.tokenizer import EnglishTokenizer from mycroft.skills.core import MycroftSkill from mycroft.util.log import getLogger logger = getLogger(__name__) __author__ = 'seanfitz' IFL_TEMPLATE = "http://www.google.com/search?&sourceid=navclient&btnI=I&q=%s" class DesktopLauncherSkill(MycroftSkill): def __init__(self): MycroftSkill.__init__(self, "DesktopLauncherSkill") self.appmap = {} def initialize(self): try: import gio except: sys.path.append("/usr/lib/python2.7/dist-packages") try: import gio except: logger.error("Could not import gio") return
from mycroft.messagebus.message import Message from mycroft.tts import tts_factory from mycroft.util.log import getLogger from xml.dom import minidom import os from traceback import print_exc import dbus.mainloop.glib from gi.repository import GLib tts = tts_factory.create() client = None mutex = Lock() logger = getLogger("CLIClient") guioutputstring = '' def handle_speak(event): mutex.acquire() client.emit(Message("recognizer_loop:audio_output_start")) try: utterance = event.metadata.get('utterance') logger.info("Speak: " + utterance) global guioutputstring guioutputstring = utterance logger.info("guioutputstring: " + guioutputstring) dbusout() tts.execute(utterance) finally: mutex.release()
from mycroft.util.log import getLogger __author__ = 'augustnmonteiro' # The following lines are replaced during the release process. # START_VERSION_BLOCK CORE_VERSION_MAJOR = 0 CORE_VERSION_MINOR = 8 CORE_VERSION_BUILD = 18 # END_VERSION_BLOCK CORE_VERSION_STR = (str(CORE_VERSION_MAJOR) + "." + str(CORE_VERSION_MINOR) + "." + str(CORE_VERSION_BUILD)) LOG = getLogger(__name__) class VersionManager(object): __location = "/opt/mycroft/version.json" @staticmethod def get(): if (exists(VersionManager.__location) and isfile(VersionManager.__location)): try: with open(VersionManager.__location) as f: return json.load(f) except: LOG.error("Failed to load version from '%s'" % VersionManager.__location)
import subprocess import sys from threading import Thread, Lock import re from mycroft.client.speech.listener import RecognizerLoop from mycroft.configuration import ConfigurationManager from mycroft.messagebus.client.ws import WebsocketClient from mycroft.messagebus.message import Message from mycroft.tts import tts_factory from mycroft.util.log import getLogger from mycroft.util import kill, connected logger = getLogger("SpeechClient") client = None tts = tts_factory.create() mutex = Lock() loop = None config = ConfigurationManager.get() def handle_record_begin(): logger.info("Begin Recording...") client.emit(Message('recognizer_loop:record_begin')) def handle_record_end(): logger.info("End Recording...")
import json import requests from speech_recognition import UnknownValueError from mycroft.configuration.config import ConfigurationManager from mycroft.identity import IdentityManager from mycroft.metrics import Stopwatch from mycroft.util import CerberusAccessDenied from mycroft.util.log import getLogger from mycroft.util.setup_base import get_version __author__ = 'seanfitz' log = getLogger("RecognizerWrapper") config = ConfigurationManager.get_config().get('speech_client') class GoogleRecognizerWrapper(object): def __init__(self, recognizer): self.recognizer = recognizer def transcribe(self, audio, language="en-US", show_all=False, metrics=None): key = config.get('goog_api_key') return self.recognizer.recognize_google(audio, key=key,
import os import wave from glob import glob import pyee from os.path import dirname, join from speech_recognition import AudioSource from mycroft.client.speech.local_recognizer import LocalRecognizer from mycroft.client.speech.mic import ResponsiveRecognizer from mycroft.util.log import getLogger from mycroft.client.speech.mic import logger as speech_logger __author__ = 'wolfgange3311999' logger = getLogger('audio_test_runner') class FileStream(object): def __init__(self, file_name): self.file = wave.open(file_name, 'rb') self.size = self.file.getnframes() self.sample_rate = self.file.getframerate() self.sample_width = self.file.getsampwidth() def read(self, chunk_size): if abs(self.file.tell() - self.size) < 10: raise EOFError return self.file.readframes(chunk_size) def close(self): self.file.close()
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>. import argparse import sys from os.path import dirname, exists, isdir from mycroft.configuration import ConfigurationManager from mycroft.messagebus.client.ws import WebsocketClient from mycroft.skills.core import create_skill_descriptor, load_skill from mycroft.skills.intent import Intent from mycroft.util.log import getLogger __author__ = 'seanfitz' LOG = getLogger("SkillContainer") class SkillContainer(object): def __init__(self, args): params = self.__build_params(args) if params.config: ConfigurationManager.load_local([params.config]) if exists(params.lib) and isdir(params.lib): sys.path.append(params.lib) sys.path.append(params.dir) self.dir = params.dir
import json from mycroft.messagebus.client.ws import WebsocketClient from mycroft.skills.core import load_skills from mycroft.util.log import getLogger logger = getLogger("Skills") __author__ = 'seanfitz' client = None def load_skills_callback(): global client load_skills(client) def connect(): global client client.run_forever() def main(): global client client = WebsocketClient() def echo(message): try: _message = json.loads(message) if _message.get("message_type") == "registration":
import json import requests from speech_recognition import UnknownValueError from mycroft.configuration.config import ConfigurationManager from mycroft.identity import IdentityManager from mycroft.metrics import Stopwatch from mycroft.util import CerberusAccessDenied from mycroft.util.log import getLogger from mycroft.util.setup_base import get_version __author__ = 'seanfitz' log = getLogger("RecognizerWrapper") config = ConfigurationManager.get_config().get('speech_client') class GoogleRecognizerWrapper(object): def __init__(self, recognizer): self.recognizer = recognizer def transcribe(self, audio, language="en-US", show_all=False, metrics=None): key = config.get('goog_api_key') return self.recognizer.recognize_google(audio, key=key, language=language, show_all=show_all) class WitRecognizerWrapper(object): def __init__(self, recognizer): self.recognizer = recognizer
from threading import Thread from time import sleep from pyric import pyw from wifi import Cell from mycroft.client.enclosure.api import EnclosureAPI from mycroft.messagebus.client.ws import WebsocketClient from mycroft.messagebus.message import Message from mycroft.util import connected, wait_while_speaking, is_speaking, \ stop_speaking from mycroft.util.log import getLogger __author__ = 'aatchison and penrods' LOG = getLogger("WiFiClient") SCRIPT_DIR = dirname(realpath(__file__)) WPA_SUPPLICANT = '''#mycroft_p2p_start ctrl_interface=/var/run/wpa_supplicant driver_param=p2p_device=1 update_config=1 device_name=mycroft-holmes-i device_type=1-0050F204-1 p2p_go_intent=10 p2p_go_ht40=1 network={ ssid="MYCROFT" psk="12345678"
# 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/>. from abc import ABCMeta, abstractmethod from speech_recognition import Recognizer from mycroft.api import STTApi from mycroft.configuration import ConfigurationManager from mycroft.util.log import getLogger __author__ = "jdorleans" LOG = getLogger("STT") class STT(object): __metaclass__ = ABCMeta def __init__(self): config_core = ConfigurationManager.get() self.lang = str(self.init_language(config_core)) config_stt = config_core.get("stt", {}) self.config = config_stt.get(config_stt.get("module"), {}) self.credential = self.config.get("credential", {}) self.recognizer = Recognizer() @staticmethod def init_language(config_core):
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>. import json import threading import time import requests from mycroft.util import str2bool from mycroft.util.log import getLogger from mycroft.configuration import ConfigurationManager from mycroft.session import SessionManager from mycroft.util.setup_base import get_version config = ConfigurationManager.get().get('metrics_client') metrics_log = getLogger("METRICS") class Stopwatch(object): def __init__(self): self.timestamp = None def start(self): self.timestamp = time.time() def lap(self): cur_time = time.time() start_time = self.timestamp self.timestamp = cur_time return cur_time - start_time
# (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/>. from mycroft.messagebus.message import Message from mycroft.util.log import getLogger __author__ = 'jdorleans' LOGGER = getLogger(__name__) class EnclosureAPI: """ This API is intended to be used to interface with the hardware that is running Mycroft. It exposes all possible commands which can be sent to a Mycroft enclosure implementation. Different enclosure implementations may implement this differently and/or may ignore certain API calls completely. For example, the eyes_color() API might be ignore on a Mycroft that uses simple LEDs which only turn on/off, or not at all on an implementation where there is no face at all. """ def __init__(self, ws):
# (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/>. from mycroft.util.log import getLogger __author__ = 'jdorleans' LOGGER = getLogger(__name__) class EnclosureMouth: """ Listens to enclosure commands for Mycroft's Mouth. Performs the associated command on Arduino by writing on the Serial port. """ def __init__(self, client, writer): self.client = client self.writer = writer self.__init_events() def __init_events(self):
# 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/>. import pystache import os import random from mycroft.util import log, resolve_resource_file __author__ = 'seanfitz' logger = log.getLogger(__name__) __doc__ = """ """ class MustacheDialogRenderer(object): """ A dialog template renderer based on the mustache templating language. """ def __init__(self): self.templates = {} def load_template_file(self, template_name, filename): """
from mycroft.client.enclosure.arduino import EnclosureArduino from mycroft.client.enclosure.eyes import EnclosureEyes from mycroft.client.enclosure.mouth import EnclosureMouth from mycroft.client.enclosure.weather import EnclosureWeather from mycroft.configuration import ConfigurationManager from mycroft.messagebus.client.ws import WebsocketClient from mycroft.messagebus.message import Message from mycroft.util import kill, str2bool from mycroft.util import play_wav from mycroft.util.log import getLogger from mycroft.util.audio_test import record __author__ = 'aatchison + jdorleans + iward' LOGGER = getLogger("EnclosureClient") class EnclosureReader(Thread): """ Reads data from Serial port. Listens to all commands sent by Arduino that must be be performed on Mycroft Core. E.g. Mycroft Stop Feature #. Arduino sends a Stop command after a button press on a Mycroft unit #. ``EnclosureReader`` captures the Stop command #. Notify all Mycroft Core processes (e.g. skills) to be stopped Note: A command is identified by a line break
from mycroft.configuration import ConfigurationManager from mycroft.dialog import DialogLoader from mycroft.filesystem import FileSystemAccess from mycroft.messagebus.message import Message from mycroft.util.log import getLogger __author__ = 'seanfitz' PRIMARY_SKILLS = ['intent', 'wake'] BLACKLISTED_SKILLS = ["send_sms"] SKILLS_BASEDIR = dirname(__file__) THIRD_PARTY_SKILLS_DIR = "/opt/mycroft/third_party" MainModule = '__init__' logger = getLogger(__name__) def load_vocab_from_file(path, vocab_type, emitter): with open(path, 'r') as voc_file: for line in voc_file.readlines(): parts = line.strip().split("|") entity = parts[0] emitter.emit( Message("register_vocab", metadata={ 'start': entity, 'end': vocab_type })) for alias in parts[1:]: