def initialize(self):
        self.load(self.testGram)
        # problem of Dragon not waking on initialisation when in sleep,
        # exacerbated by background noise.
        # Seems that cannot change micState until it is waiting in sleeping
        # mode. Waiting in initialisation in natlink delays  Dragon start-up.
        # polling produces a ~68 seconds wait for sleeping mode to activate.
        # TODO: to avoid this delay, need to catch signal from DNS post NatLink
        # init. ( temporary solution is to test the dimensions of monitor)
        monitorRects=[mon[2] for mon in win32api.EnumDisplayMonitors(None, None) if
                      mon[2] == (0,0,1024,768)]
        if not monitorRects:
            print("not car monitor")
            self.activateSet(['normalState'],exclusive=0)
        else:
            STEP=4
            count=0
            micstate=natlink.getMicState()
            print "micstate: {0}, {1} sec wait".format(micstate, count)

            # poll until Dragon is in sleep state (select "start dragon in sleep
            # state" option in Dragon options)
            while micstate not in ['sleeping', 'on']: #'off':
                time.sleep(STEP)
                count+=STEP
                micstate=natlink.getMicState()
                print "polling micstate: {0}, {1} sec wait".format(micstate, count)

            natlink.setMicState('on')
            micstate=natlink.getMicState()
            print "micstate: {0}, {1} sec wait".format(micstate, count)

            # now Dragon is on, put in an exclusive state waiting for "switch
            # active listener" grammar
            self.activateSet(['notListening'],exclusive=1)
示例#2
0
 def _sync_mode(cls):
     """
     Synchronizes Caster exclusivity modes an with DNS/DPI GUI built-in modes state.
     """
     # TODO: Implement set_engine_mode logic with modes not just mic_state.
     mic_state = cls.get_mic_mode()
     if mic_state is None:
         cls.mic_state = natlink.getMicState()
     else:
         if natlink.getMicState() != mic_state:
             cls.set_mic_mode(natlink.getMicState())
示例#3
0
文件: toggler.py 项目: j127/caster
def toggle():
    if natlink.getMicState()!="on":
        return
    
    '''determines whether to toggle and then if so toggles appropriately'''
    global _LAST, _HAS_RUN_FIRST_TIME, _ON, _OFF
    should_toggle = False
    if not _HAS_RUN_FIRST_TIME:
        should_toggle = True
        _HAS_RUN_FIRST_TIME = True
    
    if not settings.SETTINGS["auto_com"]["change_language_only"]:
        current_window = utilities.get_active_window_path(natlink).split("\\")[-1]
        should_be_on = current_window in settings.SETTINGS["auto_com"]["executables"]
        should_toggle = should_be_on != _LAST
        _LAST = should_be_on
        
        if should_toggle:
            e = _ON if _LAST else _OFF
            e.execute()
            
    
    # language switching section
    if settings.SETTINGS["auto_com"]["change_language"]:
        language.toggle_language()
示例#4
0
    def eventLoop(self):
        if self.other is None and natlink.getMicState() == 'on':
            self.other = self.makeSocket()
            self.other.settimeout(0.05)
            try:
                self.other.connect(("10.0.2.2", 23133))
                log.info("attempting to connect")
                #self.other.connect(("192.168.56.1", 23133))
                log.info('connected')

                # Should reset variables here rather than on disconnect,
                # because at startup you've never been disconnected.
                if self.requestedLoads:
                    oldRequests = self.requestedLoads
                    self.requestedLoads = set()
                    self.sendLoadRequest(oldRequests)
                self.lastMicState = None
                self.lastLoadState = None
            except socket.error as e:
                log.info('connect error: %s' % e)
                self.dumpOther()
            except socket.timeout as e:
                log.info('connect timeout: %s' % e)
                self.dumpOther()
                return

        mdlog.flush()
        self.retrieveMessages()
        self.heartbeat()
        self.updateMicState()
        self.updateLoadState()
示例#5
0
    def eventLoop(self):
        if self.other is None and natlink.getMicState() == 'on':
            self.other = self.makeSocket()
            self.other.settimeout(0.05)
            try:
                #self.other.connect(("10.0.0.2", 23133))
                log.info("attempting to connect")
                self.other.connect(("192.168.56.1", 23133))
                log.info('connected')

                # Should reset variables here rather than on disconnect,
                # because at startup you've never been disconnected.
                if self.requestedLoads:
                    oldRequests = self.requestedLoads
                    self.requestedLoads = set()
                    self.sendLoadRequest(oldRequests)
                self.lastMicState = None
                self.lastLoadState = None
            except socket.error as e:
                log.info('connect error')
                self.dumpOther()
            except socket.timeout as e:
                log.info('connect timeout')
                self.dumpOther()
                return

        mdlog.flush()
        self.retrieveMessages()
        self.heartbeat()
        self.updateMicState()
        self.updateLoadState()
示例#6
0
文件: winspch.py 项目: merrillh/aenea
 def onMic(self,nID,code):
     micState = natlink.getMicState()
     if micState == 'on' or micState == 'sleeping':
         print 'Button click: Turn Mic Off'
         natlink.setMicState('off')
     else:
         print 'Button click: Turn Mic On'
         natlink.setMicState('on')
示例#7
0
 def onMic(self,nID,code):
     micState = natlink.getMicState()
     if micState == 'on' or micState == 'sleeping':
         print 'Button click: Turn Mic Off'
         natlink.setMicState('off')
     else:
         print 'Button click: Turn Mic On'
         natlink.setMicState('on')
示例#8
0
def get_mic():
    """checks the current microphone state

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection.
    """
#    if not sr_is_connected:
#        connect()
    return natlink.getMicState()
示例#9
0
def get_mic():
    """checks the current microphone state

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection.
    """
    #    if not sr_is_connected:
    #        connect()
    return natlink.getMicState()
示例#10
0
 def onMicButton(self, nID, code):
     micState = natlink.getMicState()
     if micState == 'on' or micState == 'sleeping':
         self.SetDlgItemText(IDC_MICBUTTON, 'Turn &Mic On')
         natlink.setMicState('off')
     else:
         self.SetDlgItemText(IDC_MICBUTTON, 'Turn &Mic Off')
         natlink.setMicState('on')
     self.edit.SetFocus()
示例#11
0
文件: windict.py 项目: merrillh/aenea
 def onMicButton(self,nID,code):
     micState = natlink.getMicState()
     if micState == 'on' or micState == 'sleeping':
         self.SetDlgItemText(IDC_MICBUTTON,'Turn &Mic On')
         natlink.setMicState('off')
     else:
         self.SetDlgItemText(IDC_MICBUTTON,'Turn &Mic Off')
         natlink.setMicState('on')
     self.edit.SetFocus()
示例#12
0
文件: modes.py 项目: mrob95/MR-caster
 def check_context(self):
     if natlink.getMicState() == "on":
         w = Window.get_foreground()
         should_be_command = self.command_contexts.matches(w.executable, w.title, w.handle)
         if should_be_command and self.mode == "normal":
             self.switch_mode("command")
         elif not should_be_command and self.mode == "command":
             self.switch_mode("normal")
         else:
             pass
示例#13
0
 def onTimer(self):
     if natlink.getMicState() != 'on':
         print 'mic switched off, cancel timer'
         self.cancelMode()
         return
     modInfo = natlink.getCurrentModule()
     if modInfo[2] != self.prevHandle:
         print 'window handle changed, cancel timer'
         self.cancelMode()
         return
     print 'in onTimer: %.1f'% time.clock()
     self.rule_newcard([])
示例#14
0
 def _sync_mode(self):
     """
     Synchronizes Caster exclusivity modes an with DNS/DPI GUI built-in modes state.
     """
     # TODO: Implement set_engine_mode logic with modes not just mic_state.
     caster_mic = self.get_mic_mode()
     natlink_mic = natlink.getMicState()
     if caster_mic is None:
         self.mic_state = natlink_mic
     else:
         if natlink_mic != caster_mic:
             self.set_mic_mode(natlink_mic)
示例#15
0
 def onTimer(self):
     if natlink.getMicState() != 'on':
         print 'mic switched off, cancel timer'
         self.cancelMode()
         return
     modInfo = natlink.getCurrentModule()
     if modInfo[2] != self.prevHandle:
         print 'window handle changed, cancel timer'
         self.cancelMode()
         return
     print 'in onTimer: %.1f' % time.clock()
     self.rule_newcard([])
示例#16
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
示例#17
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
示例#18
0
    def initialize(self):
        self.load(self.testGram)
        # problem of Dragon not waking on initialisation when in sleep,
        # exacerbated by background noise.
        # Seems that cannot change micState until it is waiting in sleeping
        # mode. Waiting in initialisation in natlink delays  Dragon start-up.
        # polling produces a ~68 seconds wait for sleeping mode to activate.
        # TODO: to avoid this delay, need to catch signal from DNS post NatLink
        # init. ( temporary solution is to test the dimensions of monitor)
        monitorRects = [
            mon[2] for mon in win32api.EnumDisplayMonitors(None, None)
            if mon[2] == (0, 0, 1024, 768)
        ]
        if not monitorRects:
            print("not car monitor")
            self.activateSet(['normalState'], exclusive=0)
        else:
            STEP = 4
            count = 0
            micstate = natlink.getMicState()
            print "micstate: {0}, {1} sec wait".format(micstate, count)

            # poll until Dragon is in sleep state (select "start dragon in sleep
            # state" option in Dragon options)
            while micstate not in ['sleeping', 'on']:  #'off':
                time.sleep(STEP)
                count += STEP
                micstate = natlink.getMicState()
                print "polling micstate: {0}, {1} sec wait".format(
                    micstate, count)

            natlink.setMicState('on')
            micstate = natlink.getMicState()
            print "micstate: {0}, {1} sec wait".format(micstate, count)

            # now Dragon is on, put in an exclusive state waiting for "switch
            # active listener" grammar
            self.activateSet(['notListening'], exclusive=1)
示例#19
0
 def goTrain(self, ToTrain):
     Title = 'Train Phrases'
     Phrases = []
     for p in ToTrain:
         Phrases.append((p))
     try:
         natlink.natConnect(1)
     except:
         return
     MicState = natlink.getMicState()
     dlg = TrainDialog.TrainDialog(Title, Phrases, MicState)
     SetMic('off')
     dlg.DoModal()
     natlink.natDisconnect()
示例#20
0
 def goTrain(self,ToTrain):
     Title='Train Phrases'
     Phrases=[]
     for p in ToTrain:
         Phrases.append((p))
     try:
         natlink.natConnect(1)
     except:
         return
     MicState=natlink.getMicState()
     dlg=TrainDialog.TrainDialog(Title,Phrases,MicState)
     SetMic('off')
     dlg.DoModal()
     natlink.natDisconnect()    
示例#21
0
 def onTimer(self):
     if self.lastClock:
         diff = int( (time.time() - self.lastClock) * 1000 )
         self.lastClock = time.time()
     if self.curMode == 1:
         moduleInfo = natlink.getCurrentModule()
         if natlink.getMicState() == 'on' and moduleInfo == self.moduleInfo:
             self.setTrayIcon(1)
             # Note: it is often during a playString operation that the
             # "stop moving" command occurs
             natlink.playString('{'+self.curDirection+'}')
         else:
             self.cancelMode()
     elif self.curMode == 2:
         self.moveMouse(self.curDirection,self.curPixels)
示例#22
0
文件: _mouse.py 项目: merrillh/aenea
 def onTimer(self):
     if self.lastClock:
         diff = int( (time.clock() - self.lastClock) * 1000 )
         self.lastClock = time.clock()
     if self.curMode == 1:
         moduleInfo = natlink.getCurrentModule()
         if natlink.getMicState() == 'on' and moduleInfo == self.moduleInfo:
             self.setTrayIcon(1)
             # Note: it is often during a playString operation that the
             # "stop moving" command occurs
             natlink.playString('{'+self.curDirection+'}')
         else:
             self.cancelMode()
     elif self.curMode == 2:
         self.moveMouse(self.curDirection,self.curPixels)
    def onTimer(self):
##        if self.lastClock:
##            diff = int((time.clock() - self.lastClock) * 1000 )
        if natbj.IsDisplayingMessage:
            debugPrint('in timer, displaying message, returning')
            return
        moduleInfo = natlink.getCurrentModule()
        if natlink.getMicState() == 'on' and moduleInfo[2] == self.moduleInfo[2]:
            if self.inside or self.insideCommand:
                self.setTrayIcon(1)
                return
            elif self.waiting:
                self.setTrayIcon(1) 
                return
            elif self.doAction():
                return   # this is the only good exit from onTimer!!!!
        self.cancelMode()
示例#24
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))
示例#25
0
 def _toggle(self):
     if self.is_natlink and natlink.getMicState()!="on":
         return
     
     '''determines whether to toggle and then if so toggles appropriately'''
     should_toggle = False
     if not self._has_run_first_time:
         should_toggle = True
         self._has_run_first_time = True
     if not settings.SETTINGS["auto_com"]["change_language_only"]:
         current_window = utilities.get_active_window_path().split("\\")[-1]
         should_be_on = current_window in settings.SETTINGS["auto_com"]["executables"]
         should_toggle = should_be_on != self._last
         self._last = should_be_on
     
         if should_toggle:
             e = self._ON if self._last else self._OFF
             e.execute()
     
     '''language switching section'''
     if settings.SETTINGS["auto_com"]["change_language"]:
         self._toggle_language()
示例#26
0
文件: zerver.py 项目: altV/intro
def run():
    global s
    global g
    natlink.natConnect(1)  #if natlink.isNatSpeakRunning() else wait
    try:
        print 'MicState:', natlink.getMicState()
        natlink.setBeginCallback(beginCallback)
        natlink.setChangeCallback(changeCallback)
        updateGrammarFromClient()
        natlink.setMicState('on')
        natlink.waitForSpeech(300)
        #data = client_socket.recv(512)
        #data = raw_input ( "SEND( TYPE q or Q to Quit):" )
    except:
        #print sys.exc_info()
        print traceback.format_exc()
    finally:
        g.unload()
        natlink.natDisconnect()
        print 'iDisconnected.'
        s.close()
        print 'all closed'
示例#27
0
文件: zerver.py 项目: altV/intro
def run():
    global s
    global g
    natlink.natConnect(1) #if natlink.isNatSpeakRunning() else wait
    try:
        print 'MicState:', natlink.getMicState()
        natlink.setBeginCallback(beginCallback)
        natlink.setChangeCallback(changeCallback)
        updateGrammarFromClient()
        natlink.setMicState('on')
        natlink.waitForSpeech(300)
        #data = client_socket.recv(512)
        #data = raw_input ( "SEND( TYPE q or Q to Quit):" )
    except:
        #print sys.exc_info()
        print traceback.format_exc()
    finally:
        g.unload()
        natlink.natDisconnect()
        print 'iDisconnected.'
        s.close()
        print 'all closed'
示例#28
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))
示例#29
0
def toggle():
    if control.nexus().dep.NATLINK and natlink.getMicState() != "on":
        return
    '''determines whether to toggle and then if so toggles appropriately'''
    global _LAST, _HAS_RUN_FIRST_TIME, _ON, _OFF
    should_toggle = False
    if not _HAS_RUN_FIRST_TIME:
        should_toggle = True
        _HAS_RUN_FIRST_TIME = True

    if not settings.SETTINGS["auto_com"]["change_language_only"]:
        current_window = utilities.get_active_window_path().split("\\")[-1]
        should_be_on = current_window in settings.SETTINGS["auto_com"][
            "executables"]
        should_toggle = should_be_on != _LAST
        _LAST = should_be_on

        if should_toggle:
            e = _ON if _LAST else _OFF
            e.execute()

    # language switching section
    if settings.SETTINGS["auto_com"]["change_language"]:
        language.toggle_language()
示例#30
0
    def _process_recognition(self,node,extras):
        player.pause()
class ResumeRule(CompoundRule):
    spec = "Resume"
    def _process_recognition(self,node,extras):
        player.play()

class VolumeUp(CompoundRule):
    spec = "Volume Up"
    def _process_recognition(self,node,extras):
        a1 = Key("w-b,right,right,right,right,enter,up:20")
        a1.execute()

grammar = Grammar("Basic Grammar")
grammar.add_rule(PlayMusicRule())
grammar.add_rule(SkipRule())
grammar.add_rule(StopRule())
grammar.add_rule(ResumeRule())
grammar.add_rule(VolumeUp())

natlink.natConnect()
grammar.load()
print natlink.getMicState()
grammar.enable()
natlink.waitForSpeech()
natlink.natDisconnect()