本文整理汇总了Python中mycroft.configuration.Configuration.get方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get方法的具体用法?Python Configuration.get怎么用?Python Configuration.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mycroft.configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"):
super(PreciseHotword, self).__init__(key_phrase, config, lang)
self.update_freq = 24 # in hours
precise_config = Configuration.get()['precise']
self.dist_url = precise_config['dist_url']
self.models_url = precise_config['models_url']
self.exe_name = 'precise-stream'
ww = Configuration.get()['listener']['wake_word']
model_name = ww.replace(' ', '-') + '.pb'
model_folder = expanduser('~/.mycroft/precise')
if not isdir(model_folder):
mkdir(model_folder)
model_path = join(model_folder, model_name)
exe_file = self.find_download_exe()
LOG.info('Found precise executable: ' + exe_file)
self.update_model(model_name, model_path)
args = [exe_file, model_path, '1024']
self.proc = Popen(args, stdin=PIPE, stdout=PIPE)
self.has_found = False
self.cooldown = 20
t = Thread(target=self.check_stdout)
t.daemon = True
t.start()
示例2: get_skills_dir
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def get_skills_dir():
return (
expanduser(os.environ.get('SKILLS_DIR', '')) or
expanduser(join(
Configuration.get()['data_dir'],
Configuration.get()['skills']['msm']['directory']
))
)
示例3: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"):
self.key_phrase = str(key_phrase).lower()
# rough estimate 1 phoneme per 2 chars
self.num_phonemes = len(key_phrase) / 2 + 1
if config is None:
config = Configuration.get().get("hot_words", {})
config = config.get(self.key_phrase, {})
self.config = config
self.listener_config = Configuration.get().get("listener", {})
self.lang = str(self.config.get("lang", lang)).lower()
示例4: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self, args):
params = self.__build_params(args)
if params.config:
Configuration.get([params.config])
if exists(params.lib) and isdir(params.lib):
sys.path.append(params.lib)
sys.path.append(params.dir)
self.dir = params.dir
self.enable_intent = params.enable_intent
self.__init_client(params)
示例5: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self, bus, schedule_file='schedule.json'):
"""
Create an event scheduler thread. Will send messages at a
predetermined time to the registered targets.
Args:
bus: Mycroft messagebus (mycroft.messagebus)
schedule_file: File to store pending events to on shutdown
"""
super(EventScheduler, self).__init__()
data_dir = expanduser(Configuration.get()['data_dir'])
self.events = {}
self.event_lock = Lock()
self.bus = bus
self.isRunning = True
self.schedule_file = join(data_dir, schedule_file)
if self.schedule_file:
self.load()
self.bus.on('mycroft.scheduler.schedule_event',
self.schedule_event_handler)
self.bus.on('mycroft.scheduler.remove_event',
self.remove_event_handler)
self.bus.on('mycroft.scheduler.update_event',
self.update_event_handler)
self.bus.on('mycroft.scheduler.get_event',
self.get_event_handler)
self.start()
示例6: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self, emitter):
self.config = Configuration.get().get('context', {})
self.engine = IntentDeterminationEngine()
# Dictionary for translating a skill id to a name
self.skill_names = {}
# Context related intializations
self.context_keywords = self.config.get('keywords', [])
self.context_max_frames = self.config.get('max_frames', 3)
self.context_timeout = self.config.get('timeout', 2)
self.context_greedy = self.config.get('greedy', False)
self.context_manager = ContextManager(self.context_timeout)
self.emitter = emitter
self.emitter.on('register_vocab', self.handle_register_vocab)
self.emitter.on('register_intent', self.handle_register_intent)
self.emitter.on('recognizer_loop:utterance', self.handle_utterance)
self.emitter.on('detach_intent', self.handle_detach_intent)
self.emitter.on('detach_skill', self.handle_detach_skill)
# Context related handlers
self.emitter.on('add_context', self.handle_add_context)
self.emitter.on('remove_context', self.handle_remove_context)
self.emitter.on('clear_context', self.handle_clear_context)
# Converse method
self.emitter.on('skill.converse.response',
self.handle_converse_response)
self.emitter.on('mycroft.speech.recognition.unknown',
self.reset_converse)
self.emitter.on('mycroft.skills.loaded', self.update_skill_name_dict)
def add_active_skill_handler(message):
self.add_active_skill(message.data['skill_id'])
self.emitter.on('active_skill_request', add_active_skill_handler)
self.active_skills = [] # [skill_id , timestamp]
self.converse_timeout = 5 # minutes to prune active_skills
示例7: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self, bus):
super(SkillManager, self).__init__()
self._stop_event = Event()
self._connected_event = Event()
self.loaded_skills = {}
self.bus = bus
self.enclosure = EnclosureAPI(bus)
# Schedule install/update of default skill
self.msm = self.create_msm()
self.num_install_retries = 0
self.update_interval = Configuration.get()['skills']['update_interval']
self.update_interval = int(self.update_interval * 60 * MINUTES)
self.dot_msm = join(self.msm.skills_dir, '.msm')
if exists(self.dot_msm):
self.next_download = os.path.getmtime(self.dot_msm) + \
self.update_interval
else:
self.next_download = time.time() - 1
# Conversation management
bus.on('skill.converse.request', self.handle_converse_request)
# Update on initial connection
bus.on('mycroft.internet.connected',
lambda x: self._connected_event.set())
# Update upon request
bus.on('skillmanager.update', self.schedule_now)
bus.on('skillmanager.list', self.send_skill_list)
bus.on('skillmanager.deactivate', self.deactivate_skill)
bus.on('skillmanager.keep', self.deactivate_except)
bus.on('skillmanager.activate', self.activate_skill)
示例8: main
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def main():
global ws
# Create PID file, prevent multiple instancesof this service
mycroft.lock.Lock('skills')
# Connect this Skill management process to the websocket
ws = WebsocketClient()
Configuration.init(ws)
ignore_logs = Configuration.get().get("ignore_logs")
# Listen for messages and echo them for logging
def _echo(message):
try:
_message = json.loads(message)
if _message.get("type") in ignore_logs:
return
if _message.get("type") == "registration":
# do not log tokens from registration messages
_message["data"]["token"] = None
message = json.dumps(_message)
except BaseException:
pass
LOG('SKILLS').debug(message)
ws.on('message', _echo)
# Startup will be called after websocket is fully live
ws.once('open', _starting_up)
ws.run_forever()
示例9: __init__
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def __init__(self):
config_core = Configuration.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()
示例10: run
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def run(self):
""" Load skills and update periodically from disk and internet """
self.remove_git_locks()
self._connected_event.wait()
has_loaded = False
# check if skill updates are enabled
update = Configuration.get()["skills"]["auto_update"]
# 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():
# Update skills once an hour if update is enabled
if time.time() >= self.next_download and update:
self.download_skills()
# Look for recently changed skill(s) needing a reload
# checking skills dir and getting all skills there
skill_paths = glob(join(self.msm.skills_dir, '*/'))
still_loading = False
for skill_path in skill_paths:
still_loading = (
self._load_or_reload_skill(skill_path) or
still_loading
)
if not has_loaded and not still_loading and len(skill_paths) > 0:
has_loaded = True
self.bus.emit(Message('mycroft.skills.initialized'))
self._unload_removed(skill_paths)
# Pause briefly before beginning next scan
time.sleep(2)
示例11: _load_config
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def _load_config(self):
"""
Load configuration parameters from configuration
"""
config = Configuration.get()
self.config_core = config
self._config_hash = hash(str(config))
self.lang = config.get('lang')
self.config = config.get('listener')
rate = self.config.get('sample_rate')
device_index = self.config.get('device_index')
device_name = self.config.get('device_name')
if not device_index and device_name:
device_index = find_input_device(device_name)
LOG.debug('Using microphone (None = default): '+str(device_index))
self.microphone = MutableMicrophone(device_index, rate,
mute=self.mute_calls > 0)
# TODO:19.02 - channels are not been used, remove from mycroft.conf
# and from code.
self.microphone.CHANNELS = self.config.get('channels')
self.wakeword_recognizer = self.create_wake_word_recognizer()
# TODO - localization
self.wakeup_recognizer = self.create_wakeup_recognizer()
self.responsive_recognizer = ResponsiveRecognizer(
self.wakeword_recognizer)
self.state = RecognizerLoopState()
示例12: get
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def get(phrase, lang=None, context=None):
"""
Looks up a resource file for the given phrase. If no file
is found, the requested phrase is returned as the string.
This will use the default language for translations.
Args:
phrase (str): resource phrase to retrieve/translate
lang (str): the language to use
context (dict): values to be inserted into the string
Returns:
str: a randomized and/or translated version of the phrase
"""
if not lang:
from mycroft.configuration import Configuration
lang = Configuration.get().get("lang")
filename = "text/" + lang.lower() + "/" + phrase + ".dialog"
template = resolve_resource_file(filename)
if not template:
LOG.debug("Resource file not found: " + filename)
return phrase
stache = MustacheDialogRenderer()
stache.load_template_file("template", template)
if not context:
context = {}
return stache.render("template", context)
示例13: main
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def main():
import tornado.options
lock = Lock("service")
tornado.options.parse_command_line()
def reload_hook():
""" Hook to release lock when autoreload is triggered. """
lock.delete()
autoreload.add_reload_hook(reload_hook)
config = Configuration.get().get("websocket")
host = config.get("host")
port = config.get("port")
route = config.get("route")
validate_param(host, "websocket.host")
validate_param(port, "websocket.port")
validate_param(route, "websocket.route")
routes = [
(route, WebsocketEventHandler)
]
application = web.Application(routes, **settings)
application.listen(port, host)
ioloop.IOLoop.instance().start()
示例14: create
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def create():
"""
Factory method to create a TTS engine based on configuration.
The configuration file ``mycroft.conf`` contains a ``tts`` section with
the name of a TTS module to be read by this method.
"tts": {
"module": <engine_name>
}
"""
from mycroft.tts.remote_tts import RemoteTTS
config = Configuration.get().get('tts', {})
module = config.get('module', 'mimic')
lang = config.get(module).get('lang')
voice = config.get(module).get('voice')
clazz = TTSFactory.CLASSES.get(module)
if issubclass(clazz, RemoteTTS):
url = config.get(module).get('url')
tts = clazz(lang, voice, url)
else:
tts = clazz(lang, voice)
tts.validator.validate()
return tts
示例15: main
# 需要导入模块: from mycroft.configuration import Configuration [as 别名]
# 或者: from mycroft.configuration.Configuration import get [as 别名]
def main():
global ws
global loop
global config
lock = PIDLock("voice")
ws = WebsocketClient()
config = Configuration.get()
Configuration.init(ws)
loop = RecognizerLoop()
loop.on('recognizer_loop:utterance', handle_utterance)
loop.on('speak', handle_speak)
loop.on('recognizer_loop:record_begin', handle_record_begin)
loop.on('recognizer_loop:wakeword', handle_wakeword)
loop.on('recognizer_loop:record_end', handle_record_end)
loop.on('recognizer_loop:no_internet', handle_no_internet)
ws.on('open', handle_open)
ws.on('complete_intent_failure', handle_complete_intent_failure)
ws.on('recognizer_loop:sleep', handle_sleep)
ws.on('recognizer_loop:wake_up', handle_wake_up)
ws.on('mycroft.mic.mute', handle_mic_mute)
ws.on('mycroft.mic.unmute', handle_mic_unmute)
ws.on("mycroft.paired", handle_paired)
ws.on('recognizer_loop:audio_output_start', handle_audio_start)
ws.on('recognizer_loop:audio_output_end', handle_audio_end)
ws.on('mycroft.stop', handle_stop)
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()
try:
loop.run()
except KeyboardInterrupt, e:
LOG.exception(e)
sys.exit()