コード例 #1
0
ファイル: service.py プロジェクト: gdumee/LISA-CLIENT-Linux
def makeService(config):
    global LisaFactory

    # Get configuration
    if config['configuration']:
        if ConfigManager.setConfiguration(config_file = config['configuration']) == False:
            Speaker.start()
            Speaker.speak(ConfigManager.getConfiguration()['trans']("error_conf"))
            return

    # Multiservice mode
    multi = service.MultiService()
    multi.setServiceParent(application)

    # Ctrl-C handler
    signal.signal(signal.SIGINT, sigint_handler)

    # Create factory
    LisaFactory = LisaClientFactory()

    # Start client factory
    configuration = ConfigManager.getConfiguration()
    if configuration['enable_secure_mode'] == True:
        lisaclientService = internet.SSLClient(configuration['lisa_url'], configuration['lisa_port'], LisaFactory, ClientAuthContextFactory())
    else:
        lisaclientService = internet.TCPClient(configuration['lisa_url'], configuration['lisa_port'], LisaFactory)
    lisaclientService.setServiceParent(multi)

    return multi
コード例 #2
0
ファイル: service.py プロジェクト: gdumee/LISA-CLIENT-Linux
    def sendChatToServer(self, message, outcome = None):
        # If not connected to the server
        if self.active_protocol is None:
            Speaker.speak(self._('no_server'))
            self.warn_on_connect = True
            return

        # Send chat to server
        self.active_protocol.sendChatToServer(message = message, outcome = outcome)
コード例 #3
0
ファイル: service.py プロジェクト: ant1fr/LISA-CLIENT-Linux
    def clientConnectionFailed(self, connector, reason):
        # Warn on first failure
        if self.first_time == True:
            Speaker.speak("no_server")
            self.first_time = False

        # Retry
        self.resetDelay()
        log.err("Connection failed. Reason:", reason.getErrorMessage())
        ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
コード例 #4
0
ファイル: service.py プロジェクト: gdumee/LISA-CLIENT-Linux
    def lineReceived(self, data):
        """
        Data received callback
        The nolistener in configuration is here to let the travis build pass without loading gst
        """
        datajson = json.loads(data)
        if self.debug_input == True:
            log.msg("INPUT: {0}".format(str(datajson)))

        if datajson.has_key("type"):
            datajson['type'] = datajson['type'].lower()
            if datajson['type'] == 'chat':
                if datajson.has_key('nolistener') == False:
                    Speaker.speak(datajson['message'])

            if datajson['type'].lower() == 'error':
                log.err(datajson['message'])
                if datajson.has_key('nolistener') == False:
                    Speaker.speak(datajson['message'])

            elif datajson['type'] == 'command':
                datajson['command'] = datajson['command'].lower()
                if datajson['command'] == 'login ack':
                    # Get Bot name
                    botname = datajson['bot_name'].lower()
                    log.msg("setting botname to {0}".format(botname))
                    self.factory.setBotName(botname)

                elif datajson['command'] == 'ask':
                    if datajson.has_key('nolistener') == False and datajson.has_key('message'):
                        Speaker.speak(datajson['message'])

                    # Set continuous mode
                    if datajson.has_key('nolistener') == False:
                        wit_context = None
                        if datajson.has_key('wit_context') == True:
                            wit_context = datajson['wit_context']
                        self.factory.setContinuousMode(enabled = True, wit_context = wit_context)

                elif datajson['command'] == 'kws':
                    if datajson.has_key('nolistener') == False and datajson.has_key('message'):
                        Speaker.speak(datajson['message'])

                    # Set KWS mode
                    if datajson.has_key('nolistener') == False:
                        wit_context = None
                        if datajson.has_key('wit_context') == True:
                            wit_context = datajson['wit_context']
                        self.factory.setContinuousMode(enabled = False, wit_context = wit_context)

        else:
            # Send to TTS queue
            if datajson.has_key('nolistener') == False and datajson.has_key('message'):
                Speaker.speak(datajson['message'])
コード例 #5
0
ファイル: service.py プロジェクト: gdumee/LISA-CLIENT-Linux
    def buildProtocol(self, addr):
        # Reset retry delay
        self.resetDelay()

        # Warn on connection
        if self.warn_on_connect == True:
            Speaker.speak(self._('back_ready'))
            self.warn_on_connect = False

        # Return protocol
        self.active_protocol = LisaClient(factory = self)
        return self.active_protocol
コード例 #6
0
ファイル: service.py プロジェクト: ant1fr/LISA-CLIENT-Linux
def sigint_handler(signum, frame):
    global LisaFactory

    # Unregister handler, next Ctrl-C will kill app
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Stop factory
    LisaFactory.stopTrying()

    # Stop reactor
    reactor.stop()

    # Stop speaker
    Speaker.stop()
コード例 #7
0
ファイル: service.py プロジェクト: ant1fr/LISA-CLIENT-Linux
    def lineReceived(self, data):
        """
        Data received callback
        The nolistener in configuration is here to let the travis build pass without loading gst
        """

        datajson = json.loads(data)
        if self.debug_input == True:
            log.msg("INPUT: " + unicode(datajson))

        if datajson.has_key("type"):
            if datajson["type"] == "chat":
                if datajson.has_key("nolistener") == False:
                    Speaker.speak(datajson["body"])

            elif datajson["type"] == "command":
                if datajson["command"] == "LOGIN":
                    # Get Bot name
                    botname = unicode(datajson["bot_name"])
                    log.msg("setting botname to %s" % botname)
                    self.botname = botname

                    # Send TTS
                    if datajson.has_key("nolistener") == False:
                        Speaker.start()
                        Speaker.speak(datajson["body"])

                    # Create listener
                    if datajson.has_key("nolistener") == False and not self.listener:
                        self.listener = Listener(lisa_client=self, botname=botname)

                # TODO seems a bit more complicated than I thought. I think the reply will be another type like "answer"
                # TODO and will contains a unique ID. On server side, the question will be stored in mongodb so it will
                # TODO let possible the multi user / multi client. Questions need to implement a lifetime too.
                # TODO For the soundqueue, I will need a callback system to be sure to play the audio before recording
                elif datajson["command"] == "ASK":
                    if datajson.has_key("nolistener") == False:
                        Speaker.speak(datajson["body"])

                    # Start record
                    if datajson.has_key("nolistener") == False and self.listener:
                        self.listener.record()

        else:
            # Send to TTS queue
            if datajson.has_key("nolistener") == False:
                Speaker.speak(datajson["body"])
コード例 #8
0
ファイル: service.py プロジェクト: ant1fr/LISA-CLIENT-Linux
def makeService(config):
    global LisaFactory

    # Get configuration
    if config["configuration"]:
        ConfigManagerSingleton.get().setConfiguration(config["configuration"])
    configuration = ConfigManagerSingleton.get().getConfiguration()

    # Check vital configuration
    if configuration.has_key("lisa_url") == False or configuration.has_key("lisa_engine_port_ssl") == False:
        Speaker.start()
        Speaker.speak("error_conf")
        return

    # Multiservice mode
    multi = service.MultiService()
    multi.setServiceParent(application)

    # Ctrl-C handler
    signal.signal(signal.SIGINT, sigint_handler)

    # Create factory
    LisaFactory = LisaClientFactory()
    LisaFactory.Init()

    # Start client
    if configuration.has_key("enable_secure_mode") and configuration["enable_secure_mode"] == True:
        lisaclientService = internet.TCPClient(
            configuration["lisa_url"], configuration["lisa_engine_port_ssl"], LisaFactory, CtxFactory()
        )
    else:
        lisaclientService = internet.TCPClient(
            configuration["lisa_url"], configuration["lisa_engine_port"], LisaFactory
        )
    lisaclientService.setServiceParent(multi)

    return multi
コード例 #9
0
ファイル: service.py プロジェクト: gdumee/LISA-CLIENT-Linux
 def stop(self):
     # Stop workers
     self.running_state = False
     self.listener.stop()
     self.listener = None
     Speaker.stop()
コード例 #10
0
ファイル: service.py プロジェクト: gdumee/LISA-CLIENT-Linux
 def startFactory(self):
     # Create workers
     if self.listener is None:
         self.listener = Listener(factory = self)
         Speaker.start(listener = self.listener)