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)
Esempio n. 2
0
 def gotResults_reload(self, words, fullResults):
     print "reloading natlink...."
     natqh.switchToWindowWithTitle("Messages from Python Macros")
     natqh.Wait()
     natlink.setMicState("off")
     natqh.Wait()
     print "do it yourself..."
Esempio n. 3
0
def updateAllGrammars(grammar_directory=GRAMMAR_DIRECTORY, touch_bin=TOUCH_BIN):
    for file in os.listdir(grammar_directory):
        if file.endswith(".py"):
            touch("{0}/{1}".format(grammar_directory, file), touch_bin)
    setMicState("sleeping")
    time.sleep(0.2)
    setMicState("on")
Esempio n. 4
0
 def gotResults_reload(self,words,fullResults):
     print "reloading natlink...."
     natqh.switchToWindowWithTitle("Messages from Python Macros")
     natqh.Wait()
     natlink.setMicState("off")
     natqh.Wait()
     print "do it yourself..."
Esempio n. 5
0
def connect(user_name, mic_state=None, mic_change_callback = None):
    """Connects to the SR system.
    
    **INPUTS**
    
    *STR* name of the Natspeak user to open

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection. If *None*, then leave mic alone.

    *FCT* mic_change_callback -- 
      mic_change_callback(*STR* mic_state)
    (optional) function to be called when the microphone state changes.
    
    **OUTPUTS**
    
    *none* -- 
    """
    global sr_is_connected, vc_user_name, vc_base_model, vc_base_topic
    global sr_mic_change_callback
    
    
    if not sr_is_connected:
        trace('sr_interface.connect', 'mic_state=%s, sr_is_connected=%s' % (mic_state, sr_is_connected))
#        trace_call_stack('sr_interface.connect')
# 1 means use threads -- needed for GUI apps
        natlink.natConnect(1)
        sr_is_connected = 1            
        openUser(user_name)
    if mic_state:
        natlink.setMicState(mic_state)
    if mic_change_callback:
        set_change_callback(mic_change_callback)
Esempio n. 6
0
def updateAllGrammars(grammar_directory=GRAMMAR_DIRECTORY,
                      touch_bin=TOUCH_BIN):
    for file in os.listdir(grammar_directory):
        if file.endswith(".py"):
            touch("{0}/{1}".format(grammar_directory, file), touch_bin)
    setMicState("sleeping")
    time.sleep(0.2)
    setMicState("on")
Esempio n. 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')
Esempio n. 8
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')
Esempio n. 9
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()
Esempio n. 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()
Esempio n. 11
0
def set_mic(mic_state):
    """turns microphone on or off (connecting first, if necessary).

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection.
    """

#    if not sr_is_connected:
#        connect()
    natlink.setMicState(mic_state)
Esempio n. 12
0
    def _execute(self, data):
        grammar = "%(grammar)s" % data

        if not grammar.endswith(".py"):
            grammar += ".py"
            
        touch("{0}/{1}".format(self._grammar_directory, grammar), self._touch_bin)
        setMicState("sleeping")
        time.sleep(0.2)
        setMicState("on")
Esempio n. 13
0
    def _process_recognition(self, node, extras):
        self._log.debug("%s: locking screen." % self)

        # Put the microphone to sleep.
        natlink.setMicState("sleeping")

        # Lock screen.
        success = ctypes.windll.user32.LockWorkStation()
        if not success:
            self._log.error("%s: failed to lock screen." % self)
Esempio n. 14
0
    def _process_recognition(self, node, extras):
        self._log.debug("%s: locking screen." % self)

        # Put the microphone to sleep.
        natlink.setMicState("sleeping")

        # Lock screen.
        success = ctypes.windll.user32.LockWorkStation()
        if not success:
            self._log.error("%s: failed to lock screen." % self)
Esempio n. 15
0
def set_mic(mic_state):
    """turns microphone on or off (connecting first, if necessary).

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection.
    """

    #    if not sr_is_connected:
    #        connect()
    natlink.setMicState(mic_state)
Esempio n. 16
0
def cancel_and_sleep(text=None, text2=None):
    """Used to cancel an ongoing dictation and puts microphone to sleep.
    This method notifies the user that the dictation was in fact canceled,
     a message in the Natlink feedback window.
    Then the the microphone is put to sleep.
    Example:
    "'random mumbling go to sleep'" => Microphone sleep.
    """
    print("* Dictation canceled. Going to sleep. *")
    setMicState("sleeping")
Esempio n. 17
0
def cancel_and_sleep(text=None, text2=None):
    """Used to cancel an ongoing dictation and puts microphone to sleep.
    This method notifies the user that the dictation was in fact canceled,
     a message in the Natlink feedback window.
    Then the the microphone is put to sleep.
    Example:
    "'random mumbling go to sleep'" => Microphone sleep.
    """
    print("* Dictation canceled. Going to sleep. *")
    setMicState("sleeping")
Esempio n. 18
0
def kick_dragon():
    """
    sending dragon to sleep and up again to reload macros
    """

    Key("c-s").execute()
    show_natlink_messages_window(
        duration=2,
        msg="** saved notepad, reloading by mic sleeping then on **")
    setMicState("sleeping")
    setMicState("on")
Esempio n. 19
0
    def _execute(self, data):
        grammar = "%(grammar)s" % data

        if not grammar.endswith(".py"):
            grammar += ".py"

        touch("{0}/{1}".format(self._grammar_directory, grammar),
              self._touch_bin)
        setMicState("sleeping")
        time.sleep(0.2)
        setMicState("on")
Esempio n. 20
0
def cancel_and_sleep(text=None, text2=None):
    """Used to cancel an ongoing dictation and puts microphone to sleep.

    This method notifies the user that the dictation was in fact canceled,
    with a sound and a message in the Natlink feedback window.
    Then the the microphone is put to sleep.
    Example:
    "'random mumbling or other noises cancel and sleep'" => Microphone sleep.

    """
    print("* Dictation canceled, by user command. Going to sleep. *")
    sound.play(sound.SND_DING)
    setMicState("sleeping")
Esempio n. 21
0
 def set_mic_mode(cls, mode):
     """
     Changes the engine microphone mode
     :param mode: str
         'on': mic is on
         'sleeping': mic from the sleeping and can be woken up by command
         'off': mic off and cannot be turned back on by voice. (DPI Only)
     """
     if mode in cls.mic_modes:
         cls.mic_state = mode
         if engine == 'natlink':
             natlink.setMicState(mode)
         # Overrides DNS/DPI is built in sleep grammar
         ExclusiveManager(mode, modetype="mic_mode")
     else:
         printer.out(
             "Caster: '{}' is not valid. set_mic_state modes are: 'off' - DPI Only, 'on', 'sleeping'"
             .format(mode))
Esempio n. 22
0
def connect(user_name, mic_state=None, mic_change_callback=None):
    """Connects to the SR system.
    
    **INPUTS**
    
    *STR* name of the Natspeak user to open

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection. If *None*, then leave mic alone.

    *FCT* mic_change_callback -- 
      mic_change_callback(*STR* mic_state)
    (optional) function to be called when the microphone state changes.
    
    **OUTPUTS**
    
    *none* -- 
    """
    global sr_is_connected, vc_user_name, vc_base_model, vc_base_topic
    global sr_mic_change_callback, natspeak_version, period_space_after_spoken_form_letter, category_information_in_vocabulary_entries

    if not sr_is_connected:
        trace(
            'sr_interface.connect',
            'mic_state=%s, sr_is_connected=%s' % (mic_state, sr_is_connected))
        #        trace_call_stack('sr_interface.connect')
        # 1 means use threads -- needed for GUI apps
        natlink.natConnect(1)
        sr_is_connected = 1
        openUser(user_name)
        check_alpha_bravo()  # check the exact spelling of military alphabet
        # return the results in alpha_bravo dict
    if mic_state:
        natlink.setMicState(mic_state)
    if mic_change_callback:
        set_change_callback(mic_change_callback)
    natspeak_version = NLstatus.getDNSVersion()
    if natspeak_version >= 11:
        period_space_after_spoken_form_letter = ' '  # new in NatSpeak 11
        category_information_in_vocabulary_entries = True
    trace(
        'sr_interface.period_space_after_spoken_form_letter',
        'natspeak_version: %s, nperiod_space_after_spoken_form_letter: "%s"' %
        (natspeak_version, period_space_after_spoken_form_letter))
Esempio n. 23
0
def connect(user_name, mic_state=None, mic_change_callback = None):
    """Connects to the SR system.
    
    **INPUTS**
    
    *STR* name of the Natspeak user to open

    *STR* mic_state -- *'on'* or *'off'*. State to put the mic in
    after connection. If *None*, then leave mic alone.

    *FCT* mic_change_callback -- 
      mic_change_callback(*STR* mic_state)
    (optional) function to be called when the microphone state changes.
    
    **OUTPUTS**
    
    *none* -- 
    """
    global sr_is_connected, vc_user_name, vc_base_model, vc_base_topic
    global sr_mic_change_callback, natspeak_version, period_space_after_spoken_form_letter, category_information_in_vocabulary_entries
    
    
    if not sr_is_connected:
        trace('sr_interface.connect', 'mic_state=%s, sr_is_connected=%s' % (mic_state, sr_is_connected))
#        trace_call_stack('sr_interface.connect')
# 1 means use threads -- needed for GUI apps
        natlink.natConnect(1)
        sr_is_connected = 1            
        openUser(user_name)
        check_alpha_bravo() # check the exact spelling of military alphabet
                            # return the results in alpha_bravo dict 
    if mic_state:
        natlink.setMicState(mic_state)
    if mic_change_callback:
        set_change_callback(mic_change_callback)
    natspeak_version = NLstatus.getDNSVersion()
    if natspeak_version >= 11:
        period_space_after_spoken_form_letter = ' ' # new in NatSpeak 11
        category_information_in_vocabulary_entries = True
    trace('sr_interface.period_space_after_spoken_form_letter',
                'natspeak_version: %s, nperiod_space_after_spoken_form_letter: "%s"'%
                    (natspeak_version, period_space_after_spoken_form_letter))
Esempio n. 24
0
class DragonRule(MappingRule):
    mapping = {
        "(go-to-sleep | snore | mic-sleep)":
        Function(lambda: natlink.setMicState("sleeping")),
        "(lock-Dragon|turn-mic-off)":
        Function(lambda: natlink.setMicState("off")),
        "german profile":
        Function(
            lambda: natlink.saveUser() + natlink.openUser("Codebold german")),
        "englisches Profil":
        Function(lambda: natlink.saveUser() + natlink.openUser("Codebold")),
        "reload grammar[s]":
        Function(lambda: updateAllGrammars()),
        "reload <grammar>":
        GrammarUpdate(),
        "como":
        Function(lambda: natlink.recognitionMimic(
            ["switch", "to", "command", "mode"])),
        "diemo":
        Function(
            lambda: natlink.recognitionMimic(["start", "dictation", "mode"])),
        "nomo":
        Function(lambda: natlink.recognitionMimic(["normal", "mode", "on"])),
        "sleemo":
        Function(lambda: natlink.recognitionMimic(["go", "to", "sleep"])),
        "dictation":
        Function(
            lambda: natlink.recognitionMimic(["show", "dictation", "box"])),
        "dictox":
        Function(lambda: natlink.recognitionMimic(["normal", "mode", "on"])) +
        Function(
            lambda: natlink.recognitionMimic(["show", "dictation", "box"])),
        "transfox":
        Function(lambda: natlink.recognitionMimic(["click", "transfer"])) +
        Function(lambda: natlink.recognitionMimic(["command", "mode", "on"])),
        "blitz NatLink":
        Function(blitz_natlink_status),
        "show NatLink":
        Function(show_natlink_status)
    }
    extras = [chc_base.grammar]
Esempio n. 25
0
File: zerver.py Progetto: 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'
Esempio n. 26
0
File: zerver.py Progetto: 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'
Esempio n. 27
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)
Esempio n. 28
0
    def doUnitTests(self, tests):
        # self.checkSysPath(self.testFolder)  # append unimacro_test if needed
        suiteAll = None
        self.activeTests = []

        for test in tests:
            print('do test %s (%s)' % (test, self.allTests[test]))
            suite = self.addUnitTest(test, self.allTests[test])
            if suite:
                self.activeTests.append(test)
                if suiteAll:
                    suiteAll.addTest(suite)
                else:
                    suiteAll = suite
        if suiteAll:
            natlink.setMicState('off')
            result = unittest.TextTestRunner().run(suiteAll)
            print('after testing------------------------------------')
            self.dumpResult(result, filesToSkip=self.filesToSkipInResult)
            natlink.setMicState('on')

        else:
            print("nothing valid to test")
Esempio n. 29
0
 def gotResults_micOff(self,words,fullResults):
     natlink.setMicState('off')
Esempio n. 30
0
def reload_natlink():
    import natlink
    natlink.setMicState('off')
    natlink.setMicState('on')
    play(SND_DING)
Esempio n. 31
0
def snore(**kw):
    natlink.setMicState('sleeping')
Esempio n. 32
0
 def _process_recognition(self, node, extras):
     natlink.setMicState("sleeping")
Esempio n. 33
0
 def listen(self, echo_cmd=0):
     if echo_cmd: self.echo_command('listen')
     natlink.setMicState('on')
     natlink.waitForSpeech(0)
     natlink.setMicState('off')
Esempio n. 34
0
def snore_and_unload():
    natlink.setMicState('sleeping')
    client.setRecognitionState('success')
    client.updateMicState()
 def gotResults_micOff(self, words, fullResults):
     natlink.setMicState('off')
 def gotResults_resetMic(self, words, fullResults):
     natlink.setMicState("off")
     time.sleep(2)
     natlink.setMicState("on")
Esempio n. 37
0
    grammars[grammar_name].setExclusive(exclusive)
    return "done"


@rpc
def activate(grammar_name, rule_name):
    grammars[grammar_name].activate(rule_name, 0)
    return "done"


@rpc
def deactivate(grammar_name, rule_name):
    grammars[grammar_name].deactivate(rule_name)
    return "done"


#@rpc
#def updateList(grammar_name, list_name, elements): Pass

try:
    print "loading"
    natlink.natConnect(1)
    natlink.openUser("Michael")
    natlink.setMicState("on")
    natlink.setTimerCallback(drainRequests, 100)
    natlink.waitForSpeech(0)
except Exception as e:
    print e
finally:
    shutdown()
Esempio n. 38
0
def wakeup():
    print("* Dictation on. *")
    sound.play(sound.SND_WAKE)
    setMicState("on")
Esempio n. 39
0
 def _process_recognition(self, node, extras):
     self._log.debug("sleepy mic")
     natlink.setMicState("sleeping")
Esempio n. 40
0
 def gotResults_sleep(self,words,fullResults):
     natlink.setMicState('sleeping')
Esempio n. 41
0
 def deactivate_natlink():
     natlink.setMicState("sleeping")
Esempio n. 42
0
def snore(**kw):
    natlink.setMicState('sleeping')
 def gotResults_sleep(self, words, fullResults):
     natlink.setMicState('sleeping')
Esempio n. 44
0
def mute_microphone():
    setMicState("off")
    time.sleep(11)
    setMicState('on')
Esempio n. 45
0
 def _process_recognition(self, node, extras):
   self._log.debug("sleepy mic")
   natlink.setMicState("sleeping")
def reload_rules(text=None, text2=None):
	Key("c-s").execute()
	setMicState("sleeping")
	setMicState("on")
Esempio n. 47
0
#
# Python Macro Language for Dragon NaturallySpeaking
#   (c) Copyright 1999 by Joel Gould
#   Portions (c) Copyright 1999 by Dragon Systems, Inc.
#
# _sleeping.py
#   Simply by having this file in the Python command and control subsystem
#   directory, we turn the microphone on and put the system in a sleeping
#   state when NatSpeak first loads
#
# April 25, 1999
#   - packaged for external release
#
# March 3, 1999
#   - initial version
#

import natlink

natlink.setMicState('sleeping')


def unload():
    # must be defined, we do not need to do anything here
    pass
Esempio n. 48
0
def snore_and_unload():
    natlink.setMicState('sleeping')
    client.setRecognitionState('success')
    client.updateMicState()
Esempio n. 49
0
 def gotResults_resetMic(self, words, fullResults):
     natlink.setMicState("off")
     time.sleep(2)
     natlink.setMicState("on")
Esempio n. 50
0
def cancel_and_sleep(text=None, text2=None):
    print('Dictation canceled, going to sleep. Say "wake up" to restart')
    setMicState("sleeping")