Ejemplo n.º 1
0
    def testPreTests(self):
        # make sure that NatSpeak is loaded into memory
        testForException = self.doTestForException
        # these function should all fail before natConnect is called
        testForException( natlink.NatError, "natlink.playString('')" )
        testForException( natlink.NatError, "natlink.getCurrentModule()" )
        testForException( natlink.NatError, "natlink.getCurrentUser()" )
        testForException( natlink.NatError, "natlink.getMicState()" )
        testForException( natlink.NatError, "natlink.setMicState('off')" )
        testForException( natlink.NatError, "natlink.execScript('')" )
        testForException( natlink.NatError, "natlink.recognitionMimic('')" )
        testForException( natlink.NatError, "natlink.playEvents([])" )
        testForException( natlink.NatError, "natlink.inputFromFile('test.wav')" )
        testForException( natlink.NatError, "natlink.setTimerCallback(None)" )
        testForException( natlink.NatError, "natlink.getTrainingMode()" )
        testForException( natlink.NatError, "natlink.startTraining('calibrate')" )
        testForException( natlink.NatError, "natlink.finishTraining()" )
        testForException( natlink.NatError, "natlink.getAllUsers()" )
        testForException( natlink.NatError, "natlink.openUser('testUser')" )
        testForException( natlink.NatError, "natlink.saveUser()" )
        testForException( natlink.NatError, "natlink.getUserTraining()" )
        testForException( natlink.NatError, "natlink.waitForSpeech(0)" )
        testForException( natlink.NatError, "natlink.GramObj().load('')" )
        testForException( natlink.NatError, "natlink.DictObj()" )

        # these functions should all work before natConnect is called
        natlink.displayText('',0)
        natlink.getClipboard()
        natlink.getCallbackDepth()
        natlink.getCursorPos()
        natlink.getScreenSize()
        natlink.setBeginCallback(None)
        natlink.setChangeCallback(None)
        natlink.isNatSpeakRunning()
Ejemplo n.º 2
0
    def testPreTests(self):
        # make sure that NatSpeak is loaded into memory
        testForException = self.doTestForException
        # these function should all fail before natConnect is called
        testForException(natlink.NatError, "natlink.playString('')")
        testForException(natlink.NatError, "natlink.getCurrentModule()")
        testForException(natlink.NatError, "natlink.getCurrentUser()")
        testForException(natlink.NatError, "natlink.getMicState()")
        testForException(natlink.NatError, "natlink.setMicState('off')")
        testForException(natlink.NatError, "natlink.execScript('')")
        testForException(natlink.NatError, "natlink.recognitionMimic('')")
        testForException(natlink.NatError, "natlink.playEvents([])")
        testForException(natlink.NatError, "natlink.inputFromFile('test.wav')")
        testForException(natlink.NatError, "natlink.setTimerCallback(None)")
        testForException(natlink.NatError, "natlink.getTrainingMode()")
        testForException(natlink.NatError,
                         "natlink.startTraining('calibrate')")
        testForException(natlink.NatError, "natlink.finishTraining()")
        testForException(natlink.NatError, "natlink.getAllUsers()")
        testForException(natlink.NatError, "natlink.openUser('testUser')")
        testForException(natlink.NatError, "natlink.saveUser()")
        testForException(natlink.NatError, "natlink.getUserTraining()")
        testForException(natlink.NatError, "natlink.waitForSpeech(0)")
        testForException(natlink.NatError, "natlink.GramObj().load('')")
        testForException(natlink.NatError, "natlink.DictObj()")

        # these functions should all work before natConnect is called
        natlink.displayText('', 0)
        natlink.getClipboard()
        natlink.getCallbackDepth()
        natlink.getCursorPos()
        natlink.getScreenSize()
        natlink.setBeginCallback(None)
        natlink.setChangeCallback(None)
        natlink.isNatSpeakRunning()
Ejemplo n.º 3
0
    def gotResultsObject(self, recogType, resObj):
        if natbj.IsDisplayingMessage:
            debugPrint('displaying message, ignoring generic movement')
            return

        if recogType == 'reject':
            return
        handle = natlink.getCurrentModule()[2]
        if handle != self.prevHandle:
            # new window, empty lastResults list:
            self.lastResults = []
            self.prevHandle = handle
            self.repeatFlag = 0
        words = resObj.getWords(0)[:]
        if recogType == 'other':
            #print 'resultObject, %s,  repeatFlag: %s' % (words, self.repeatFlag)
            if self.repeatFlag:
                if words != self.repeatStuff:
                    self.cancelMode()
            elif self.inTimer:
                self.cancelMode()
            elif natlink.getCallbackDepth() < 3:
                if self.lastResults and words == self.lastResults[-1]:
                    pass
                else:
                    self.lastResults.append(words)
                    if len(self.lastResults) > 6:
                        self.lastResults = self.lastResults[1:]
                #debugPrint('lastResults: %s' % `self.lastResults`)
            else:
                debugPrint('callbackdepth %s, words: %s' %
                           (natlink.getCallbackDepth(), words))
            self.inside = 0
            return
##        skipped this, because it interferes with _message:
##        elif recogType == 'reject':
##            if self.inTimer and self.missed:
##                self.doAction()
##                self.startNow()
        elif recogType == 'self':
            self.nDir = ''
            self.Count = 0
            self.nSpeed = None
            self.dirState = ''
            debugPrint('---starting phrase')
            debugPrint('callbackdepth %s, words: %s' %
                       (natlink.getCallbackDepth(), words))
            if showAll:
                self.DisplayMessage('<%s>' % ' '.join(words))
        else:
            print('recogtype: %s' % recogType)
        self.inside = 0
Ejemplo n.º 4
0
    def gotResultsObject(self, recogType, resObj):
        #  If in oops mode, no actions are taken in this function.  If
        #    however the grammar was rejected, which is exclusive whenever the
        #    oops mode is on, the warning message is printed.hello
        if self.logging:
            if natlink.getCallbackDepth() < 3:
                try:
                    words = resObj.getWords(0)
                except (natlink.OutOfRange, IndexError):
                    words = "<???>"

                resCode = -1
                isDictate = -1
                k, rest = -1, -1
                for i in range(10):
                    try:
                        res = resObj.getResults(i)
                        try:
                            lenWave = len(resObj.getWave())
                        except natlink.DataMissing:
                            lenWave = 0
                        k, rest = int(lenWave / 1000), lenWave % 1000
                        resCode = res[0][1]
                        resCode = resCode & 0x7fffffff
                        if i == 0:
                            isDictate = not resCode
                        if resCode:
                            break
                    except (natlink.OutOfRange, IndexError):
                        break

                if isDictate == -1:
                    line = '  <???> '
                elif isDictate and not resCode:
                    line = '  %s (only dictate alternatives)' % ' '.join(words)
                elif isDictate:
                    line = '  %s (dictate, command alternatives)' % ' '.join(
                        words)
                else:
                    line = '  %s (command %s)' % (words, resCode)
                if k == -1:
                    logToFile(line + '(nowave)')
                elif rest <= 500:
                    logToFile(line + '(%sk+%s)' % (k, rest))
                else:
                    logToFile(line + '(%sk-%s)' % (k + 1, 1000 - rest))

        if recogType == 'other':
            # remember result for repeat grammar:
            if natlink.getCallbackDepth() < 3:
                self.lastResObj = resObj
Ejemplo n.º 5
0
def beginCallback(moduleInfo, checkAll=None):
    global loadedFiles, prevModInfo
    cbd = natlink.getCallbackDepth()
    if debugCallback:
        print('beginCallback, cbd: %s' % cbd)
        # print 'beginCallback, cbd: %s, checkAll: %s, checkForGrammarChanges: %s'% \
        #       (cbd, checkAll, checkForGrammarChanges)
    # maybe should be 1...
    if natlink.getCallbackDepth() > 1:
        return
    t0 = time.time()

    if vocolaEnabled and vocolaIsLoaded:
        result = vocolaModule.vocolaBeginCallback(moduleInfo)
        if result == 2:
            if debugCallback:
                print('Vocola made new module, load all Python files')
            findAndLoadFiles()
            loadModSpecific(moduleInfo)
        elif result == 1:
            if debugCallback:
                print('Vocola changed a Python module, check')
            checkAll = 1
        else:
            if debugCallback:
                print('no changes Vocola user files')

    if checkAll or checkForGrammarChanges:
        if debugCallback:
            print('check for changed files (all files)...')
        for x, loadedFile in loadedFiles.items():
            if loadedFile:
                origPath, origDate = loadedFile
                loadedFiles[x] = loadFile(x, origPath, origDate)
            else:
                loadedFiles[x] = loadFile(x)
        loadModSpecific(
            moduleInfo)  # in checkAll or checkForGrammarChanges mode each time
    else:
        if debugCallback:
            print('check for changed files (only specific)')
        loadModSpecific(moduleInfo, 1)  # only if changed module
    if debugTiming:
        print('checked all grammar files: %.6f' % (time.time() - t0, ))
Ejemplo n.º 6
0
    def beginCallback(moduleInfo, checkAll=None):
        global loadedFiles, prevModInfo
        cbd = natlink.getCallbackDepth()
        if debugCallback:
            print "beginCallback, cbd: %s, checkAll: %s, checkForGrammarChanges: %s" % (
                cbd,
                checkAll,
                checkForGrammarChanges,
            )
        # maybe should be 1...
        if natlink.getCallbackDepth() > 1:
            return
        t0 = time.time()

        if vocolaEnabled and vocolaIsLoaded:
            result = vocolaModule.vocolaBeginCallback(moduleInfo)
            if result == 2:
                if debugCallback:
                    print "Vocola made new module, load all Python files"
                findAndLoadFiles()
                loadModSpecific(moduleInfo)
            elif result == 1:
                if debugCallback:
                    print "Vocola changed a Python module, check"
                checkAll = 1
            else:
                if debugCallback:
                    print "no changes Vocola user files"

        if checkAll or checkForGrammarChanges:
            if debugCallback:
                print "check for changed files (all files)..."
            for x in loadedFiles.keys():
                loadedFiles[x] = loadFile(x, loadedFiles[x])
            loadModSpecific(moduleInfo)  # in checkAll or checkForGrammarChanges mode each time
        else:
            if debugCallback:
                print "check for changed files (only specific)"
            loadModSpecific(moduleInfo, 1)  # only if changed module
        if debugTiming:
            print "checked all grammar files: %.6f" % (time.time() - t0,)
Ejemplo n.º 7
0
 def gotResults_ListDialog(self,words,fullResults):
     print natlink.getCallbackDepth()
     print 'Request List Dialog'
     win32ui.GetMainFrame().PostMessage(IDC_LD)
     SetMic('on')
 def gotResults_ListDialog(self,words,fullResults):
     print natlink.getCallbackDepth()
     print 'Request List Dialog'
     win32ui.GetMainFrame().PostMessage(IDC_LD)
     SetMic('on')