Ejemplo n.º 1
0
    def openCommandFile(self, file, comment):
        if not commandFolder:
            print("Error: Unable to create command file " + \
                "because no Vocola command folder found.", file=sys.stderr)
            return

        path = self.FindExistingCommandFile(file)
        if not path:
            path = commandFolder + '\\' + file

            new = open(path, 'w')
            new.write('# ' + comment + '\n\n')
            new.close()

        #
        # Natlink/DNS bug causes os.startfile or wpi32api.ShellExecute
        # to crash DNS if allResults is on in *any* grammer (e.g., Unimacro)
        #
        # Accordingly, use AppBringUp instead:
        #

        #try:
        #    os.startfile(path)
        #except WindowsError, e:
        #    print
        #    print "Unable to open voice command file with associated editor: " + str(e)
        #    print "Trying to open it with notepad instead."
        #    prog = os.path.join(os.getenv('WINDIR'), 'notepad.exe')
        #    os.spawnv(os.P_NOWAIT, prog, [prog, path])
        natlink.execScript("AppBringUp \"" + path + "\", \"" + path + "\"")
    def lookForNatspeakOrDragonPad(self):

        # This should find the NatSpeak window.  If the NatSpeak window is not
        # available (because, for example, NatSpeak was not started before
        # running this script) then we will get the error:
        #   NatError: Error 62167 executing script execScript (line 1)

        try:
            natlink.execScript('AppBringUp "NatSpeak"')
        except natlink.NatError:
            raise TestError, 'The NatSpeak user interface is not running'
        try:
            natlink.execScript('Start "DragonPad"')
        except natlink.NatError:
            raise TestError, 'The DragonPad window cannot be started'

        # This will make sure that the NatSpeak window is empty.  If the NatSpeak
        # window is not empty we raise an exception to avoid possibily screwing
        # up the users work.

        if self.getWindowContents():
            raise TestError, 'The NatSpeak/DragonPad window is not empty'
        mod, title, hndle = natlink.getCurrentModule()
        self.DragonPadMod = mod
        self.DragonPadHndle = hndle
    def command(self, cmd):
        """do a shownumbersplus command
        
        """
        if not self.SNPActive:
            if self.debug:
                print 'SNP not running, call "switch on %s" to restar grammar, after you started SNP! again'% self.name
            return
        
        if self.inGotBegin or self.status == 'new':
            print 'SNP command not executed (initializing or gotbegin): %s'% cmd
            return
        
        
        hndle = self.SNPIsRunning()
        if hndle:
            script = 'DdeExecute "ShowNumbersPlus", "CONTROL", "[%s]"'% cmd
            if self.debug:
                print 'SNP: %s'% cmd
            try:
                natlink.execScript(script)
            except:
                '''Ddeexecute failed for shownumbersplus command: "%s".
    This is strange, because apparently Show Numbers Plus! is running.
    Error message: %s, %s'''% (cmd, sys.exc_info()[0], sys.exc_info()[1])
                self.switchOff(skipCancelMode=1)
                self.SNPActive = 0
            else:
                self.closeMutex()
        else:
            print '''No DdeExecute to shownumbersplus: "%s".
Because SNP seems to be not running.'''% cmd
            self.switchOff()
Ejemplo n.º 4
0
 def recognitionMimic(mimicList):
     """for Dragon 12, try execScript HeardWord
     """
     if DNSVersion >= 12:
         script = 'HeardWord "%s"' % '", "'.join(mimicList)
         natlink.execScript(script)
     else:
         natlink.recognitionMimic(mimicList)
Ejemplo n.º 5
0
def recognitionMimic(mimicList):
    """for Dragon 12, try execScript HeardWord
    """
    if DNSVersion >= 12:
        script = 'HeardWord "%s"'% '", "'.join(mimicList)
        natlink.execScript(script)
    else:
        natlink.recognitionMimic(mimicList)
Ejemplo n.º 6
0
def call_Dragon(function_name, argument_types, arguments):
    global dragon_prefix

    def quoteAsVisualBasicString(argument):
        q = argument
        q = string.replace(q, '"', '""')
        q = string.replace(q, "\n", '" + chr$(10) + "')
        q = string.replace(q, "\r", '" + chr$(13) + "')
        return '"' + q + '"'

    script = ""
    for argument in arguments:
        argument_type = argument_types[0]
        argument_types = argument_types[1:]

        if argument_type == 'i':
            argument = str(to_long(argument))
        elif argument_type == 's':
            if function_name == "SendDragonKeys" or function_name == "SendKeys" \
                    or function_name == "SendSystemKeys":
                argument = convert_keys(argument)
            argument = quoteAsVisualBasicString(str(argument))
        else:
            # there is a vcl2py.pl bug if this happens:
            raise VocolaRuntimeError(
                "Vocola compiler error: unknown data type " + " specifier '" +
                argument_type + "' supplied for a Dragon procedure argument")

        if script != '':
            script += ','
        script += ' ' + argument

    script = dragon_prefix + function_name + script
    dragon_prefix = ""
    #print '[' + script + ']'
    try:
        if function_name == "SendDragonKeys":
            natlink.playString(convert_keys(arguments[0]))
        elif function_name == "ShiftKey":
            dragon_prefix = script + chr(10)
        else:
            natlink.execScript(script)
    except Exception, e:
        m = "when Vocola called Dragon to execute:\n" \
            + '        ' + script + '\n' \
            + '    Dragon reported the following error:\n' \
            + '        ' + type(e).__name__ + ": " + str(e)
        raise VocolaRuntimeError, m
Ejemplo n.º 7
0
    def openCommandFile(self, file, comment):
        if not commandFolder:
            print >> sys.stderr, "Error: Unable to create command file because no Vocola command folder found."
            return

        path = self.FindExistingCommandFile(file)
        if not path:
            path = commandFolder + '\\' + file

            new = open(path, 'w')
            new.write('# ' + comment + '\n\n')
            # insert include line to Unimacro.vch:
            if status.getVocolaTakesUnimacroActions():
                if language == 'enx' or not status.getVocolaTakesLanguages():
                    includeLine = 'include Unimacro.vch;\n\n'
                else:
                    includeLine = 'include ..\\Unimacro.vch;\n\n'
                new.write(includeLine)
            new.close()

        wantedPath = os.path.join(commandFolder, file)
        if path and path != wantedPath:
            # copy from other location
            if wantedPath.startswith(
                    path) and len(wantedPath) - len(path) == 3:
                print 'copying enx version to language version %s' % language
                copyVclFileLanguageVersion(path, wantedPath)
            else:
                print 'copying from other location'
                self.copyVclFile(path, wantedPath)
            path = wantedPath

        #
        # NatLink/DNS bug causes os.startfile or wpi32api.ShellExecute
        # to crash DNS if allResults is on in *any* grammer (e.g., Unimacro)
        #
        # Accordingly, use AppBringUp instead:
        #

        #try:
        #    os.startfile(path)
        #except WindowsError, e:
        #    print
        #    print "Unable to open voice command file with associated editor: " + str(e)
        #    print "Trying to open it with notepad instead."
        #    prog = os.path.join(os.getenv('WINDIR'), 'notepad.exe')
        #    os.spawnv(os.P_NOWAIT, prog, [prog, path])
        natlink.execScript("AppBringUp \"" + path + "\", \"" + path + "\"")
Ejemplo n.º 8
0
def call_Dragon(function_name, argument_types, arguments):
    global dragon_prefix

    def quoteAsVisualBasicString(argument):
        q = argument
        q = string.replace(q, '"', '""')
        q = string.replace(q, "\n", '" + chr$(10) + "')
        q = string.replace(q, "\r", '" + chr$(13) + "')
        return '"' + q + '"'

    script = ""
    for argument in arguments:
        argument_type = argument_types[0]
        argument_types = argument_types[1:]

        if argument_type == 'i':
            argument = str(to_long(argument))
        elif argument_type == 's':
            if function_name == "SendDragonKeys" or function_name == "SendKeys" \
                    or function_name == "SendSystemKeys":
                argument = convert_keys(argument)
            argument = quoteAsVisualBasicString(str(argument))
        else:
            # there is a vcl2py.pl bug if this happens:
            raise VocolaRuntimeError("Vocola compiler error: unknown data type " +
                                     " specifier '" + argument_type +
                                   "' supplied for a Dragon procedure argument")

        if script != '':
            script += ','
        script += ' ' + argument

    script = dragon_prefix + function_name + script
    dragon_prefix = ""
    #print '[' + script + ']'
    try:
        if function_name == "SendDragonKeys":
            natlink.playString(convert_keys(arguments[0]))
        elif function_name == "ShiftKey":
            dragon_prefix = script + chr(10)
        else:
            natlink.execScript(script)
    except Exception, e:
        m = "when Vocola called Dragon to execute:\n" \
            + '        ' + script + '\n' \
            + '    Dragon reported the following error:\n' \
            + '        ' + type(e).__name__ + ": " + str(e)
        raise VocolaRuntimeError, m
Ejemplo n.º 9
0
    def openCommandFile(self, file, comment):
        if not commandFolder:
            print >> sys.stderr, "Error: Unable to create command file because no Vocola command folder found."
            return

        path = self.FindExistingCommandFile(file)
        if not path:
            path = commandFolder + '\\' + file

            new = open(path, 'w')
            new.write('# ' + comment + '\n\n')
            # insert include line to Unimacro.vch:
            if status.getVocolaTakesUnimacroActions():
                if language == 'enx' or not status.getVocolaTakesLanguages():
                    includeLine = 'include Unimacro.vch;\n\n'
                else:
                    includeLine = 'include ..\\Unimacro.vch;\n\n'
                new.write(includeLine)                    
            new.close()

        wantedPath = os.path.join(commandFolder, file)
        if path and path != wantedPath:
            # copy from other location
            if wantedPath.startswith(path) and len(wantedPath) - len(path) == 3:
                print 'copying enx version to language version %s'% language
                copyVclFileLanguageVersion(path, wantedPath)
            else:
                print 'copying from other location'
                self.copyVclFile(path, wantedPath)
            path = wantedPath   

        #
        # NatLink/DNS bug causes os.startfile or wpi32api.ShellExecute
        # to crash DNS if allResults is on in *any* grammer (e.g., Unimacro)
        #
        # Accordingly, use AppBringUp instead:
        #

        #try:
        #    os.startfile(path)
        #except WindowsError, e: 
        #    print
        #    print "Unable to open voice command file with associated editor: " + str(e)
        #    print "Trying to open it with notepad instead."
        #    prog = os.path.join(os.getenv('WINDIR'), 'notepad.exe')
        #    os.spawnv(os.P_NOWAIT, prog, [prog, path])
        natlink.execScript("AppBringUp \"" + path + "\", \"" + path + "\"")
Ejemplo n.º 10
0
    def set_engine_mode(cls, mode=None, state=True):
        """
        Sets the engine mode so that only certain types of commands/dictation are recognized.
        :param state: Bool - enable/disable mode.
            'True': replaces current mode (Default)
            'False': restores previous mode
        :param mode: str
            'normal': dictation and command (Default: DPI only)
            'dictation': Dictation only 
            'command': Commands only (Default: Other engines)
            'numbers': Numbers only
            'spell': Spelling only
        """
        if state and mode is not None:
            # Track previous engine state
            cls.previous_engine_state = cls.engine_state
        else:
            if not state:
                # Restore previous mode
                mode = cls.previous_engine_state
            else:
                printer.out(
                    "Caster: set_engine_mode: 'State' cannot be 'True' with a undefined a 'mode'"
                )

        if mode in cls.engine_modes:
            if engine == 'natlink':
                try:
                    natlink.execScript("SetRecognitionMode {}".format(
                        cls.engine_modes[mode])
                                       )  # engine_modes[mode] is an integer
                    cls.engine_state = mode
                    ExclusiveManager(mode, modetype="engine_mode")
                except Exception as e:
                    printer.out("natlink.execScript failed \n {}".format(e))
            else:
                # TODO: Implement set_engine_mode exclusivity. This should override DPI is built mode but kept in sync automatically.
                if engine == 'text':
                    cls.engine_state = mode
                else:
                    printer.out(
                        "Caster: 'set_engine_mode' is not implemented for '{}'"
                        .format(engine))
        else:
            printer.out(
                "Caster: '{}' mode is not valid. set_engine_mode: Modes: 'normal'- DPI Only, 'dictation', 'command', 'numbers', 'spell'"
                .format(mode))
Ejemplo n.º 11
0
def processFile(fileName):

    # this create a decoder object
    sx96 = mobiletools.SX96Codec()

    # open the file and get the header information again (this has the side
    # effect of skipping past the header)
    sriFile = open(fileName,'rb')
    year,month,day,hour,minute,second,packetCount = decodeHeader(sriFile)

    # compute the size of the data for the output file
    frameCount = packetCount * 9
    outDataSize = frameCount * wavFrameSize
    
    # open an output wave file and write out a header
    tempFileName = tempfile.mktemp() + '.wav'
    wavFile = open(tempFileName,'wb')
    writeHeader(wavFile,outDataSize)

    # iterate over each packet (9 frames) in the input file, convert the data
    # and write the converted data into the output file
    for i in range(packetCount):
        for j in range(9):
            frame = sriFile.read(sriFrameSize)
            wavData = sx96.decode(frame)
            wavFile.write(wavData)
        # discard the extra packet descriptor byte
        sriFile.read(1)

    wavFile.close()
    wavFile = None

    sriFile.close()
    sriFile = None

    # now we transcribe this file in NatSpeak
    natlink.execScript('AppBringUp "NatSpeak"')
    natlink.playString(formatDate(year,month,day,hour,minute,second))
    natlink.inputFromFile(tempFileName)
Ejemplo n.º 12
0
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# (C)2002, National Research Council of Canada
#
##############################################################################

import sr_interface, util
import natlink


def help():
   print """

Usage: python toggle_nat_text.py user_name status
   
Turns NaturalText on (status=1) or off (status=0)."""

if __name__ == '__main__':
   opts, args = util.gopt(())
   if len(args) == 0:
      help()
   else:
      sr_interface.connect(args[0])
      natlink.execScript('SetNaturalText %s' % args[1])
      sr_interface.disconnect()