def onHotwordDetected(self, client, data, msg): siteId = commons.parseSiteId(msg) payload = commons.payload(msg) if not self._multiDetectionsHolder: self.ThreadManager.doLater(interval=0.5, func=self.handleMultiDetection) self._multiDetectionsHolder.append(payload['siteId']) user = constants.UNKNOWN_USER if payload['modelType'] == 'personal': speaker = payload['modelId'] users = { name.lower(): user for name, user in self.UserManager.users.items() } if speaker in users: user = users[speaker].name self.DialogSessionManager.preSession(siteId, user) SuperManager.getInstance().broadcast(method='onHotword', exceptions=[self.name], propagateToModules=True, siteId=siteId)
def addSession(self, sessionId: str, message: MQTTMessage) -> DialogSession: """ Adds a session from an existing pre session. If the pre session doesn't exist it means the session was started programatically so we create a session :param sessionId: str :param message: dict """ siteId = commons.parseSiteId(message) session = self._preSessions.pop(siteId, DialogSession(siteId)) session.extend(message, sessionId) self._sessions[sessionId] = session return session
def onSnipsSay(self, client, data, msg: mqtt.MQTTMessage): sessionId = commons.parseSessionId(msg) payload = commons.payload(msg) session = self.DialogSessionManager.getSession(sessionId) if session: session.payload = payload siteId = session.siteId else: siteId = commons.parseSiteId(msg) if 'text' in payload: module = self.ModuleManager.getModuleInstance('ContextSensitive') if module: module.addChat(text=payload['text'], siteId=siteId) SuperManager.getInstance().broadcast(method='onSay', exceptions=[self.name], propagateToModules=True, session=session)
def onMessage(self, client, userdata, message: mqtt.MQTTMessage): try: if message.topic == constants.TOPIC_AUDIO_FRAME: SuperManager.getInstance().broadcast(method='onAudioFrame', exceptions=[self.name], propagateToModules=True, message=message) return if message.topic == constants.TOPIC_INTENT_PARSED: return siteId = commons.parseSiteId(message) payload = commons.payload(message) sessionId = commons.parseSessionId(message) session = self.DialogSessionManager.getSession(sessionId) if session: session.update(message) if self.MultiIntentManager.processMessage(message): return if message.topic == constants.TOPIC_TEXT_CAPTURED and session: return elif message.topic == constants.TOPIC_ASR_START_LISTENING: self.ModuleManager.broadcast('onListening', siteId=siteId) return elif message.topic == constants.TOPIC_HOTWORD_TOGGLE_ON: self.ModuleManager.broadcast('onHotwordToggleOn', siteId=siteId) return session = self.DialogSessionManager.getSession(sessionId) if not session: session = self.DeviceManager.onMessage(message) if not session: self._logger.warning( f'[{self.name}] Got a message on ({message.topic}) but nobody knows what to do with it' ) self.endDialog(sessionId) return redQueen = self.ModuleManager.getModuleInstance('RedQueen') if redQueen and not redQueen.inTheMood(session): return customData = session.customData if 'intent' in payload and payload['intent'][ 'confidenceScore'] < self.ConfigManager.getAliceConfigByName( 'probabilityTreshold'): if session.notUnderstood < 3: session.notUnderstood = session.notUnderstood + 1 self.continueDialog(sessionId=sessionId, text=self.TalkManager.randomTalk( 'notUnderstood', module='system')) else: del session.notUnderstood self.endDialog(sessionId=sessionId, text=self.TalkManager.randomTalk( 'notUnderstoodEnd', module='system')) return del session.notUnderstood module = self.ModuleManager.getModuleInstance('ContextSensitive') if module: module.addToMessageHistory(session) modules = self.ModuleManager.getModules() for modul in modules.values(): module = modul['instance'] try: consumed = module.filterIntent( message.topic, session) and module.onMessage( message.topic, session) except AccessLevelTooLow: # The command was recognized but required higher access level return # Authentication might end the session directly from a module if not self.DialogSessionManager.getSession(sessionId): return if self.MultiIntentManager.isProcessing(sessionId): self.MultiIntentManager.processNextIntent(sessionId) return elif consumed: return self._logger.warning( f"[{self.name}] Intent \"{message.topic}\" wasn't consumed by any module" ) self.endDialog(sessionId) except Exception as e: try: self._logger.info(traceback.print_exc()) except: pass self._logger.error( f'[{self.name}] Uncaught error in onMessage: {e}')