Exemplo n.º 1
0
    def updateMicState(self):
        micState = natlink.getMicState()

        # filter redundant change events
        if self.lastMicState is None or micState != self.lastMicState:
            if micState == "off":
                # without this when you say 'snore' you get an utterance
                # that never has an end, because Natlink only gives the
                # processing beginning callback and not the end.
                self.sendMsg(makeJSON(RecognitionStateMsg("success")))

            if self.sendMsg(makeJSON(MicStateMsg(micState))):
                self.lastMicState = micState
Exemplo n.º 2
0
    def updateMicState(self):
        micState = natlink.getMicState()

        # filter redundant change events
        if self.lastMicState is None or micState != self.lastMicState:
            if micState == "off":
                # without this when you say 'snore' you get an utterance
                # that never has an end, because Natlink only gives the
                # processing beginning callback and not the end.
                self.sendMsg(makeJSON(RecognitionStateMsg("success")))

            if self.sendMsg(makeJSON(MicStateMsg(micState))):
                self.lastMicState = micState
Exemplo n.º 3
0
    def loadRule(self, hash):
        if hash not in self.hashedRules:
            log.error("Client requested rule we don't have! Hash: %s" % hash)
            return

        log.info("Loading rule: %s" % (self.hashedRules[hash].rule.name,))
        self.sendMsg(makeJSON(LoadRuleMsg(self.stripActions(hash))))
Exemplo n.º 4
0
    def loadRule(self, hash):
        if hash not in self.hashedRules:
            log.error("Client requested rule we don't have! Hash: %s" % hash)
            return

        log.info("Loading rule: %s" % (self.hashedRules[hash].rule.name, ))
        self.sendMsg(makeJSON(LoadRuleMsg(self.stripActions(hash))))
Exemplo n.º 5
0
    def heartbeat(self):
        if self.other is None:
            return        

        # heartbeating
        newtime = time.time()
        if newtime - self.lastMsgSendTime > 1 and self.other is not None:
            self.sendMsg(makeJSON(HeartbeatMsg("")))
Exemplo n.º 6
0
 def commitRuleEnabledness(self, ev=None):
     if self.activatedRules == self.activatedLastCommit:
         return
     self.activatedLastCommit = copy(self.activatedRules)
     log.info("Committing rule activations: %s" %
              [rule.rule.name for rule in self.activatedRules])
     self.sendMsg(
         makeJSON(EnableRulesMsg([r.hash for r in self.activatedRules])))
Exemplo n.º 7
0
 def onWordList(self, ev):
     # We track whether word lists have changed in the server class because
     # the classes generating the WordListEvents are not able to detect if
     # sending fails.
     if ev.name in self.lastWordList and self.lastWordList[ev.name] == ev.words:
         return
     #log.info("Sending updated word list [%s] -- [%s]" % (ev.name, ev.words))
     # log.info("Sending updated word list [%s]" % (ev.name,))
     self.sendMsg(makeJSON(WordListMsg(ev.name, ev.words)))
     self.lastWordList[ev.name] = copy(ev.words)
Exemplo n.º 8
0
 def onWordList(self, ev):
     # We track whether word lists have changed in the server class because
     # the classes generating the WordListEvents are not able to detect if
     # sending fails.
     if ev.name in self.lastWordList and self.lastWordList[
             ev.name] == ev.words:
         return
     #log.info("Sending updated word list [%s] -- [%s]" % (ev.name, ev.words))
     # log.info("Sending updated word list [%s]" % (ev.name,))
     self.sendMsg(makeJSON(WordListMsg(ev.name, ev.words)))
     self.lastWordList[ev.name] = copy(ev.words)
Exemplo n.º 9
0
 def cleanup(self):
     self.globalRuleGrammar.disable()
     self.globalRuleGrammar.unload()
     for hash, grammar in self.hashedRules.items():
         if hasattr(grammar, "unload"):
             log.info("Unloading: [%s]" % grammar.hash)
             grammar.unload()
     self.timer.stop()
     try:
         self.sendMsg(makeJSON(ClientQuitMsg()))
     except socket.error:
         pass
     DragonflyNode.cleanup(self)
Exemplo n.º 10
0
 def cleanup(self):
     self.globalRuleGrammar.disable()
     self.globalRuleGrammar.unload()
     for hash, grammar in self.hashedRules.items():
         if hasattr(grammar, "unload"):
             log.info("Unloading: [%s]" % grammar.hash)
             grammar.unload()
     self.timer.stop()
     try:
         self.sendMsg(makeJSON(ClientQuitMsg()))
     except socket.error:
         pass
     DragonflyNode.cleanup(self)
Exemplo n.º 11
0
 def updateLoadState(self, forceState=None):
     if forceState:
         state = forceState
     else:
         log.info("not forcing")
         state = 'loading'
         if self.activeMasterGrammar:
             log.info("grammars chosen")
             g = self.hashedRules[self.activeMasterGrammar]
             log.info("active? %s" % g.active())
             state = 'done' if g.active() else state
     log.info("last load state [%s] new load state [%s]" % (self.lastLoadState, state))
     if self.lastLoadState is None or self.lastLoadState != state:
         if self.sendMsg(makeJSON(LoadStateMsg(state))):
             self.lastLoadState = state
Exemplo n.º 12
0
    def onMatch(self, grammarString, data):
        if natlink.getMicState() != 'on':
            return

        matches = []
        root = data['_node']
        seriesNode = root.get_child_by_name('series')
        if seriesNode:
            #individualMatches = seriesNode.get_children_by_name('MappingRule')
            individualMatches = self.getChildrenByActorType(
                seriesNode, MappingRule)
            log.info("Matches: %s" % individualMatches)
            for m in individualMatches:
                # TODO: This is a less than ideal hack. MappingRule type children
                # happen for all matches, even those through RuleRefs, so when saying
                # 'pig' you get a match on the series rule, the char rule, and the alpha
                # rule. We filter the latter 2 by only including enabled things like
                # this.
                # ... probably we shuld really only be looking at ReportingAction nodes?
                if m.actor.enabled:
                    matches.append(self.getMatchFromNode(m))

        terminator = root.get_child_by_name('terminator')
        if terminator:
            matches.append(self.getMatchFromNode(terminator))

        if not seriesNode and not terminator:
            # we have a match on a independent rule
            matches.append(self.getMatchFromNode(root))

        # TODO: what about independent activated rules?

        log.info("node tree:")
        log.info(self.pprint(data['_node']))
        log.info("data: %s" % data)

        for m in matches:
            log.info("Sending match: %s" % (m, ))
            self.sendMsg(makeJSON(m))
Exemplo n.º 13
0
    def onMatch(self, grammarString, data):
        if natlink.getMicState() != 'on':
            return

        matches = []
        root = data['_node']
        seriesNode = root.get_child_by_name('series')
        if seriesNode:
            #individualMatches = seriesNode.get_children_by_name('MappingRule')
            individualMatches = self.getChildrenByActorType(seriesNode, MappingRule)
            log.info("Matches: %s" % individualMatches)
            for m in individualMatches:
                # TODO: This is a less than ideal hack. MappingRule type children
                # happen for all matches, even those through RuleRefs, so when saying
                # 'pig' you get a match on the series rule, the char rule, and the alpha
                # rule. We filter the latter 2 by only including enabled things like
                # this.
                # ... probably we shuld really only be looking at ReportingAction nodes?
                if m.actor.enabled:
                    matches.append(self.getMatchFromNode(m))

        terminator = root.get_child_by_name('terminator')
        if terminator:
            matches.append(self.getMatchFromNode(terminator))

        if not seriesNode and not terminator:
            # we have a match on a independent rule
            matches.append(self.getMatchFromNode(root))

        # TODO: what about independent activated rules?

        log.info("node tree:")
        log.info(self.pprint(data['_node']))
        log.info("data: %s" % data)

        for m in matches:
            log.info("Sending match: %s" % (m,))
            self.sendMsg(makeJSON(m))
Exemplo n.º 14
0
 def setRecognitionState(self, state):
     self.recognitionState = state
     log.info("Recognition state: [%s]" % state)
     self.sendMsg(makeJSON(RecognitionStateMsg(state)))
Exemplo n.º 15
0
 def commitRuleEnabledness(self, ev=None):
     if self.activatedRules == self.activatedLastCommit:
         return
     self.activatedLastCommit = copy(self.activatedRules)
     log.info("Committing rule activations: %s" % [rule.rule.name for rule in self.activatedRules])
     self.sendMsg(makeJSON(EnableRulesMsg([r.hash for r in self.activatedRules])))
Exemplo n.º 16
0
 def sendLoadRequest(self, hashes):
     unrequested = hashes - self.requestedLoads
     if unrequested:
         self.requestedLoads.update(unrequested)
         self.sendMsg(makeJSON(RequestRulesMsg(unrequested)))
Exemplo n.º 17
0
 def setRecognitionState(self, state):
     self.recognitionState = state
     log.info("Recognition state: [%s]" % state)
     self.sendMsg(makeJSON(RecognitionStateMsg(state)))
Exemplo n.º 18
0
 def sendLoadRequest(self, hashes):
     unrequested = hashes - self.requestedLoads
     if unrequested:
         self.requestedLoads.update(unrequested)
         self.sendMsg(makeJSON(RequestRulesMsg(unrequested)))