当前位置: 首页>>代码示例>>Python>>正文


Python ws.WebsocketClient类代码示例

本文整理汇总了Python中mycroft.messagebus.client.ws.WebsocketClient的典型用法代码示例。如果您正苦于以下问题:Python WebsocketClient类的具体用法?Python WebsocketClient怎么用?Python WebsocketClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebsocketClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: simple_cli

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()
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:25,代码来源:text_client.py

示例2: setUp

    def setUp(self):
        """
        This sets up for testing the message buss

        This requires starting the mycroft service and creating two
        WebsocketClient object to talk with eachother.  Not this is
        threaded and will require cleanup
        """
        # start the mycroft service. and get the pid of the script.
        self.pid = Popen(["python", "mycroft/messagebus/service/main.py"]).pid
        # delay to allow the service to start up.
        time.sleep(10)
        # Create the two web clients
        self.ws1 = WebsocketClient()
        self.ws2 = WebsocketClient()
        # init the flags for handler's
        self.handle1 = False
        self.handle2 = False
        # Start threads to handle websockets
        Thread(target=self.ws1.run_forever).start()
        Thread(target=self.ws2.run_forever).start()
        # Sleep to give the websockets to startup before adding handlers
        time.sleep(10)
        # Setup handlers for each of the messages.
        self.ws1.on('ws1.message', self.onHandle1)
        self.ws2.on('ws2.message', self.onHandle2)
开发者ID:Ceda-EI,项目名称:mycroft-core,代码行数:26,代码来源:messagebus_test.py

示例3: __init__

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()
开发者ID:Cliabhach,项目名称:mycroft-core,代码行数:57,代码来源:enclosure.py

示例4: main

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)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()
    try:
        loop.run()
    except KeyboardInterrupt, e:
        logger.exception(e)
        event_thread.exit()
        sys.exit()
开发者ID:Acidburn0zzz,项目名称:mycroft-core,代码行数:28,代码来源:main.py

示例5: SkillContainer

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()
开发者ID:BK-University,项目名称:mycroft-core,代码行数:34,代码来源:container.py

示例6: __init__

    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)
        sys.path.append(parsed_args.skill_directory)

        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)
开发者ID:Cliabhach,项目名称:mycroft-core,代码行数:26,代码来源:container.py

示例7: 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()
开发者ID:Dark5ide,项目名称:mycroft-core,代码行数:16,代码来源:__main__.py

示例8: main

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()
开发者ID:BK-University,项目名称:mycroft-core,代码行数:16,代码来源:cli.py

示例9: 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()
开发者ID:antlarr,项目名称:mycroft-core,代码行数:30,代码来源:main.py

示例10: 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

        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()
开发者ID:Acidburn0zzz,项目名称:mycroft-core,代码行数:55,代码来源:container.py

示例11: main

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()
开发者ID:Wolfgange3311999,项目名称:mycroft-core,代码行数:31,代码来源:main.py

示例12: stop_speaking

def stop_speaking(ws=None):
    from mycroft.messagebus.client.ws import WebsocketClient
    from mycroft.messagebus.message import Message

    if ws is None:
        ws = WebsocketClient()
    # TODO: Less hacky approach to this once Audio Manager is implemented
    # Skills should only be able to stop speech they've initiated

    create_signal('stoppingTTS')
    ws.emit(Message('mycroft.audio.speech.stop'))

    # Block until stopped
    while check_for_signal("isSpeaking", -1):
        time.sleep(0.25)

    # This consumes the signal
    check_for_signal('stoppingTTS')
开发者ID:aatchison,项目名称:mycroft-core,代码行数:18,代码来源:__init__.py

示例13: __init__

 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.__register_events()
开发者ID:khellan,项目名称:mycroft-core,代码行数:9,代码来源:enclosure.py

示例14: __init__

 def __init__(self, config=_config, pairing_code=None):
     self.config = config
     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()
开发者ID:BK-University,项目名称:mycroft-core,代码行数:9,代码来源:client.py

示例15: __init__

 def __init__(self):
     self.iface = pyw.winterfaces()[0]
     self.ap = AccessPoint(self.iface)
     self.server = None
     self.ws = WebsocketClient()
     self.enclosure = EnclosureAPI(self.ws)
     self.init_events()
     self.conn_monitor = None
     self.conn_monitor_stop = threading.Event()
     self.starting = False
开发者ID:Holly-Buteau,项目名称:mycroft-core,代码行数:10,代码来源:main.py


注:本文中的mycroft.messagebus.client.ws.WebsocketClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。