本文整理汇总了Python中mycroft.messagebus.client.ws.WebsocketClient.on方法的典型用法代码示例。如果您正苦于以下问题:Python WebsocketClient.on方法的具体用法?Python WebsocketClient.on怎么用?Python WebsocketClient.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mycroft.messagebus.client.ws.WebsocketClient
的用法示例。
在下文中一共展示了WebsocketClient.on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
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
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
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)
ignore_logs = ConfigurationManager.instance().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:
pass
logger.debug(message)
ws.on('message', _echo)
# Startup will be called after websocket is full live
ws.once('open', _starting_up)
ws.run_forever()
示例3: simple_cli
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def simple_cli():
global bus
global bSimple
bSimple = True
bus = WebsocketClient() # Mycroft messagebus connection
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()
bus.on('speak', handle_speak)
try:
while True:
# Sleep for a while so all the output that results
# from the previous command finishes before we print.
time.sleep(1.5)
print("Input (Ctrl+C to quit):")
line = sys.stdin.readline()
bus.emit(Message("recognizer_loop:utterance",
{'utterances': [line.strip()]}))
except KeyboardInterrupt as e:
# User hit Ctrl+C to quit
print("")
except KeyboardInterrupt as e:
LOG.exception(e)
event_thread.exit()
sys.exit()
示例4: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def main():
global client
global loop
client = WebsocketClient()
device_index = config.get('speech_client').get('device_index')
if device_index:
device_index = int(device_index)
loop = RecognizerLoop(device_index=device_index)
loop.on('recognizer_loop:utterance', handle_utterance)
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('speak', handle_speak)
client.on('speak', handle_speak)
client.on(
'multi_utterance_intent_failure',
handle_multi_utterance_intent_failure)
client.on('recognizer_loop:sleep', handle_sleep)
client.on('recognizer_loop:wake_up', handle_wake_up)
client.on('mycroft.stop', handle_stop)
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()
try:
subprocess.call('echo "eyes.reset" >/dev/ttyAMA0', shell=True)
except:
pass
try:
loop.run()
except KeyboardInterrupt, e:
logger.exception(e)
event_thread.exit()
sys.exit()
示例5: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def main():
global client
global loop
client = WebsocketClient()
device_index = config.get('speech_client').get('device_index')
if device_index:
device_index = int(device_index)
loop = RecognizerLoop(device_index=device_index)
loop.on('recognizer_loop:listening', handle_listening)
loop.on('recognizer_loop:wakeword', handle_wakeword)
loop.on('recognizer_loop:utterance', handle_utterance)
loop.on('speak', handle_speak)
client.on('speak', handle_speak)
client.on(
'multi_utterance_intent_failure',
handle_multi_utterance_intent_failure)
client.on('recognizer_loop:sleep', handle_sleep)
client.on('recognizer_loop:wake_up', handle_wake_up)
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()
try:
loop.run()
except KeyboardInterrupt, e:
event_thread.exit()
sys.exit()
示例6: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
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()
示例7: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def main():
global client
client = WebsocketClient()
if not '--quiet' in sys.argv:
client.on('speak', handle_speak)
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()
try:
while True:
print("Input:")
line = sys.stdin.readline()
client.emit(Message("recognizer_loop:utterance", metadata={'utterances': [line.strip()]}))
except KeyboardInterrupt, e:
event_thread.exit()
sys.exit()
示例8: __init__
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
class Enclosure:
"""
Serves as a communication interface between Arduino and Mycroft Core.
``Enclosure`` initializes and aggregates all enclosures implementation.
E.g. ``EnclosureEyes``, ``EnclosureMouth`` and ``EnclosureArduino``
It also listens to the basis events in order to perform those core actions
on the unit.
E.g. Start and Stop talk animation
"""
def __init__(self):
self.__init_serial()
self.client = WebsocketClient()
self.reader = EnclosureReader(self.serial, self.client)
self.writer = EnclosureWriter(self.serial, self.client)
self.eyes = EnclosureEyes(self.client, self.writer)
self.mouth = EnclosureMouth(self.client, self.writer)
self.system = EnclosureArduino(self.client, self.writer)
self.__init_events()
def __init_serial(self):
try:
self.config = ConfigurationManager.get_config().get("enclosure")
self.port = self.config.get("port")
self.rate = int(self.config.get("rate"))
self.timeout = int(self.config.get("timeout"))
self.serial = serial.serial_for_url(
url=self.port, baudrate=self.rate, timeout=self.timeout)
LOGGER.info(
"Connected to: " + self.port + " rate: " + str(self.rate) +
" timeout: " + str(self.timeout))
except:
LOGGER.error(
"It is not possible to connect to serial port: " + self.port)
raise
def __init_events(self):
self.client.on('recognizer_loop:listening', self.mouth.listen)
self.client.on('recognizer_loop:audio_output_start', self.mouth.talk)
self.client.on('recognizer_loop:audio_output_end', self.mouth.reset)
self.client.on('recognizer_loop:wakeword', self.eyes.blink)
def run(self):
try:
self.client.run_forever()
except Exception as e:
LOGGER.error("Client error: {0}".format(e))
self.stop()
def stop(self):
self.writer.stop()
self.reader.stop()
self.serial.close()
示例9: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def main():
global client
client = WebsocketClient()
def echo(message):
try:
_message = json.loads(message)
if _message.get("message_type") == "registration":
# do not log tokens from registration messages
_message["metadata"]["token"] = None
message = json.dumps(_message)
except:
pass
logger.debug(message)
client.on('message', echo)
client.once('open', load_skills_callback)
client.run_forever()
示例10: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def main():
global ws
ws = WebsocketClient()
ConfigurationManager.init(ws)
def echo(message):
try:
_message = json.loads(message)
if _message.get("type") == "registration":
# do not log tokens from registration messages
_message["data"]["token"] = None
message = json.dumps(_message)
except:
pass
logger.debug(message)
ws.on('message', echo)
ws.once('open', load_skills_callback)
ws.run_forever()
示例11: SkillContainer
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
class SkillContainer(object):
def __init__(self, args):
parser = argparse.ArgumentParser()
parser.add_argument("--dependency-dir", default="./lib")
parser.add_argument("--messagebus-host", default=messagebus_config.get("host"))
parser.add_argument("--messagebus-port", type=int, default=messagebus_config.get("port"))
parser.add_argument("--use-ssl", action='store_true', default=False)
parser.add_argument("--enable-intent-skill", action='store_true', default=False)
parser.add_argument("skill_directory", default=os.path.dirname(__file__))
parsed_args = parser.parse_args(args)
if os.path.exists(parsed_args.dependency_dir):
sys.path.append(parsed_args.dependency_dir)
self.skill_directory = parsed_args.skill_directory
self.enable_intent_skill = parsed_args.enable_intent_skill
self.client = WebsocketClient(host=parsed_args.messagebus_host,
port=parsed_args.messagebus_port,
ssl=parsed_args.use_ssl)
def try_load_skill(self):
if self.enable_intent_skill:
intent_skill = create_intent_skill()
intent_skill.bind(self.client)
intent_skill.initialize()
skill_descriptor = create_skill_descriptor(self.skill_directory)
load_skill(skill_descriptor, self.client)
def run(self):
self.client.on('message', logger.debug)
self.client.on('open', self.try_load_skill)
self.client.on('error', logger.error)
self.client.run_forever()
示例12: catchInput
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def catchInput(queryInput):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.gnome.Shell","/com/mycroftaignome/MycroftGnomeResult")
getText = remote_object.sendQuery(guioutputstring,dbus_interface = "com.mycroftaignome.MycroftAiGnomeBox")
print getText
global client
client = WebsocketClient()
client.on('speak', handle_speak)
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()
try:
while True:
print("Input:")
queryInput= object.sendQuery(guioutputstring,dbus_interface = "com.mycroftaignome.MycroftAiGnomeBox")
client.emit(
Message("recognizer_loop:utterance",
metadata={'utterances': [queryInput]}))
break
except KeyboardInterrupt, e:
logger.exception(e)
event_thread.exit()
sys.exit()
示例13: SkillContainer
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
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
self.enable_intent_skill = params.enable_intent_skill
self.__init_client(params)
@staticmethod
def __build_params(args):
parser = argparse.ArgumentParser()
parser.add_argument("--config", default="./mycroft.ini")
parser.add_argument("dir", nargs='?', default=dirname(__file__))
parser.add_argument("--lib", default="./lib")
parser.add_argument("--host", default=None)
parser.add_argument("--port", default=None)
parser.add_argument("--use-ssl", action='store_true', default=False)
parser.add_argument("--enable-intent-skill", action='store_true',
default=False)
return parser.parse_args(args)
def __init_client(self, params):
config = ConfigurationManager.get().get("messagebus_client")
if not params.host:
params.host = config.get('host')
if not params.port:
params.port = config.get('port')
self.client = WebsocketClient(host=params.host,
port=params.port,
ssl=params.use_ssl)
def try_load_skill(self):
if self.enable_intent_skill:
intent_skill = create_intent_skill()
intent_skill.bind(self.client)
intent_skill.initialize()
skill_descriptor = create_skill_descriptor(self.dir)
load_skill(skill_descriptor, self.client)
def run(self):
self.client.on('message', logger.debug)
self.client.on('open', self.try_load_skill)
self.client.on('error', logger.error)
self.client.run_forever()
示例14: DevicePairingClient
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
class DevicePairingClient(object):
def __init__(self, config=_config, pairing_code=None):
self.config = config
self.paired = False
self.ws_client = WebsocketClient(host=config.get("host"),
port=config.get("port"),
path=config.get("route"),
ssl=str2bool(config.get("ssl")))
self.identity_manager = IdentityManager()
self.identity = self.identity_manager.identity
self.pairing_code = (
pairing_code if pairing_code else generate_pairing_code())
def on_registration(self, message):
# TODO: actually accept the configuration message and store it in
# identity
identity = self.identity_manager.get()
register_payload = message.metadata
if register_payload.get("device_id") == identity.device_id:
identity.token = register_payload.get('token')
identity.owner = register_payload.get('user')
self.identity_manager.update(identity)
self.ws_client.close()
self.paired = True
def send_device_info(self):
msg = Message("device_info",
metadata={
"pairing_code": self.pairing_code,
"device_id": self.identity.device_id
})
self.ws_client.emit(msg)
@staticmethod
def print_error(message):
print(repr(message))
def run(self):
self.ws_client.on('registration', self.on_registration)
self.ws_client.on('open', self.send_device_info)
self.ws_client.on('error', self.print_error)
self.ws_client.run_forever()
示例15: init_display_manager_bus_connection
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import on [as 别名]
def init_display_manager_bus_connection():
""" Connects the display manager to the messagebus """
LOG.info("Connecting display manager to messagebus")
# Should remove needs to be an object so it can be referenced in functions
# [https://stackoverflow.com/questions/986006/how-do-i-pass-a-variable-by-reference]
display_manager = DisplayManager()
should_remove = [True]
def check_flag(flag):
if flag[0] is True:
display_manager.remove_active()
def set_delay(event=None):
should_remove[0] = True
Timer(2, check_flag, [should_remove]).start()
def set_remove_flag(event=None):
should_remove[0] = False
def connect():
bus.run_forever()
def remove_wake_word():
data = _read_data()
if "active_skill" in data and data["active_skill"] == "wakeword":
display_manager.remove_active()
def set_wakeword_skill(event=None):
display_manager.set_active("wakeword")
Timer(10, remove_wake_word).start()
bus = WebsocketClient()
bus.on('recognizer_loop:audio_output_end', set_delay)
bus.on('recognizer_loop:audio_output_start', set_remove_flag)
bus.on('recognizer_loop:record_begin', set_wakeword_skill)
event_thread = Thread(target=connect)
event_thread.setDaemon(True)
event_thread.start()