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
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"])
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
def startFactory(self): # Create workers if self.listener is None: self.listener = Listener(factory = self) Speaker.start(listener = self.listener)