本文整理汇总了Python中mycroft.configuration.Configuration类的典型用法代码示例。如果您正苦于以下问题:Python Configuration类的具体用法?Python Configuration怎么用?Python Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
global ws
global config
ws = WebsocketClient()
Configuration.init(ws)
config = Configuration.get()
speech.init(ws)
# Setup control of pulse audio
setup_pulseaudio_handlers(config.get('Audio').get('pulseaudio'))
def echo(message):
try:
_message = json.loads(message)
if 'mycroft.audio.service' not in _message.get('type'):
return
message = json.dumps(_message)
except:
pass
LOG.debug(message)
LOG.info("Staring Audio Services")
ws.on('message', echo)
ws.once('open', load_services_callback)
try:
ws.run_forever()
except KeyboardInterrupt, e:
LOG.exception(e)
speech.shutdown()
sys.exit()
示例2: main
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()
示例3: __init__
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()
示例4: get_skills_dir
def get_skills_dir():
return (
expanduser(os.environ.get('SKILLS_DIR', '')) or
expanduser(join(
Configuration.get()['data_dir'],
Configuration.get()['skills']['msm']['directory']
))
)
示例5: __init__
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()
示例6: handle_speak
def handle_speak(event):
"""
Handle "speak" message
"""
config = Configuration.get()
Configuration.init(bus)
global _last_stop_signal
# Get conversation ID
if event.context and 'ident' in event.context:
ident = event.context['ident']
else:
ident = 'unknown'
start = time.time() # Time of speech request
with lock:
stopwatch = Stopwatch()
stopwatch.start()
utterance = event.data['utterance']
if event.data.get('expect_response', False):
# When expect_response is requested, the listener will be restarted
# at the end of the next bit of spoken audio.
bus.once('recognizer_loop:audio_output_end', _start_listener)
# This is a bit of a hack for Picroft. The analog audio on a Pi blocks
# for 30 seconds fairly often, so we don't want to break on periods
# (decreasing the chance of encountering the block). But we will
# keep the split for non-Picroft installs since it give user feedback
# faster on longer phrases.
#
# TODO: Remove or make an option? This is really a hack, anyway,
# so we likely will want to get rid of this when not running on Mimic
if (config.get('enclosure', {}).get('platform') != "picroft" and
len(re.findall('<[^>]*>', utterance)) == 0):
chunks = re.split(r'(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\;|\?)\s',
utterance)
for chunk in chunks:
# Check if somthing has aborted the speech
if (_last_stop_signal > start or
check_for_signal('buttonPress')):
# Clear any newly queued speech
tts.playback.clear()
break
try:
mute_and_speak(chunk, ident)
except KeyboardInterrupt:
raise
except Exception:
LOG.error('Error in mute_and_speak', exc_info=True)
else:
mute_and_speak(utterance, ident)
stopwatch.stop()
report_timing(ident, 'speech', stopwatch, {'utterance': utterance,
'tts': tts.__class__.__name__})
示例7: __init__
def __init__(self):
self.ws = WebsocketClient()
self.ws.on("open", self.on_ws_open)
Configuration.init(self.ws)
self.config = Configuration.get().get("enclosure")
self.__init_serial()
self.reader = EnclosureReader(self.serial, self.ws)
self.writer = EnclosureWriter(self.serial, self.ws)
# initiates the web sockets on display manager
# NOTE: this is a temporary place to initiate display manager sockets
initiate_display_manager_ws()
示例8: __init_client
def __init_client(self, params):
config = Configuration.get().get("websocket")
if not params.host:
params.host = config.get('host')
if not params.port:
params.port = config.get('port')
self.ws = WebsocketClient(host=params.host,
port=params.port,
ssl=params.use_ssl)
# Connect configuration manager to message bus to receive updates
Configuration.init(self.ws)
示例9: __init__
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)
示例10: main
def main():
global bus
reset_sigint_handler()
# Create PID file, prevent multiple instancesof this service
mycroft.lock.Lock('skills')
# Connect this Skill management process to the Mycroft Messagebus
bus = WebsocketClient()
Configuration.init(bus)
bus.on('message', create_echo_function('SKILLS'))
# Startup will be called after the connection with the Messagebus is done
bus.once('open', _starting_up)
create_daemon(bus.run_forever)
wait_for_exit_signal()
shutdown()
示例11: __init__
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
示例12: main
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()
示例13: __init__
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()
示例14: run
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)
示例15: create
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